function SchemaTest::checkGeneratedColumnStorage

Same name in this branch
  1. main core/modules/mysql/tests/src/Kernel/mysql/SchemaTest.php \Drupal\Tests\mysql\Kernel\mysql\SchemaTest::checkGeneratedColumnStorage()
  2. main core/modules/pgsql/tests/src/Kernel/pgsql/SchemaTest.php \Drupal\Tests\pgsql\Kernel\pgsql\SchemaTest::checkGeneratedColumnStorage()
Same name and namespace in other branches
  1. 11.x core/modules/sqlite/tests/src/Kernel/sqlite/SchemaTest.php \Drupal\Tests\sqlite\Kernel\sqlite\SchemaTest::checkGeneratedColumnStorage()
  2. 11.x core/modules/mysql/tests/src/Kernel/mysql/SchemaTest.php \Drupal\Tests\mysql\Kernel\mysql\SchemaTest::checkGeneratedColumnStorage()
  3. 11.x core/modules/pgsql/tests/src/Kernel/pgsql/SchemaTest.php \Drupal\Tests\pgsql\Kernel\pgsql\SchemaTest::checkGeneratedColumnStorage()

Checks that the database computes a column with the given storage.

Parameters

\Drupal\Core\Database\SchemaDefinition\GeneratedColumnStorage $storage: The asserted storage.

string $table: The table to test.

string $column: The generated column to test.

Overrides DriverSpecificSchemaTestBase::checkGeneratedColumnStorage

File

core/modules/sqlite/tests/src/Kernel/sqlite/SchemaTest.php, line 40

Class

SchemaTest
Tests schema API for the SQLite driver.

Namespace

Drupal\Tests\sqlite\Kernel\sqlite

Code

public function checkGeneratedColumnStorage(GeneratedColumnStorage $storage, string $table, string $column) : void {
  $getPrefixInfo = new \ReflectionMethod(get_class($this->schema), 'getPrefixInfo');
  $info = $getPrefixInfo->invoke($this->schema, $table);
  // table_info omits generated columns, table_xinfo reports them with a
  // hidden flag of 2 for VIRTUAL and 3 for STORED.
  $result = $this->connection
    ->query('PRAGMA [' . $info['schema'] . '].table_xinfo([' . $info['table'] . '])');
  $expected = match ($storage) {  GeneratedColumnStorage::Virtual => 2,
    GeneratedColumnStorage::Stored => 3,
  
  };
  foreach ($result as $row) {
    if ($row->name === $column) {
      $this->assertSame($expected, (int) $row->hidden);
      return;
    }
  }
  $this->fail("Column '{$column}' was not found in table '{$table}'.");
}

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