Commit d6d3f6a6 authored by webchick's avatar webchick

Issue #2553533 by alexpott, dawehner, amateescu, hussainweb:...

Issue #2553533 by alexpott, dawehner, amateescu, hussainweb: KernelTestBaseTNG is not cleaning up after itself
parent 8f94d838
...@@ -591,6 +591,20 @@ protected function tearDown() { ...@@ -591,6 +591,20 @@ protected function tearDown() {
$this->kernel->shutdown(); $this->kernel->shutdown();
} }
// Remove all prefixed tables.
$original_connection_info = Database::getConnectionInfo('simpletest_original_default');
$original_prefix = $original_connection_info['default']['prefix']['default'];
$test_connection_info = Database::getConnectionInfo('default');
$test_prefix = $test_connection_info['default']['prefix']['default'];
if ($original_prefix != $test_prefix) {
$tables = Database::getConnection()->schema()->findTables('%');
foreach ($tables as $table) {
if (Database::getConnection()->schema()->dropTable($table)) {
unset($tables[$table]);
}
}
}
// Free up memory: Own properties. // Free up memory: Own properties.
$this->classLoader = NULL; $this->classLoader = NULL;
$this->vfsRoot = NULL; $this->vfsRoot = NULL;
...@@ -618,13 +632,20 @@ protected function tearDown() { ...@@ -618,13 +632,20 @@ protected function tearDown() {
$this->container = NULL; $this->container = NULL;
new Settings(array()); new Settings(array());
parent::tearDown();
}
/**
* @after
*
* Additional tear down method to close the connection at the end.
*/
public function tearDownCloseDatabaseConnection() {
// Destroy the database connection, which for example removes the memory // Destroy the database connection, which for example removes the memory
// from sqlite in memory. // from sqlite in memory.
foreach (Database::getAllConnectionInfo() as $key => $targets) { foreach (Database::getAllConnectionInfo() as $key => $targets) {
Database::removeConnection($key); Database::removeConnection($key);
} }
parent::tearDown();
} }
/** /**
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
namespace Drupal\KernelTests; namespace Drupal\KernelTests;
use Drupal\Core\Database\Database;
use org\bovigo\vfs\vfsStream; use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\visitor\vfsStreamStructureVisitor; use org\bovigo\vfs\visitor\vfsStreamStructureVisitor;
...@@ -52,26 +53,10 @@ public function testBootEnvironment() { ...@@ -52,26 +53,10 @@ public function testBootEnvironment() {
* @covers ::getDatabaseConnectionInfo * @covers ::getDatabaseConnectionInfo
*/ */
public function testGetDatabaseConnectionInfoWithOutManualSetDbUrl() { public function testGetDatabaseConnectionInfoWithOutManualSetDbUrl() {
$this->setUp();
$options = $this->container->get('database')->getConnectionOptions(); $options = $this->container->get('database')->getConnectionOptions();
$this->assertSame($this->databasePrefix, $options['prefix']['default']); $this->assertSame($this->databasePrefix, $options['prefix']['default']);
} }
/**
* @covers ::getDatabaseConnectionInfo
*/
public function testGetDatabaseConnectionInfoWithManualSetDbUrl() {
if (!file_exists('/tmp')) {
$this->markTestSkipped();
}
putenv('SIMPLETEST_DB=sqlite://localhost//tmp/test2.sqlite');
$this->setUp();
$options = $this->container->get('database')->getConnectionOptions();
$this->assertNotEqual('', $options['prefix']['default']);
}
/** /**
* @covers ::setUp * @covers ::setUp
*/ */
...@@ -216,4 +201,29 @@ public function testRenderWithTheme() { ...@@ -216,4 +201,29 @@ public function testRenderWithTheme() {
$this->assertRegExp($expected, (string) $output); $this->assertRegExp($expected, (string) $output);
} }
/**
* {@inheritdoc}
*/
protected function tearDown() {
parent::tearDown();
// Check that all tables of the test instance have been deleted. At this
// point the original database connection is restored so we need to prefix
// the tables.
$connection = Database::getConnection();
if ($connection->databaseType() != 'sqlite') {
$tables = $connection->schema()->findTables($this->databasePrefix . '%');
$this->assertTrue(empty($tables), 'All test tables have been removed.');
}
else {
$result = $connection->query("SELECT name FROM " . $this->databasePrefix . ".sqlite_master WHERE type = :type AND name LIKE :table_name AND name NOT LIKE :pattern", array(
':type' => 'table',
':table_name' => '%',
':pattern' => 'sqlite_%',
))->fetchAllKeyed(0, 0);
$this->assertTrue(empty($result), 'All test tables have been removed.');
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment