function SchemaTest::tryInsert

Same name in other branches
  1. 8.9.x core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php \Drupal\KernelTests\Core\Database\SchemaTest::tryInsert()

Tests inserting data into an existing table.

Parameters

string $table: The database table to insert data into.

Return value

bool TRUE if the insert succeeded, FALSE otherwise.

1 call to SchemaTest::tryInsert()
SchemaTest::testSchema in core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php
Tests database interactions.

File

core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php, line 363

Class

SchemaTest
Tests table creation and modification via the schema API.

Namespace

Drupal\KernelTests\Core\Database

Code

public function tryInsert($table = 'test_table') {
    try {
        $this->connection
            ->insert($table)
            ->fields([
            'id' => mt_rand(10, 20),
        ])
            ->execute();
        return TRUE;
    } catch (\Exception $e) {
        return FALSE;
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.