class DatabaseTestBase
Same name in this branch
- 9 core/modules/system/tests/src/Functional/Database/DatabaseTestBase.php \Drupal\Tests\system\Functional\Database\DatabaseTestBase
Same name and namespace in other branches
- 11.x core/modules/system/tests/src/Functional/Database/DatabaseTestBase.php \Drupal\Tests\system\Functional\Database\DatabaseTestBase
- 11.x core/tests/Drupal/KernelTests/Core/Database/DatabaseTestBase.php \Drupal\KernelTests\Core\Database\DatabaseTestBase
- 10 core/modules/system/tests/src/Functional/Database/DatabaseTestBase.php \Drupal\Tests\system\Functional\Database\DatabaseTestBase
- 10 core/tests/Drupal/KernelTests/Core/Database/DatabaseTestBase.php \Drupal\KernelTests\Core\Database\DatabaseTestBase
- 8.9.x core/modules/system/tests/src/Functional/Database/DatabaseTestBase.php \Drupal\Tests\system\Functional\Database\DatabaseTestBase
- 8.9.x core/tests/Drupal/KernelTests/Core/Database/DatabaseTestBase.php \Drupal\KernelTests\Core\Database\DatabaseTestBase
Base class for databases database tests.
Because all database tests share the same test data, we can centralize that here.
Hierarchy
- class \Drupal\KernelTests\KernelTestBase implements \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertLegacyTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\KernelTests\Core\Database\DatabaseTestBase uses \Drupal\KernelTests\Core\Database\DatabaseTestSchemaDataTrait, \Drupal\KernelTests\Core\Database\DatabaseTestSchemaInstallTrait extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of DatabaseTestBase
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Database/ DatabaseTestBase.php, line 14
Namespace
Drupal\KernelTests\Core\DatabaseView source
abstract class DatabaseTestBase extends KernelTestBase {
use DatabaseTestSchemaDataTrait;
use DatabaseTestSchemaInstallTrait;
protected static $modules = [
'database_test',
];
/**
* The database connection for testing.
*
* @var \Drupal\Core\Database\Connection
*/
protected $connection;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->connection = Database::getConnection();
$this->installSampleSchema();
$this->addSampleData();
}
/**
* Sets up tables for NULL handling.
*/
public function ensureSampleDataNull() {
$this->connection
->insert('test_null')
->fields([
'name',
'age',
])
->values([
'name' => 'Kermit',
'age' => 25,
])
->values([
'name' => 'Fozzie',
'age' => NULL,
])
->values([
'name' => 'Gonzo',
'age' => 27,
])
->execute();
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.