Browse Source

A major surgery for FixtureManager, to fix failing tests in travis

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
Jose Lorenzo Rodriguez 12 years ago
parent
commit
dc839a1092

+ 0 - 2
src/TestSuite/Fixture/FixtureInjector.php

@@ -62,7 +62,6 @@ class FixtureInjector implements PHPUnit_Framework_TestListener {
  * @return void
  */
 	public function endTestSuite(PHPUnit_Framework_TestSuite $suite) {
-		$this->_fixtureManager->shutdown();
 	}
 
 /**
@@ -116,7 +115,6 @@ class FixtureInjector implements PHPUnit_Framework_TestListener {
  * @return void
  */
 	public function startTest(PHPUnit_Framework_Test $test) {
-		$this->_fixtureManager->fixturize($test);
 		$test->fixtureManager = $this->_fixtureManager;
 		$this->_fixtureManager->load($test);
 	}

+ 8 - 3
src/TestSuite/Fixture/FixtureManager.php

@@ -64,7 +64,6 @@ class FixtureManager {
 		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 @@ class FixtureManager {
 		}
 
 		$dbs = [];
+		$this->fixturize($test);
 		foreach ($fixtures as $f) {
 			if (!empty($this->_loaded[$f])) {
 				$fixture = $this->_loaded[$f];
@@ -235,7 +235,9 @@ class FixtureManager {
 				$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 @@ class FixtureManager {
 			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 {

+ 2 - 3
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.

+ 4 - 0
tests/TestCase/Database/ConnectionTest.php

@@ -124,10 +124,14 @@ class ConnectionTest extends TestCase {
  * @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');
 	}
 
 /**