Adding Fixture manager overriding.

Refs #1511
This commit is contained in:
mark_story 2011-02-12 17:36:00 -05:00
parent 0a2822335c
commit 8c2e0815ec
3 changed files with 39 additions and 3 deletions

View file

@ -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;

View file

@ -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.');
}
}

View file

@ -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;
}
}