Skip to content

Commit

Permalink
Running individual tests from the web runner now works.
Browse files Browse the repository at this point in the history
Adding some more hooks, so webrunner can swap out result printers like it did before.
  • Loading branch information
markstory committed Feb 13, 2011
1 parent 8ebbccb commit 16481d7
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 11 deletions.
5 changes: 5 additions & 0 deletions cake/tests/lib/cake_test_runner.php
Expand Up @@ -35,13 +35,18 @@ class CakeTestRunner extends PHPUnit_TextUI_TestRunner {
* @return void
*/
public function doRun(PHPUnit_Framework_Test $suite, array $arguments = array()) {
if (isset($arguments['printer'])) {
self::$versionStringPrinted = true;
}

$fixture = $this->_getFixtureManager($arguments);
foreach ($suite->getIterator() as $test) {
if ($test instanceof CakeTestCase) {
$fixture->fixturize($test);
$test->fixtureManager = $fixture;
}
}

$return = parent::doRun($suite, $arguments);
$fixture->shutdown();
return $return;
Expand Down
23 changes: 23 additions & 0 deletions cake/tests/lib/cake_test_suite_command.php
Expand Up @@ -49,6 +49,7 @@ public function __construct($loader, $params = array()) {
$this->_params = $params;

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

/**
Expand Down Expand Up @@ -140,4 +141,26 @@ public function run(array $argv, $exit = TRUE)
function handleFixture($class) {
$this->arguments['fixtureManager'] = $class;
}

/**
* Handles output flag used to change printing on webrunner.
*
* @return void
*/
public function handleReporter($reporter) {
$object = null;

$type = strtolower($reporter);
$coreClass = 'Cake' . ucwords($reporter) . 'Reporter';
$coreFile = CAKE_TESTS_LIB . 'reporter/cake_' . $type . '_reporter.php';

$appClass = $reporter . 'Reporter';
$appFile = APPLIBS . 'test_suite/reporter/' . $type . '_reporter.php';
if (include_once $coreFile) {
$object = new $coreClass(null, $this->_params);
} elseif (include_once $appFile) {
$object = new $appClass(null, $this->_params);
}
$this->arguments['printer'] = $object;
}
}
34 changes: 24 additions & 10 deletions cake/tests/lib/cake_test_suite_dispatcher.php
Expand Up @@ -39,13 +39,6 @@ class CakeTestSuiteDispatcher {
'filter' => false
);

/**
* The classname for the TestManager being used
*
* @var string
*/
protected $_managerClass = 'TestManager';

/**
* The Instance of the Manager being used.
*
Expand Down Expand Up @@ -260,9 +253,11 @@ function _parseParams() {
$this->_checkXdebug();
}
}
if (empty($this->params['plugin']) && empty($this->params['app'])) {
$this->params['core'] = true;
}
$this->params['baseUrl'] = $this->_baseUrl;
$this->params['baseDir'] = $this->_baseDir;
$this->getManager();
}

/**
Expand All @@ -271,9 +266,28 @@ function _parseParams() {
* @return void
*/
function _runTestCase() {
require_once CAKE . 'tests' . DS . 'lib' . DS . 'cake_test_suite_command.php';

$Reporter = CakeTestSuiteDispatcher::getReporter();

$commandArgs = array(
'case' => $this->params['case'],
'core' =>$this->params['core'],
'app' => $this->params['app'],
'plugin' => $this->params['plugin'],
'codeCoverage' => $this->params['codeCoverage'],
'baseUrl' => $this->_baseUrl,
'baseDir' => $this->_baseDir,
);

$options = array(
'--filter', $this->params['filter'],
'--output', $this->params['output']
);

try {
$Reporter = CakeTestSuiteDispatcher::getReporter();
return $this->Manager->runTestCase($this->params['case'], $Reporter, $this->params['codeCoverage']);
$command = new CakeTestSuiteCommand('CakeTestLoader', $commandArgs);
$result = $command->run($options);
} catch (MissingConnectionException $exception) {
ob_end_clean();
$baseDir = $this->_baseDir;
Expand Down
7 changes: 6 additions & 1 deletion cake/tests/lib/reporter/cake_base_reporter.php
Expand Up @@ -16,6 +16,7 @@
* @since CakePHP(tm) v 1.3
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
require_once 'PHPUnit/TextUi/ResultPrinter.php';

PHP_CodeCoverage_Filter::getInstance()->addFileToBlacklist(__FILE__, 'DEFAULT');

Expand All @@ -25,7 +26,7 @@
* @package cake
* @package cake.tests.lib
*/
class CakeBaseReporter implements PHPUnit_Framework_TestListener {
class CakeBaseReporter extends PHPUnit_TextUI_ResultPrinter {

/**
* Time the test runs started.
Expand Down Expand Up @@ -146,6 +147,10 @@ public function baseUrl() {
return '';
}

public function printResult(PHPUnit_Framework_TestResult $result) {
$this->paintFooter($result);
}

public function paintResult(PHPUnit_Framework_TestResult $result) {
$this->paintFooter($result);
}
Expand Down
1 change: 1 addition & 0 deletions cake/tests/lib/reporter/cake_html_reporter.php
Expand Up @@ -340,6 +340,7 @@ protected function _getStackTrace(Exception $e) {
* @param PHPUnit_Framework_TestSuite $suite
*/
public function startTestSuite(PHPUnit_Framework_TestSuite $suite) {
echo $this->paintHeader();
echo '<h2>' . __('Running %s', $suite->getName()) . '</h2>';
}
}

0 comments on commit 16481d7

Please sign in to comment.