Skip to content

Commit

Permalink
Adding Fixture manager overriding.
Browse files Browse the repository at this point in the history
Refs #1511
  • Loading branch information
markstory committed Feb 13, 2011
1 parent 0a28223 commit 8c2e081
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
2 changes: 2 additions & 0 deletions cake/console/shells/testsuite.php
Expand Up @@ -143,6 +143,8 @@ public function getOptionParser() {
))->addOption('directive', array(
'help' => __('key[=value] Sets a php.ini value.'),
'default' => false
))->addOption('fixture', array(
'help' => __('Choose a custom fixture manager.'),
));

return $parser;
Expand Down
29 changes: 26 additions & 3 deletions cake/tests/lib/cake_test_runner.php
Expand Up @@ -27,16 +27,39 @@
*/
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.');
}
}
11 changes: 11 additions & 0 deletions cake/tests/lib/cake_test_suite_command.php
Expand Up @@ -47,6 +47,8 @@ public function __construct($loader, $params = array()) {
$this->arguments['test'] = $params['case'];
$this->arguments['testFile'] = $params;
$this->_params = $params;

$this->longOptions['fixture='] = 'handleFixture';
}

/**
Expand Down Expand Up @@ -127,4 +129,13 @@ public function run(array $argv, $exit = TRUE)
}
}

/**
* 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;
}
}

0 comments on commit 8c2e081

Please sign in to comment.