Skip to content

Commit

Permalink
A major surgery for FixtureManager, to fix failing tests in travis
Browse files Browse the repository at this point in the history
Some important changes:

* Tables are not dropped at the end of the test suite
* Tables are not dropped by default at the end of each test
  • Loading branch information
lorenzo committed Mar 28, 2014
1 parent db2f455 commit dc839a1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
2 changes: 0 additions & 2 deletions src/TestSuite/Fixture/FixtureInjector.php
Expand Up @@ -62,7 +62,6 @@ public function startTestSuite(PHPUnit_Framework_TestSuite $suite) {
* @return void
*/
public function endTestSuite(PHPUnit_Framework_TestSuite $suite) {
$this->_fixtureManager->shutdown();
}

/**
Expand Down Expand Up @@ -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);
}
Expand Down
11 changes: 8 additions & 3 deletions src/TestSuite/Fixture/FixtureManager.php
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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];
Expand All @@ -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);
}
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 2 additions & 3 deletions src/TestSuite/TestCase.php
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions tests/TestCase/Database/ConnectionTest.php
Expand Up @@ -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');
}

/**
Expand Down

0 comments on commit dc839a1

Please sign in to comment.