mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-03-18 23:49:55 +00:00
Starting to banish TestManager, and replace it with a more normal PHPUnit test loader.
This commit is contained in:
parent
681b9997b0
commit
60590de6bc
4 changed files with 100 additions and 8 deletions
|
@ -165,7 +165,6 @@ class TestSuiteShell extends Shell {
|
||||||
|
|
||||||
$this->_dispatcher = new CakeTestSuiteDispatcher();
|
$this->_dispatcher = new CakeTestSuiteDispatcher();
|
||||||
$this->_dispatcher->loadTestFramework();
|
$this->_dispatcher->loadTestFramework();
|
||||||
require_once CAKE . 'tests' . DS . 'lib' . DS . 'test_manager.php';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -178,6 +177,7 @@ class TestSuiteShell extends Shell {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$params = array(
|
$params = array(
|
||||||
|
'core' => false,
|
||||||
'app' => false,
|
'app' => false,
|
||||||
'plugin' => null,
|
'plugin' => null,
|
||||||
'output' => 'text',
|
'output' => 'text',
|
||||||
|
@ -185,7 +185,9 @@ class TestSuiteShell extends Shell {
|
||||||
|
|
||||||
$category = $this->args[0];
|
$category = $this->args[0];
|
||||||
|
|
||||||
if ($category == 'app') {
|
if ($category == 'core') {
|
||||||
|
$params['core'] = true;
|
||||||
|
} elseif ($category == 'app') {
|
||||||
$params['app'] = true;
|
$params['app'] = true;
|
||||||
} elseif ($category != 'core') {
|
} elseif ($category != 'core') {
|
||||||
$params['plugin'] = $category;
|
$params['plugin'] = $category;
|
||||||
|
@ -252,11 +254,12 @@ class TestSuiteShell extends Shell {
|
||||||
*/
|
*/
|
||||||
protected function run($runnerArgs, $options = array()) {
|
protected function run($runnerArgs, $options = array()) {
|
||||||
require_once CAKE . 'tests' . DS . 'lib' . DS . 'test_runner.php';
|
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();
|
||||||
restore_error_handler();
|
restore_error_handler();
|
||||||
|
|
||||||
$testCli = new TestRunner($runnerArgs);
|
$testCli = new TestRunner('CakeTestLoader', $runnerArgs);
|
||||||
$testCli->run($options);
|
$testCli->run($options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
80
cake/tests/lib/cake_test_loader.php
Normal file
80
cake/tests/lib/cake_test_loader.php
Normal file
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,6 +16,7 @@
|
||||||
* @since CakePHP(tm) v 1.2.0.4433
|
* @since CakePHP(tm) v 1.2.0.4433
|
||||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
* @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_CASES', TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'cases');
|
||||||
define('CORE_TEST_GROUPS', TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'groups');
|
define('CORE_TEST_GROUPS', TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'groups');
|
||||||
define('APP_TEST_CASES', TESTS . 'cases');
|
define('APP_TEST_CASES', TESTS . 'cases');
|
||||||
|
|
|
@ -16,10 +16,15 @@
|
||||||
* @since CakePHP(tm) v 2.0
|
* @since CakePHP(tm) v 2.0
|
||||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
* @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 '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');
|
PHP_CodeCoverage_Filter::getInstance()->addFileToBlacklist(__FILE__, 'DEFAULT');
|
||||||
|
|
||||||
|
@ -35,7 +40,10 @@ class TestRunner extends PHPUnit_TextUI_Command {
|
||||||
*
|
*
|
||||||
* @param array $params list of options to be used for this run
|
* @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;
|
$this->_params = $params;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,12 +54,12 @@ class TestRunner extends PHPUnit_TextUI_Command {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function handleCustomTestSuite() {
|
protected function handleCustomTestSuite() {
|
||||||
$manager = new TestManager($this->_params);
|
/*$manager = new TestManager($this->_params);
|
||||||
|
|
||||||
if (!empty($this->_params['case'])) {
|
if (!empty($this->_params['case'])) {
|
||||||
$this->arguments['test'] = $manager->getTestSuite();
|
$this->arguments['test'] = $manager->getTestSuite();
|
||||||
$this->arguments['test']->setFixtureManager($manager->getFixtureManager());
|
$this->arguments['test']->setFixtureManager($manager->getFixtureManager());
|
||||||
$manager->loadCase($this->_params['case'] . '.test.php', $this->arguments['test']);
|
$manager->loadCase($this->_params['case'] . '.test.php', $this->arguments['test']);
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue