DatabaseTestBase.php
Same filename in this branch
Same filename in other branches
- 9 core/modules/system/tests/src/Functional/Database/DatabaseTestBase.php
- 9 core/tests/Drupal/KernelTests/Core/Database/DatabaseTestBase.php
- 8.9.x core/modules/system/tests/src/Functional/Database/DatabaseTestBase.php
- 8.9.x core/tests/Drupal/KernelTests/Core/Database/DatabaseTestBase.php
- 11.x core/modules/system/tests/src/Functional/Database/DatabaseTestBase.php
- 11.x core/tests/Drupal/KernelTests/Core/Database/DatabaseTestBase.php
Namespace
Drupal\KernelTests\Core\DatabaseFile
-
core/
tests/ Drupal/ KernelTests/ Core/ Database/ DatabaseTestBase.php
View source
<?php
declare (strict_types=1);
namespace Drupal\KernelTests\Core\Database;
use Drupal\Core\Database\Database;
use Drupal\KernelTests\KernelTestBase;
/**
* Base class for databases database tests.
*
* Because all database tests share the same test data, we can centralize that
* here.
*/
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() : void {
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' => 'Ernie',
'age' => NULL,
])
->values([
'name' => 'Gonzo',
'age' => 27,
])
->execute();
}
}
Classes
Title | Deprecated | Summary |
---|---|---|
DatabaseTestBase | Base class for databases database tests. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.