function SchemaTest::checkGeneratedColumnStorage

Same name in this branch
  1. 11.x core/modules/mysql/tests/src/Kernel/mysql/SchemaTest.php \Drupal\Tests\mysql\Kernel\mysql\SchemaTest::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.