From f0036b3ebcbba83a1ad7803ecbd6050869922681 Mon Sep 17 00:00:00 2001 From: Stephen Young Date: Sat, 7 Dec 2013 09:47:06 -0500 Subject: [PATCH 1/2] CakeFixtureManager::load now calls CakeTestFixture::truncate --- .../Fixture/CakeFixtureManagerTest.php | 103 ++++++++++++++++++ .../TestSuite/Fixture/CakeFixtureManager.php | 1 + 2 files changed, 104 insertions(+) create mode 100644 lib/Cake/Test/Case/TestSuite/Fixture/CakeFixtureManagerTest.php diff --git a/lib/Cake/Test/Case/TestSuite/Fixture/CakeFixtureManagerTest.php b/lib/Cake/Test/Case/TestSuite/Fixture/CakeFixtureManagerTest.php new file mode 100644 index 000000000..3a9b956c5 --- /dev/null +++ b/lib/Cake/Test/Case/TestSuite/Fixture/CakeFixtureManagerTest.php @@ -0,0 +1,103 @@ +fixtureManager = new CakeFixtureManager(); + } + +/** + * tearDown + * + * @return void + */ + public function tearDown() { + parent::tearDown(); + unset($this->fixtureManager); + } + +/** + * testLoadTruncatesTable + * + * @return void + */ + public function testLoadTruncatesTable() { + $MockFixture = $this->getMock('UuidFixture', array('truncate')); + $MockFixture + ->expects($this->once()) + ->method('truncate') + ->will($this->returnValue(true)); + + $fixtureManager = $this->fixtureManager; + $fixtureManagerReflection = new ReflectionClass($fixtureManager); + + $_loadedProperty = $fixtureManagerReflection->getProperty('_loaded'); + $_loadedProperty->setAccessible(true); + $_loadedProperty->setValue($fixtureManager, array('core.uuid' => $MockFixture)); + + $TestCase = $this->getMock('CakeTestCase'); + $TestCase->fixtures = array('core.uuid'); + $TestCase->autoFixtures = true; + $TestCase->dropTables = false; + + $fixtureManager->load($TestCase); + } + +/** + * testLoadSingleTruncatesTable + * + * @return void + */ + public function testLoadSingleTruncatesTable() { + $MockFixture = $this->getMock('UuidFixture', array('truncate')); + $MockFixture + ->expects($this->once()) + ->method('truncate') + ->will($this->returnValue(true)); + + $fixtureManager = $this->fixtureManager; + $fixtureManagerReflection = new ReflectionClass($fixtureManager); + + $_fixtureMapProperty = $fixtureManagerReflection->getProperty('_fixtureMap'); + $_fixtureMapProperty->setAccessible(true); + $_fixtureMapProperty->setValue($fixtureManager, array('UuidFixture' => $MockFixture)); + + $dboMethods = array_diff(get_class_methods('DboSource'), array('enabled')); + $dboMethods[] = 'connect'; + $db = $this->getMock('DboSource', $dboMethods); + $db->config['prefix'] = ''; + + $fixtureManager->loadSingle('Uuid', $db, false); + } +} diff --git a/lib/Cake/TestSuite/Fixture/CakeFixtureManager.php b/lib/Cake/TestSuite/Fixture/CakeFixtureManager.php index f4a833080..ec53163c5 100644 --- a/lib/Cake/TestSuite/Fixture/CakeFixtureManager.php +++ b/lib/Cake/TestSuite/Fixture/CakeFixtureManager.php @@ -209,6 +209,7 @@ class CakeFixtureManager { $db = ConnectionManager::getDataSource($fixture->useDbConfig); $db->begin(); $this->_setupTable($fixture, $db, $test->dropTables); + $fixture->truncate($db); $fixture->insert($db); $db->commit(); } From 8645e05ab152f5d4e83c3435cdbe7519512eefa2 Mon Sep 17 00:00:00 2001 From: Stephen Young Date: Sat, 7 Dec 2013 12:10:03 -0500 Subject: [PATCH 2/2] Removed leading underscores from ReflectionProperty variables in test case --- .../TestSuite/Fixture/CakeFixtureManagerTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/Cake/Test/Case/TestSuite/Fixture/CakeFixtureManagerTest.php b/lib/Cake/Test/Case/TestSuite/Fixture/CakeFixtureManagerTest.php index 3a9b956c5..d33f23406 100644 --- a/lib/Cake/Test/Case/TestSuite/Fixture/CakeFixtureManagerTest.php +++ b/lib/Cake/Test/Case/TestSuite/Fixture/CakeFixtureManagerTest.php @@ -62,9 +62,9 @@ class CakeFixtureManagerTest extends CakeTestCase { $fixtureManager = $this->fixtureManager; $fixtureManagerReflection = new ReflectionClass($fixtureManager); - $_loadedProperty = $fixtureManagerReflection->getProperty('_loaded'); - $_loadedProperty->setAccessible(true); - $_loadedProperty->setValue($fixtureManager, array('core.uuid' => $MockFixture)); + $loadedProperty = $fixtureManagerReflection->getProperty('_loaded'); + $loadedProperty->setAccessible(true); + $loadedProperty->setValue($fixtureManager, array('core.uuid' => $MockFixture)); $TestCase = $this->getMock('CakeTestCase'); $TestCase->fixtures = array('core.uuid'); @@ -89,9 +89,9 @@ class CakeFixtureManagerTest extends CakeTestCase { $fixtureManager = $this->fixtureManager; $fixtureManagerReflection = new ReflectionClass($fixtureManager); - $_fixtureMapProperty = $fixtureManagerReflection->getProperty('_fixtureMap'); - $_fixtureMapProperty->setAccessible(true); - $_fixtureMapProperty->setValue($fixtureManager, array('UuidFixture' => $MockFixture)); + $fixtureMapProperty = $fixtureManagerReflection->getProperty('_fixtureMap'); + $fixtureMapProperty->setAccessible(true); + $fixtureMapProperty->setValue($fixtureManager, array('UuidFixture' => $MockFixture)); $dboMethods = array_diff(get_class_methods('DboSource'), array('enabled')); $dboMethods[] = 'connect';