function DriverSpecificSchemaTestBase::tryInsert

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/KernelTests/Core/Database/DriverSpecificSchemaTestBase.php \Drupal\KernelTests\Core\Database\DriverSpecificSchemaTestBase::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 DriverSpecificSchemaTestBase::tryInsert()
DriverSpecificSchemaTestBase::testSchema in core/tests/Drupal/KernelTests/Core/Database/DriverSpecificSchemaTestBase.php
Tests database interactions.

File

core/tests/Drupal/KernelTests/Core/Database/DriverSpecificSchemaTestBase.php, line 67

Class

DriverSpecificSchemaTestBase
Tests table creation and modification via the schema API.

Namespace

Drupal\KernelTests\Core\Database

Code

public function tryInsert(string $table = 'test_table') : bool {
  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.