function SchemaInspector::getTablesSpecification

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/TestTools/Extension/SchemaInspector.php \Drupal\TestTools\Extension\SchemaInspector::getTablesSpecification()
  2. 10 core/tests/Drupal/TestTools/Extension/SchemaInspector.php \Drupal\TestTools\Extension\SchemaInspector::getTablesSpecification()
  3. 9 core/tests/Drupal/TestTools/Extension/SchemaInspector.php \Drupal\TestTools\Extension\SchemaInspector::getTablesSpecification()

Returns the module's schema specification.

This function can be used to retrieve a schema specification provided by hook_schema(), so it allows you to derive your tables from existing specifications.

Parameters

\Drupal\Core\Extension\ModuleHandlerInterface $handler: The module handler to use for calling schema hook.

string $module: The module to which the table belongs.

Return value

\Drupal\Core\Database\SchemaDefinition\Schema|array An array of schema definition provided by hook_schema().

See also

\hook_schema()

2 calls to SchemaInspector::getTablesSpecification()
KernelTestBase::installSchema in core/tests/Drupal/KernelTests/KernelTestBase.php
Installs database tables from a module schema definition.
SchemaInspector::getTableNames in core/tests/Drupal/TestTools/Extension/SchemaInspector.php
Returns the module's schema table names.

File

core/tests/Drupal/TestTools/Extension/SchemaInspector.php, line 33

Class

SchemaInspector
Provides methods to access modules' schema.

Namespace

Drupal\TestTools\Extension

Code

public static function getTablesSpecification(ModuleHandlerInterface $handler, string $module) : Schema|array {
  if ($handler->loadInclude($module, 'install')) {
    $schema = $handler->invoke($module, 'schema') ?? [];
    if ($schema instanceof Schema) {
      assert($schema->type === SchemaDefinitionType::Module, 'Invalid schema definition type, must be SchemaDefinitionType::Module');
      assert($schema->name === $module, 'Invalid schema definition name, must be equal to the module name');
    }
    return $schema;
  }
  return [];
}

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