Fix dropTables being ignore in some cases.

When autoFixtures = false & dropTables = false, individually loaded
fixtures should not be dropped.

Fixes #3691
This commit is contained in:
mark_story 2013-03-12 09:34:20 -04:00
parent f1da6b4cbc
commit 73310f9bfd
2 changed files with 8 additions and 3 deletions

View file

@ -43,7 +43,11 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
public $autoFixtures = true; public $autoFixtures = true;
/** /**
* Control table create/drops on each test method.
*
* Set this to false to avoid tables to be dropped if they already exist * 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
* end of each test runner execution.
* *
* @var boolean * @var boolean
*/ */
@ -205,7 +209,7 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
} }
$args = func_get_args(); $args = func_get_args();
foreach ($args as $class) { foreach ($args as $class) {
$this->fixtureManager->loadSingle($class); $this->fixtureManager->loadSingle($class, null, $this->dropTables);
} }
} }

View file

@ -243,17 +243,18 @@ class CakeFixtureManager {
* *
* @param string $name of the fixture * @param string $name of the fixture
* @param DataSource $db DataSource instance or leave null to get DataSource from the fixture * @param DataSource $db DataSource instance or leave null to get DataSource from the fixture
* @param boolean $dropTables Whether or not tables should be dropped and re-created.
* @return void * @return void
* @throws UnexpectedValueException if $name is not a previously loaded class * @throws UnexpectedValueException if $name is not a previously loaded class
*/ */
public function loadSingle($name, $db = null) { public function loadSingle($name, $db = null, $dropTables = true) {
$name .= 'Fixture'; $name .= 'Fixture';
if (isset($this->_fixtureMap[$name])) { if (isset($this->_fixtureMap[$name])) {
$fixture = $this->_fixtureMap[$name]; $fixture = $this->_fixtureMap[$name];
if (!$db) { if (!$db) {
$db = ConnectionManager::getDataSource($fixture->useDbConfig); $db = ConnectionManager::getDataSource($fixture->useDbConfig);
} }
$this->_setupTable($fixture, $db); $this->_setupTable($fixture, $db, $dropTables);
$fixture->truncate($db); $fixture->truncate($db);
$fixture->insert($db); $fixture->insert($db);
} else { } else {