diff --git a/src/TestSuite/Fixture/FixtureInjector.php b/src/TestSuite/Fixture/FixtureInjector.php index 02be1a1d873..69fd58f03e8 100644 --- a/src/TestSuite/Fixture/FixtureInjector.php +++ b/src/TestSuite/Fixture/FixtureInjector.php @@ -62,7 +62,6 @@ public function startTestSuite(PHPUnit_Framework_TestSuite $suite) { * @return void */ public function endTestSuite(PHPUnit_Framework_TestSuite $suite) { - $this->_fixtureManager->shutdown(); } /** @@ -116,7 +115,6 @@ public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time * @return void */ public function startTest(PHPUnit_Framework_Test $test) { - $this->_fixtureManager->fixturize($test); $test->fixtureManager = $this->_fixtureManager; $this->_fixtureManager->load($test); } diff --git a/src/TestSuite/Fixture/FixtureManager.php b/src/TestSuite/Fixture/FixtureManager.php index fd2b5365e94..e16310a6b75 100644 --- a/src/TestSuite/Fixture/FixtureManager.php +++ b/src/TestSuite/Fixture/FixtureManager.php @@ -64,7 +64,6 @@ public function fixturize($test) { if (empty($test->fixtures) || !empty($this->_processed[get_class($test)])) { return; } - $test->db = ConnectionManager::get('test', false); if (!is_array($test->fixtures)) { $test->fixtures = array_map('trim', explode(',', $test->fixtures)); } @@ -224,6 +223,7 @@ public function load(TestCase $test) { } $dbs = []; + $this->fixturize($test); foreach ($fixtures as $f) { if (!empty($this->_loaded[$f])) { $fixture = $this->_loaded[$f]; @@ -235,7 +235,9 @@ public function load(TestCase $test) { $db = ConnectionManager::get($fixture->connection, false); $db->transactional(function($db) use ($fixtures, $test) { foreach ($fixtures as $fixture) { - $this->_setupTable($fixture, $db, $test->dropTables); + if (!in_array($db->configName(), (array)$fixture->created)) { + $this->_setupTable($fixture, $db, $test->dropTables); + } $fixture->truncate($db); $fixture->insert($db); } @@ -283,7 +285,10 @@ public function loadSingle($name, $db = null, $dropTables = true) { if (!$db) { $db = ConnectionManager::get($fixture->connection); } - $this->_setupTable($fixture, $db, $dropTables); + + if (!in_array($db->configName(), (array)$fixture->created)) { + $this->_setupTable($fixture, $db, $test->dropTables); + } $fixture->truncate($db); $fixture->insert($db); } else { diff --git a/src/TestSuite/TestCase.php b/src/TestSuite/TestCase.php index 4d6799b9411..c9ca49a7003 100644 --- a/src/TestSuite/TestCase.php +++ b/src/TestSuite/TestCase.php @@ -47,13 +47,12 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase { /** * Control table create/drops on each test method. * - * Set this to false to avoid tables to be dropped if they already exist - * between each test method. Tables will still be dropped at the + * If true, tables will still be dropped at the * end of each test runner execution. * * @var boolean */ - public $dropTables = true; + public $dropTables = false; /** * Configure values to restore at end of test. diff --git a/tests/TestCase/Database/ConnectionTest.php b/tests/TestCase/Database/ConnectionTest.php index ae67c8c61a2..f679ceb5dc5 100644 --- a/tests/TestCase/Database/ConnectionTest.php +++ b/tests/TestCase/Database/ConnectionTest.php @@ -124,10 +124,14 @@ public function testWrongCredentials() { * @return void **/ public function testDisconnect() { + $config = ConnectionManager::config('test'); + ConnectionManager::config('test_disconnect', $config); + $this->connection = ConnectionManager::get('test_disconnect'); $this->assertTrue($this->connection->connect()); $this->assertTrue($this->connection->isConnected()); $this->connection->disconnect(); $this->assertFalse($this->connection->isConnected()); + ConnectionManager::drop('test_disconnect'); } /**