function KernelTestBase::installSchema
Same name in other branches
- 9 core/tests/Drupal/KernelTests/KernelTestBase.php \Drupal\KernelTests\KernelTestBase::installSchema()
- 8.9.x core/modules/simpletest/src/KernelTestBase.php \Drupal\simpletest\KernelTestBase::installSchema()
- 8.9.x core/tests/Drupal/KernelTests/KernelTestBase.php \Drupal\KernelTests\KernelTestBase::installSchema()
- 10 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.
198 calls to KernelTestBase::installSchema()
- AccessTest::setUp in core/
modules/ file/ tests/ src/ Kernel/ AccessTest.php - AnnounceFetcherUserTest::setUp in core/
modules/ announcements_feed/ tests/ src/ Kernel/ AnnounceFetcherUserTest.php - ArgumentNodeRevisionIdTest::setUp in core/
modules/ node/ tests/ src/ Kernel/ Views/ ArgumentNodeRevisionIdTest.php - ArgumentUidRevisionTest::setUp in core/
modules/ node/ tests/ src/ Kernel/ Views/ ArgumentUidRevisionTest.php - BanIpTest::setUp in core/
modules/ ban/ tests/ src/ Kernel/ BanIpTest.php
File
-
core/
tests/ Drupal/ KernelTests/ KernelTestBase.php, line 748
Class
- KernelTestBase
- Base class for functional integration tests.
Namespace
Drupal\KernelTestsCode
protected function installSchema($module, $tables) {
/** @var \Drupal\Core\Extension\ModuleHandlerInterface $module_handler */
$module_handler = $this->container
->get('module_handler');
// Database connection schema is technically able to create database tables
// using any valid specification, for example of a non-enabled module. But
// 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 (!$module_handler->moduleExists($module)) {
throw new \LogicException("{$module} module is not installed.");
}
$specification = SchemaInspector::getTablesSpecification($module_handler, $module);
/** @var \Drupal\Core\Database\Schema $schema */
$schema = $this->container
->get('database')
->schema();
$tables = (array) $tables;
foreach ($tables as $table) {
if ($module === 'system' && $table === 'sequences') {
@trigger_error('Installing the table sequences with the method KernelTestBase::installSchema() is deprecated in drupal:10.2.0 and is removed from drupal:12.0.0. See https://www.drupal.org/node/3349345', E_USER_DEPRECATED);
}
if (empty($specification[$table])) {
throw new \LogicException("{$module} module does not define a schema for table '{$table}'.");
}
$schema->createTable($table, $specification[$table]);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.