From 5d041c58b7d781acf85969686ac373e9e4b10e5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Lorenzo=20Rodr=C3=ADguez?= Date: Sat, 8 May 2010 15:55:16 -0430 Subject: [PATCH] Using the CakeTesSuite in TestManager and calling accordingly the load and unload of fixtures using the variable $sharedFixture --- cake/tests/lib/cake_test_case.php | 21 ++++++++++++--------- cake/tests/lib/test_manager.php | 22 +++++++++++++++++++--- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/cake/tests/lib/cake_test_case.php b/cake/tests/lib/cake_test_case.php index b242a184a..27ec7a586 100644 --- a/cake/tests/lib/cake_test_case.php +++ b/cake/tests/lib/cake_test_case.php @@ -63,12 +63,6 @@ class CakeTestCase extends PHPUnit_Framework_TestCase { */ private $__savedGetData = array(); - public function __construct($name = null, array $data = array(), $dataName = '') { - parent::__construct($name, $data, $dataName); - if (!empty($this->fixtures)) { - CakeFixtureManager::fixturize($this); - } - } /** * Called when a test case (group of methods) is about to start (to be overriden when needed.) * @@ -127,7 +121,9 @@ class CakeTestCase extends PHPUnit_Framework_TestCase { */ protected function assertPreConditions() { parent::assertPreConditions(); - CakeFixtureManager::load($this); + if (!empty($this->sharedFixture)) { + $this->sharedFixture->load($this); + } if (!in_array(strtolower($this->getName()), $this->methods)) { $this->startTest($this->getName()); } @@ -162,7 +158,9 @@ class CakeTestCase extends PHPUnit_Framework_TestCase { */ protected function assertPostConditions() { parent::assertPostConditions(); - CakeFixtureManager::unload($this); + if (!empty($this->sharedFixture)) { + $this->sharedFixture->unload($this); + } if (!in_array(strtolower($this->getName()), $this->methods)) { $this->endTest($this->getName()); } @@ -192,9 +190,14 @@ class CakeTestCase extends PHPUnit_Framework_TestCase { * @see CakeTestCase::$autoFixtures */ function loadFixtures() { + if (empty($this->sharedFixture)) { + throw new Exception(__('No fixture manager to load the test fixture')); + } $args = func_get_args(); foreach ($args as $class) { - CakeFixtureManager::loadSingle($class); + if (!empty($this->sharedFixture)) { + $this->sharedFixture->unload($this); + } } } diff --git a/cake/tests/lib/test_manager.php b/cake/tests/lib/test_manager.php index a9c14bade..8bf9f0706 100644 --- a/cake/tests/lib/test_manager.php +++ b/cake/tests/lib/test_manager.php @@ -22,6 +22,7 @@ define('CORE_TEST_GROUPS', TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'groups' define('APP_TEST_CASES', TESTS . 'cases'); define('APP_TEST_GROUPS', TESTS . 'groups'); +require_once CAKE_TESTS_LIB . 'cake_test_suite.php'; /** * TestManager is the base class that handles loading and initiating the running * of TestCase and TestSuite classes that the user has selected. @@ -61,10 +62,17 @@ class TestManager { /** * TestSuite container for single or grouped test files * - * @var PHPUnit_Framework_TestSuiteboolean + * @var PHPUnit_Framework_TestSuite */ protected $_testSuit = null; +/** + * Object instance responsible for managing the test fixtures + * + * @var CakeFixtureManager + */ + protected $_fixtureManager = null; + /** * Constructor for the TestManager class * @@ -162,7 +170,9 @@ class TestManager { $result = new PHPUnit_Framework_TestResult; $result->addListener($reporter); $reporter->paintHeader(); - $this->getTestSuite()->run($result); + $testSuite = $this->getTestSuite(); + $testSuite->setFixtureManager($this->getFixtureManager()); + $testSuite->run($result); $reporter->paintResult($result); return $result; } @@ -395,9 +405,15 @@ class TestManager { if (!empty($this->_testSuite)) { return $this->_testSuite; } - return $this->_testSuite = new PHPUnit_Framework_TestSuite($name); + return $this->_testSuite = new CakeTestSuite($name); } + protected function getFixtureManager() { + if (!empty($this->_fixtureManager)) { + return $this->_fixtureManager; + } + return $this->_fixtureManager = new CakeFixtureManager; + } } ?> \ No newline at end of file