diff --git a/cake/console/shells/testsuite.php b/cake/console/shells/testsuite.php index b0c31831f..5a9202454 100644 --- a/cake/console/shells/testsuite.php +++ b/cake/console/shells/testsuite.php @@ -143,6 +143,8 @@ class TestSuiteShell extends Shell { ))->addOption('directive', array( 'help' => __('key[=value] Sets a php.ini value.'), 'default' => false + ))->addOption('fixture', array( + 'help' => __('Choose a custom fixture manager.'), )); return $parser; diff --git a/cake/tests/lib/cake_test_runner.php b/cake/tests/lib/cake_test_runner.php index 2cd81897c..99c228332 100644 --- a/cake/tests/lib/cake_test_runner.php +++ b/cake/tests/lib/cake_test_runner.php @@ -27,16 +27,39 @@ PHP_CodeCoverage_Filter::getInstance()->addFileToBlacklist(__FILE__, 'DEFAULT'); */ class CakeTestRunner extends PHPUnit_TextUI_TestRunner { +/** + * Actually run a suite of tests. Cake initializes fixtures here using the chosen fixture manager + * + * @param PHPUnit_Framework_Test $suite + * @param array $arguments + * @return void + */ public function doRun(PHPUnit_Framework_Test $suite, array $arguments = array()) { - $fixture = new CakeFixtureManager; + $fixture = $this->_getFixtureManager($arguments); foreach ($suite->getIterator() as $test) { if ($test instanceof CakeTestCase) { $fixture->fixturize($test); $test->fixtureManager = $fixture; } } - $r = parent::doRun($suite, $arguments); + $return = parent::doRun($suite, $arguments); $fixture->shutdown(); - return $r; + return $return; + } + +/** + * Get the fixture manager class specified or use the default one. + * + * @return instance of a fixture manager. + */ + protected function _getFixtureManager($arguments) { + if (!isset($arguments['fixtureManager'])) { + return new CakeFixtureManager(); + } + App::import('Lib', 'test_suite/' . Inflector::underscore($arguments['fixtureManagerΩ'])); + if (class_exists($arguments['fixtureManager'])) { + return new $arguments['fixtureManager']; + } + throw new Exception('No fixture manager found.'); } } \ No newline at end of file diff --git a/cake/tests/lib/cake_test_suite_command.php b/cake/tests/lib/cake_test_suite_command.php index ab786d74f..a86a38d31 100644 --- a/cake/tests/lib/cake_test_suite_command.php +++ b/cake/tests/lib/cake_test_suite_command.php @@ -47,6 +47,8 @@ class CakeTestSuiteCommand extends PHPUnit_TextUI_Command { $this->arguments['test'] = $params['case']; $this->arguments['testFile'] = $params; $this->_params = $params; + + $this->longOptions['fixture='] = 'handleFixture'; } /** @@ -127,4 +129,13 @@ class CakeTestSuiteCommand extends PHPUnit_TextUI_Command { } } +/** + * Handler for customizing the FixtureManager class/ + * + * @param string $class Name of the class that will be the fixture manager + * @return void + */ + function handleFixture($class) { + $this->arguments['fixtureManager'] = $class; + } } \ No newline at end of file