You are here

protected function KernelTestBase::installSchema in Zircon Profile 8

Same name in this branch
  1. 8 core/tests/Drupal/KernelTests/KernelTestBase.php \Drupal\KernelTests\KernelTestBase::installSchema()
  2. 8 core/modules/simpletest/src/KernelTestBase.php \Drupal\simpletest\KernelTestBase::installSchema()
Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/KernelTests/KernelTestBase.php \Drupal\KernelTests\KernelTestBase::installSchema()

Installs database tables from a module schema definition.

Parameters

string $module: The name of the module that defines the table's schema.

string|array $tables: The name or an array of the names of the tables to install.

Throws

\LogicException If $module is not enabled or the table schema cannot be found.

13 calls to KernelTestBase::installSchema()
AliasStorageTest::setUp in core/tests/Drupal/KernelTests/Core/Path/AliasStorageTest.php
CacheCollectorTest::setUp in core/tests/Drupal/KernelTests/Core/Cache/CacheCollectorTest.php
DbDumpCommandTest::setUp in core/modules/system/tests/src/Kernel/Scripts/DbDumpCommandTest.php
DefaultConfigTest::setUp in core/tests/Drupal/KernelTests/Config/DefaultConfigTest.php
EntitySerializationTest::setUp in core/modules/serialization/src/Tests/EntitySerializationTest.php

... See full list

File

core/tests/Drupal/KernelTests/KernelTestBase.php, line 731
Contains \Drupal\KernelTests\KernelTestBase.

Class

KernelTestBase
Base class for functional integration tests.

Namespace

Drupal\KernelTests

Code

protected function installSchema($module, $tables) {

  // drupal_get_module_schema() is technically able to install a schema
  // of a non-enabled module, but its ability to load the module's .install
  // file depends on many other factors. To prevent differences in test
  // behavior and non-reproducible test failures, we only allow the schema of
  // explicitly loaded/enabled modules to be installed.
  if (!$this->container
    ->get('module_handler')
    ->moduleExists($module)) {
    throw new \LogicException("{$module} module is not enabled.");
  }
  $tables = (array) $tables;
  foreach ($tables as $table) {
    $schema = drupal_get_module_schema($module, $table);
    if (empty($schema)) {
      throw new \LogicException("{$module} module does not define a schema for table '{$table}'.");
    }
    $this->container
      ->get('database')
      ->schema()
      ->createTable($table, $schema);
  }
}