You are here

public function SchemaTest::tryInsert in Drupal 9

Same name and namespace in other branches
  1. 8 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 497

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;
  }
}