Skip to content

Commit

Permalink
Starting to banish TestManager, and replace it with a more normal PHP…
Browse files Browse the repository at this point in the history
…Unit test loader.
  • Loading branch information
markstory committed Feb 13, 2011
1 parent 681b999 commit 60590de
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 8 deletions.
9 changes: 6 additions & 3 deletions cake/console/shells/testsuite.php
Expand Up @@ -165,7 +165,6 @@ public function initialize() {

$this->_dispatcher = new CakeTestSuiteDispatcher();
$this->_dispatcher->loadTestFramework();
require_once CAKE . 'tests' . DS . 'lib' . DS . 'test_manager.php';
}

/**
Expand All @@ -178,14 +177,17 @@ protected function parseArgs() {
return;
}
$params = array(
'core' => false,
'app' => false,
'plugin' => null,
'output' => 'text',
);

$category = $this->args[0];

if ($category == 'app') {
if ($category == 'core') {
$params['core'] = true;
} elseif ($category == 'app') {
$params['app'] = true;
} elseif ($category != 'core') {
$params['plugin'] = $category;
Expand Down Expand Up @@ -252,11 +254,12 @@ public function main() {
*/
protected function run($runnerArgs, $options = array()) {
require_once CAKE . 'tests' . DS . 'lib' . DS . 'test_runner.php';
require_once CAKE . 'tests' . DS . 'lib' . DS . 'cake_test_loader.php';

restore_error_handler();
restore_error_handler();

$testCli = new TestRunner($runnerArgs);
$testCli = new TestRunner('CakeTestLoader', $runnerArgs);
$testCli->run($options);
}

Expand Down
80 changes: 80 additions & 0 deletions cake/tests/lib/cake_test_loader.php
@@ -0,0 +1,80 @@
<?php

class CakeTestLoader implements PHPUnit_Runner_TestSuiteLoader {

public function load($filePath, $params = '') {
$file = $this->_resolveTestFile($filePath, $params);

PHPUnit_Util_Class::collectStart();
PHPUnit_Util_Fileloader::checkAndLoad($file, false);
$loadedClasses = PHPUnit_Util_Class::collectEnd();

if (!empty($loadedClasses)) {
$testCaseClass = 'PHPUnit_Framework_TestCase';

foreach ($loadedClasses as $loadedClass) {
$class = new ReflectionClass($loadedClass);
$classFile = $class->getFileName();

if ($class->isSubclassOf($testCaseClass) &&
!$class->isAbstract()) {
$suiteClassName = $loadedClass;
$testCaseClass = $loadedClass;

if ($classFile == realpath($file)) {
break;
}
}

if ($class->hasMethod('suite')) {
$method = $class->getMethod('suite');

if (!$method->isAbstract() &&
$method->isPublic() &&
$method->isStatic()) {
$suiteClassName = $loadedClass;

if ($classFile == realpath($file)) {
break;
}
}
}
}
}

if (class_exists($suiteClassName, FALSE)) {
$class = new ReflectionClass($suiteClassName);

if ($class->getFileName() == realpath($file)) {
return $class;
}
}
}

public function reload(ReflectionClass $aClass) {
return $aClass;
}

/**
* Convert path fragments used by Cake's test runner to absolute paths that can be fed to PHPUnit.
*
* @return void
*/
protected function _resolveTestFile($filePath, $params) {
$basePath = $this->_basePath($params);
return $basePath . DS . $filePath . '.test.php';
}

protected function _basePath($params) {
$result = null;
if (!empty($params['core'])) {
$result = CORE_TEST_CASES;
} elseif (!empty($params['app'])) {
$result = APP_TEST_CASES;
} else if (!empty($params['plugin'])) {
$pluginPath = App::pluginPath($params['plugin']);
$result = $pluginPath . 'tests' . DS . 'cases';
}
return $result;
}
}
1 change: 1 addition & 0 deletions cake/tests/lib/test_manager.php
Expand Up @@ -16,6 +16,7 @@
* @since CakePHP(tm) v 1.2.0.4433
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
var_dump(debug_backtrace());
define('CORE_TEST_CASES', TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'cases');
define('CORE_TEST_GROUPS', TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'groups');
define('APP_TEST_CASES', TESTS . 'cases');
Expand Down
18 changes: 13 additions & 5 deletions cake/tests/lib/test_runner.php
Expand Up @@ -16,10 +16,15 @@
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

define('CORE_TEST_CASES', TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'cases');
define('APP_TEST_CASES', TESTS . 'cases');

require 'PHPUnit/TextUI/Command.php';
require_once 'test_manager.php';

require_once CAKE_TESTS_LIB . 'cake_test_suite.php';
require_once(CAKE_TESTS_LIB . 'cake_test_case.php');
require_once(CAKE_TESTS_LIB . 'controller_test_case.php');


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

Expand All @@ -35,7 +40,10 @@ class TestRunner extends PHPUnit_TextUI_Command {
*
* @param array $params list of options to be used for this run
*/
public function __construct($params = array()) {
public function __construct($loader, $params = array()) {
$this->arguments['loader'] = $loader;
$this->arguments['test'] = $params['case'];
$this->arguments['testFile'] = $params;
$this->_params = $params;
}

Expand All @@ -46,12 +54,12 @@ public function __construct($params = array()) {
* @return void
*/
protected function handleCustomTestSuite() {
$manager = new TestManager($this->_params);
/*$manager = new TestManager($this->_params);
if (!empty($this->_params['case'])) {
$this->arguments['test'] = $manager->getTestSuite();
$this->arguments['test']->setFixtureManager($manager->getFixtureManager());
$manager->loadCase($this->_params['case'] . '.test.php', $this->arguments['test']);
}
}*/
}
}

0 comments on commit 60590de

Please sign in to comment.