2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2011-10-18 10:18:01 +00:00
|
|
|
* Test Shell
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* This Shell allows the running of test suites via the cake command line
|
|
|
|
*
|
2010-10-03 16:38:58 +00:00
|
|
|
* PHP 5
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-05-19 01:15:13 +00:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
2012-03-13 02:46:07 +00:00
|
|
|
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:38:58 +00:00
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2012-03-13 02:46:07 +00:00
|
|
|
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-05-19 01:15:13 +00:00
|
|
|
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 1.2.0.4433
|
2010-10-03 16:38:58 +00:00
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-12-08 06:19:36 +00:00
|
|
|
|
2011-03-08 18:48:46 +00:00
|
|
|
App::uses('Shell', 'Console');
|
2010-12-08 06:19:36 +00:00
|
|
|
App::uses('CakeTestSuiteDispatcher', 'TestSuite');
|
2011-02-14 04:26:41 +00:00
|
|
|
App::uses('CakeTestSuiteCommand', 'TestSuite');
|
|
|
|
App::uses('CakeTestLoader', 'TestSuite');
|
2010-12-08 06:19:36 +00:00
|
|
|
|
2011-07-26 01:46:52 +00:00
|
|
|
/**
|
|
|
|
* Provides a CakePHP wrapper around PHPUnit.
|
|
|
|
* Adds in CakePHP's fixtures and gives access to plugin, app and core test cases
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Console.Command
|
2011-07-26 01:46:52 +00:00
|
|
|
*/
|
2011-05-07 18:10:55 +00:00
|
|
|
class TestShell extends Shell {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-06-26 17:49:21 +00:00
|
|
|
/**
|
|
|
|
* Dispatcher object for the run.
|
|
|
|
*
|
|
|
|
* @var CakeTestDispatcher
|
|
|
|
*/
|
|
|
|
protected $_dispatcher = null;
|
|
|
|
|
2010-10-12 03:06:50 +00:00
|
|
|
/**
|
|
|
|
* get the option parser for the test suite.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function getOptionParser() {
|
2010-10-15 02:15:01 +00:00
|
|
|
$parser = new ConsoleOptionParser($this->name);
|
2010-10-12 03:06:50 +00:00
|
|
|
$parser->description(array(
|
2011-04-25 19:17:59 +00:00
|
|
|
__d('cake_console', 'The CakePHP Testsuite allows you to run test cases from the command line'),
|
2011-10-20 02:26:51 +00:00
|
|
|
))->addArgument('category', array(
|
|
|
|
'help' => __d('cake_console', 'The category for the test, or test file, to test.'),
|
|
|
|
'required' => false,
|
2010-10-12 03:06:50 +00:00
|
|
|
))->addArgument('file', array(
|
2011-10-18 08:28:05 +00:00
|
|
|
'help' => __d('cake_console', 'The path to the file, or test file, to test.'),
|
2010-11-03 05:57:37 +00:00
|
|
|
'required' => false,
|
2010-11-03 05:55:27 +00:00
|
|
|
))->addOption('log-junit', array(
|
2011-03-19 17:32:35 +00:00
|
|
|
'help' => __d('cake_console', '<file> Log test execution in JUnit XML format to file.'),
|
2010-11-03 05:55:27 +00:00
|
|
|
'default' => false
|
|
|
|
))->addOption('log-json', array(
|
2011-03-19 17:32:35 +00:00
|
|
|
'help' => __d('cake_console', '<file> Log test execution in TAP format to file.'),
|
2010-11-03 05:55:27 +00:00
|
|
|
'default' => false
|
|
|
|
))->addOption('log-tap', array(
|
2011-03-19 17:32:35 +00:00
|
|
|
'help' => __d('cake_console', '<file> Log test execution in TAP format to file.'),
|
2010-11-03 05:55:27 +00:00
|
|
|
'default' => false
|
|
|
|
))->addOption('log-dbus', array(
|
2011-03-19 17:32:35 +00:00
|
|
|
'help' => __d('cake_console', 'Log test execution to DBUS.'),
|
2010-11-03 05:55:27 +00:00
|
|
|
'default' => false
|
2010-11-22 03:59:49 +00:00
|
|
|
))->addOption('coverage-html', array(
|
2011-03-19 17:32:35 +00:00
|
|
|
'help' => __d('cake_console', '<dir> Generate code coverage report in HTML format.'),
|
2010-11-03 05:55:27 +00:00
|
|
|
'default' => false
|
|
|
|
))->addOption('coverage-clover', array(
|
2011-03-19 17:32:35 +00:00
|
|
|
'help' => __d('cake_console', '<file> Write code coverage data in Clover XML format.'),
|
2010-11-03 05:55:27 +00:00
|
|
|
'default' => false
|
|
|
|
))->addOption('testdox-html', array(
|
2011-03-19 17:32:35 +00:00
|
|
|
'help' => __d('cake_console', '<file> Write agile documentation in HTML format to file.'),
|
2010-11-03 05:55:27 +00:00
|
|
|
'default' => false
|
|
|
|
))->addOption('testdox-text', array(
|
2011-03-19 17:32:35 +00:00
|
|
|
'help' => __d('cake_console', '<file> Write agile documentation in Text format to file.'),
|
2010-11-03 05:55:27 +00:00
|
|
|
'default' => false
|
2010-10-14 03:40:14 +00:00
|
|
|
))->addOption('filter', array(
|
2011-03-19 17:32:35 +00:00
|
|
|
'help' => __d('cake_console', '<pattern> Filter which tests to run.'),
|
2010-11-03 05:55:27 +00:00
|
|
|
'default' => false
|
|
|
|
))->addOption('group', array(
|
2011-03-19 17:32:35 +00:00
|
|
|
'help' => __d('cake_console', '<name> Only runs tests from the specified group(s).'),
|
2010-11-03 05:55:27 +00:00
|
|
|
'default' => false
|
|
|
|
))->addOption('exclude-group', array(
|
2011-03-19 17:32:35 +00:00
|
|
|
'help' => __d('cake_console', '<name> Exclude tests from the specified group(s).'),
|
2010-11-03 05:55:27 +00:00
|
|
|
'default' => false
|
|
|
|
))->addOption('list-groups', array(
|
2011-03-19 17:32:35 +00:00
|
|
|
'help' => __d('cake_console', 'List available test groups.'),
|
2010-11-03 05:55:27 +00:00
|
|
|
'boolean' => true
|
|
|
|
))->addOption('loader', array(
|
2011-03-19 17:32:35 +00:00
|
|
|
'help' => __d('cake_console', 'TestSuiteLoader implementation to use.'),
|
2010-11-03 05:55:27 +00:00
|
|
|
'default' => false
|
|
|
|
))->addOption('repeat', array(
|
2011-03-19 17:32:35 +00:00
|
|
|
'help' => __d('cake_console', '<times> Runs the test(s) repeatedly.'),
|
2010-11-03 05:55:27 +00:00
|
|
|
'default' => false
|
|
|
|
))->addOption('tap', array(
|
2011-03-19 17:32:35 +00:00
|
|
|
'help' => __d('cake_console', 'Report test execution progress in TAP format.'),
|
2010-11-03 05:55:27 +00:00
|
|
|
'boolean' => true
|
|
|
|
))->addOption('testdox', array(
|
2011-03-19 17:32:35 +00:00
|
|
|
'help' => __d('cake_console', 'Report test execution progress in TestDox format.'),
|
2010-11-03 05:55:27 +00:00
|
|
|
'default' => false,
|
|
|
|
'boolean' => true
|
|
|
|
))->addOption('no-colors', array(
|
2011-03-19 17:32:35 +00:00
|
|
|
'help' => __d('cake_console', 'Do not use colors in output.'),
|
2010-11-03 05:55:27 +00:00
|
|
|
'boolean' => true
|
|
|
|
))->addOption('stderr', array(
|
2011-03-19 17:32:35 +00:00
|
|
|
'help' => __d('cake_console', 'Write to STDERR instead of STDOUT.'),
|
2010-11-03 05:55:27 +00:00
|
|
|
'boolean' => true
|
2010-11-04 00:10:48 +00:00
|
|
|
))->addOption('stop-on-error', array(
|
2011-03-19 17:32:35 +00:00
|
|
|
'help' => __d('cake_console', 'Stop execution upon first error or failure.'),
|
2010-11-03 05:55:27 +00:00
|
|
|
'boolean' => true
|
2010-11-04 00:10:48 +00:00
|
|
|
))->addOption('stop-on-failure', array(
|
2011-03-19 17:32:35 +00:00
|
|
|
'help' => __d('cake_console', 'Stop execution upon first failure.'),
|
2010-11-04 00:10:48 +00:00
|
|
|
'boolean' => true
|
2010-11-03 05:55:27 +00:00
|
|
|
))->addOption('stop-on-skipped ', array(
|
2011-03-19 17:32:35 +00:00
|
|
|
'help' => __d('cake_console', 'Stop execution upon first skipped test.'),
|
2010-11-03 05:55:27 +00:00
|
|
|
'boolean' => true
|
|
|
|
))->addOption('stop-on-incomplete', array(
|
2011-03-19 17:32:35 +00:00
|
|
|
'help' => __d('cake_console', 'Stop execution upon first incomplete test.'),
|
2010-11-03 05:55:27 +00:00
|
|
|
'boolean' => true
|
|
|
|
))->addOption('strict', array(
|
2011-03-19 17:32:35 +00:00
|
|
|
'help' => __d('cake_console', 'Mark a test as incomplete if no assertions are made.'),
|
2010-11-03 05:55:27 +00:00
|
|
|
'boolean' => true
|
|
|
|
))->addOption('wait', array(
|
2011-03-19 17:32:35 +00:00
|
|
|
'help' => __d('cake_console', 'Waits for a keystroke after each test.'),
|
2010-11-03 05:55:27 +00:00
|
|
|
'boolean' => true
|
|
|
|
))->addOption('process-isolation', array(
|
2011-03-19 17:32:35 +00:00
|
|
|
'help' => __d('cake_console', 'Run each test in a separate PHP process.'),
|
2010-11-03 05:55:27 +00:00
|
|
|
'boolean' => true
|
|
|
|
))->addOption('no-globals-backup', array(
|
2011-03-19 17:32:35 +00:00
|
|
|
'help' => __d('cake_console', 'Do not backup and restore $GLOBALS for each test.'),
|
2010-11-03 05:55:27 +00:00
|
|
|
'boolean' => true
|
|
|
|
))->addOption('static-backup ', array(
|
2011-03-19 17:32:35 +00:00
|
|
|
'help' => __d('cake_console', 'Backup and restore static attributes for each test.'),
|
2010-11-03 05:55:27 +00:00
|
|
|
'boolean' => true
|
|
|
|
))->addOption('syntax-check', array(
|
2011-03-19 17:32:35 +00:00
|
|
|
'help' => __d('cake_console', 'Try to check source files for syntax errors.'),
|
2010-11-03 05:55:27 +00:00
|
|
|
'boolean' => true
|
|
|
|
))->addOption('bootstrap', array(
|
2011-03-19 17:32:35 +00:00
|
|
|
'help' => __d('cake_console', '<file> A "bootstrap" PHP file that is run before the tests.'),
|
2010-11-03 05:55:27 +00:00
|
|
|
'default' => false
|
2011-03-08 19:13:00 +00:00
|
|
|
))->addOption('configuration', array(
|
2011-03-19 17:32:35 +00:00
|
|
|
'help' => __d('cake_console', '<file> Read configuration from XML file.'),
|
2010-11-03 05:55:27 +00:00
|
|
|
'default' => false
|
|
|
|
))->addOption('no-configuration', array(
|
2011-03-19 17:32:35 +00:00
|
|
|
'help' => __d('cake_console', 'Ignore default configuration file (phpunit.xml).'),
|
2010-11-03 05:55:27 +00:00
|
|
|
'boolean' => true
|
|
|
|
))->addOption('include-path', array(
|
2011-03-19 17:32:35 +00:00
|
|
|
'help' => __d('cake_console', '<path(s)> Prepend PHP include_path with given path(s).'),
|
2010-11-03 05:55:27 +00:00
|
|
|
'default' => false
|
|
|
|
))->addOption('directive', array(
|
2011-03-19 17:32:35 +00:00
|
|
|
'help' => __d('cake_console', 'key[=value] Sets a php.ini value.'),
|
2010-10-14 03:40:14 +00:00
|
|
|
'default' => false
|
2011-02-12 22:36:00 +00:00
|
|
|
))->addOption('fixture', array(
|
2011-03-19 17:32:35 +00:00
|
|
|
'help' => __d('cake_console', 'Choose a custom fixture manager.'),
|
2011-08-23 02:29:32 +00:00
|
|
|
))->addOption('debug', array(
|
|
|
|
'help' => __d('cake_console', 'More verbose output.'),
|
2010-10-12 03:06:50 +00:00
|
|
|
));
|
2010-11-03 05:55:27 +00:00
|
|
|
|
2010-10-12 03:06:50 +00:00
|
|
|
return $parser;
|
|
|
|
}
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2011-04-25 19:17:59 +00:00
|
|
|
* Initialization method installs PHPUnit and loads all plugins
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2011-07-31 20:55:52 +00:00
|
|
|
* @throws Exception
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function initialize() {
|
2010-06-26 17:49:21 +00:00
|
|
|
$this->_dispatcher = new CakeTestSuiteDispatcher();
|
2011-04-21 17:56:50 +00:00
|
|
|
$sucess = $this->_dispatcher->loadTestFramework();
|
|
|
|
if (!$sucess) {
|
2011-04-21 17:58:49 +00:00
|
|
|
throw new Exception(__d('cake_dev', 'Please install PHPUnit framework <info>(http://www.phpunit.de)</info>'));
|
2011-04-21 17:56:50 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2010-06-26 17:49:21 +00:00
|
|
|
* Parse the CLI options into an array CakeTestDispatcher can use.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-06-26 17:49:21 +00:00
|
|
|
* @return array Array of params for CakeTestDispatcher
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2011-08-20 05:39:30 +00:00
|
|
|
protected function _parseArgs() {
|
2010-01-10 02:25:05 +00:00
|
|
|
if (empty($this->args)) {
|
|
|
|
return;
|
|
|
|
}
|
2010-06-26 17:49:21 +00:00
|
|
|
$params = array(
|
2011-02-12 20:51:00 +00:00
|
|
|
'core' => false,
|
2010-06-26 17:49:21 +00:00
|
|
|
'app' => false,
|
|
|
|
'plugin' => null,
|
|
|
|
'output' => 'text',
|
|
|
|
);
|
|
|
|
|
2011-05-28 23:19:14 +00:00
|
|
|
if (strpos($this->args[0], '.php')) {
|
|
|
|
$category = $this->_mapFileToCategory($this->args[0]);
|
|
|
|
$params['case'] = $this->_mapFileToCase($this->args[0], $category);
|
|
|
|
} else {
|
|
|
|
$category = $this->args[0];
|
|
|
|
if (isset($this->args[1])) {
|
|
|
|
$params['case'] = $this->args[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($category === 'core') {
|
2011-02-12 20:51:00 +00:00
|
|
|
$params['core'] = true;
|
2011-05-28 23:19:14 +00:00
|
|
|
} elseif ($category === 'app') {
|
2010-06-26 17:49:21 +00:00
|
|
|
$params['app'] = true;
|
2011-05-28 23:19:14 +00:00
|
|
|
} else {
|
2010-06-26 17:49:21 +00:00
|
|
|
$params['plugin'] = $category;
|
2010-01-10 01:20:51 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-06-26 17:49:21 +00:00
|
|
|
return $params;
|
2010-01-10 01:20:51 +00:00
|
|
|
}
|
|
|
|
|
2010-07-07 04:41:06 +00:00
|
|
|
/**
|
|
|
|
* Converts the options passed to the shell as options for the PHPUnit cli runner
|
|
|
|
*
|
|
|
|
* @return array Array of params for CakeTestDispatcher
|
|
|
|
*/
|
2011-08-20 05:39:30 +00:00
|
|
|
protected function _runnerOptions() {
|
2010-07-07 04:41:06 +00:00
|
|
|
$options = array();
|
2010-10-12 03:43:13 +00:00
|
|
|
$params = $this->params;
|
|
|
|
unset($params['help']);
|
2010-11-03 05:55:27 +00:00
|
|
|
|
|
|
|
if (!empty($params['no-colors'])) {
|
|
|
|
unset($params['no-colors'], $params['colors']);
|
|
|
|
} else {
|
|
|
|
$params['colors'] = true;
|
|
|
|
}
|
|
|
|
|
2010-10-12 03:43:13 +00:00
|
|
|
foreach ($params as $param => $value) {
|
2010-11-03 05:55:27 +00:00
|
|
|
if ($value === false) {
|
|
|
|
continue;
|
|
|
|
}
|
2010-10-11 05:33:24 +00:00
|
|
|
$options[] = '--' . $param;
|
|
|
|
if (is_string($value)) {
|
|
|
|
$options[] = $value;
|
2010-07-07 04:41:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $options;
|
|
|
|
}
|
|
|
|
|
2010-01-10 01:20:51 +00:00
|
|
|
/**
|
|
|
|
* Main entry point to this shell
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function main() {
|
2011-03-19 17:32:35 +00:00
|
|
|
$this->out(__d('cake_console', 'CakePHP Test Shell'));
|
2010-01-10 01:20:51 +00:00
|
|
|
$this->hr();
|
|
|
|
|
2011-08-20 05:39:30 +00:00
|
|
|
$args = $this->_parseArgs();
|
2010-07-14 00:53:45 +00:00
|
|
|
|
|
|
|
if (empty($args['case'])) {
|
2010-11-03 23:26:06 +00:00
|
|
|
return $this->available();
|
2010-07-14 00:53:45 +00:00
|
|
|
}
|
|
|
|
|
2011-08-20 05:39:30 +00:00
|
|
|
$this->_run($args, $this->_runnerOptions());
|
2010-07-14 01:58:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Runs the test case from $runnerArgs
|
|
|
|
*
|
2011-08-20 05:39:30 +00:00
|
|
|
* @param array $runnerArgs list of arguments as obtained from _parseArgs()
|
|
|
|
* @param array $options list of options as constructed by _runnerOptions()
|
2010-07-14 01:58:21 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-08-20 05:39:30 +00:00
|
|
|
protected function _run($runnerArgs, $options = array()) {
|
2010-11-29 02:05:12 +00:00
|
|
|
restore_error_handler();
|
|
|
|
restore_error_handler();
|
|
|
|
|
2011-02-12 21:08:48 +00:00
|
|
|
$testCli = new CakeTestSuiteCommand('CakeTestLoader', $runnerArgs);
|
2010-07-14 01:58:21 +00:00
|
|
|
$testCli->run($options);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-07-13 03:54:59 +00:00
|
|
|
/**
|
|
|
|
* Shows a list of available test cases and gives the option to run one of them
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function available() {
|
2011-08-20 05:39:30 +00:00
|
|
|
$params = $this->_parseArgs();
|
2011-02-13 04:07:39 +00:00
|
|
|
$testCases = CakeTestLoader::generateTestList($params);
|
2010-07-13 03:54:59 +00:00
|
|
|
$app = $params['app'];
|
|
|
|
$plugin = $params['plugin'];
|
|
|
|
|
|
|
|
$title = "Core Test Cases:";
|
|
|
|
$category = 'core';
|
|
|
|
if ($app) {
|
|
|
|
$title = "App Test Cases:";
|
|
|
|
$category = 'app';
|
|
|
|
} elseif ($plugin) {
|
|
|
|
$title = Inflector::humanize($plugin) . " Test Cases:";
|
|
|
|
$category = $plugin;
|
|
|
|
}
|
2010-07-14 00:53:45 +00:00
|
|
|
|
2010-07-13 03:54:59 +00:00
|
|
|
if (empty($testCases)) {
|
2011-03-19 17:32:35 +00:00
|
|
|
$this->out(__d('cake_console', "No test cases available \n\n"));
|
2010-11-17 04:32:23 +00:00
|
|
|
return $this->out($this->OptionParser->help());
|
2010-07-13 03:54:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->out($title);
|
|
|
|
$i = 1;
|
|
|
|
$cases = array();
|
|
|
|
foreach ($testCases as $testCaseFile => $testCase) {
|
2011-04-21 18:01:34 +00:00
|
|
|
$case = str_replace('Test.php', '', $testCase);
|
2010-07-13 03:54:59 +00:00
|
|
|
$this->out("[$i] $case");
|
|
|
|
$cases[$i] = $case;
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
|
2011-03-19 17:32:35 +00:00
|
|
|
while ($choice = $this->in(__d('cake_console', 'What test case would you like to run?'), null, 'q')) {
|
2012-03-03 23:55:07 +00:00
|
|
|
if (is_numeric($choice) && isset($cases[$choice])) {
|
2010-07-13 03:54:59 +00:00
|
|
|
$this->args[0] = $category;
|
|
|
|
$this->args[1] = $cases[$choice];
|
2011-08-20 05:39:30 +00:00
|
|
|
$this->_run($this->_parseArgs(), $this->_runnerOptions());
|
2010-07-13 03:54:59 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_string($choice) && in_array($choice, $cases)) {
|
|
|
|
$this->args[0] = $category;
|
|
|
|
$this->args[1] = $choice;
|
2011-08-20 05:39:30 +00:00
|
|
|
$this->_run($this->_parseArgs(), $this->_runnerOptions());
|
2010-07-13 03:54:59 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($choice == 'q') {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-05-28 23:19:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Find the test case for the passed file. The file could itself be a test.
|
|
|
|
*
|
|
|
|
* @param mixed $file
|
2011-10-18 09:02:08 +00:00
|
|
|
* @param mixed $category
|
|
|
|
* @param mixed $throwOnMissingFile
|
2011-05-28 23:19:14 +00:00
|
|
|
* @access protected
|
|
|
|
* @return array(type, case)
|
2011-10-18 09:02:08 +00:00
|
|
|
* @throws Exception
|
2011-05-28 23:19:14 +00:00
|
|
|
*/
|
2011-10-18 09:02:08 +00:00
|
|
|
protected function _mapFileToCase($file, $category, $throwOnMissingFile = true) {
|
2011-05-28 23:19:14 +00:00
|
|
|
if (!$category || (substr($file, -4) !== '.php')) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-05-28 23:49:21 +00:00
|
|
|
$_file = realpath($file);
|
|
|
|
if ($_file) {
|
|
|
|
$file = $_file;
|
|
|
|
}
|
|
|
|
|
2011-05-28 23:19:14 +00:00
|
|
|
$testFile = $testCase = null;
|
|
|
|
|
|
|
|
if (preg_match('@Test[\\\/]@', $file)) {
|
|
|
|
|
|
|
|
if (substr($file, -8) === 'Test.php') {
|
|
|
|
|
|
|
|
$testCase = substr($file, 0, -8);
|
|
|
|
$testCase = str_replace(DS, '/', $testCase);
|
|
|
|
|
2011-05-28 23:57:18 +00:00
|
|
|
if ($testCase = preg_replace('@.*Test\/Case\/@', '', $testCase)) {
|
2011-05-28 23:19:14 +00:00
|
|
|
|
|
|
|
if ($category === 'core') {
|
2011-05-28 23:57:18 +00:00
|
|
|
$testCase = str_replace('lib/Cake', '', $testCase);
|
2011-05-28 23:19:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $testCase;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new Exception(__d('cake_dev', 'Test case %s cannot be run via this shell', $testFile));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$file = substr($file, 0, -4);
|
|
|
|
if ($category === 'core') {
|
|
|
|
|
|
|
|
$testCase = str_replace(DS, '/', $file);
|
|
|
|
$testCase = preg_replace('@.*lib/Cake/@', '', $file);
|
|
|
|
$testCase[0] = strtoupper($testCase[0]);
|
|
|
|
$testFile = CAKE . 'Test/Case/' . $testCase . 'Test.php';
|
|
|
|
|
2011-10-18 09:02:08 +00:00
|
|
|
if (!file_exists($testFile) && $throwOnMissingFile) {
|
|
|
|
throw new Exception(__d('cake_dev', 'Test case %s not found', $testFile));
|
2011-05-28 23:19:14 +00:00
|
|
|
}
|
2012-03-03 23:55:07 +00:00
|
|
|
|
2011-10-18 09:02:08 +00:00
|
|
|
return $testCase;
|
2011-05-28 23:19:14 +00:00
|
|
|
}
|
|
|
|
|
2011-05-28 23:49:21 +00:00
|
|
|
if ($category === 'app') {
|
|
|
|
$testFile = str_replace(APP, APP . 'Test/Case/', $file) . 'Test.php';
|
|
|
|
} else {
|
|
|
|
$testFile = preg_replace(
|
|
|
|
"@((?:plugins|Plugin)[\\/]{$category}[\\/])(.*)$@",
|
|
|
|
'\1Test/Case/\2Test.php',
|
|
|
|
$file
|
|
|
|
);
|
|
|
|
}
|
2011-05-28 23:19:14 +00:00
|
|
|
|
2011-10-18 09:02:08 +00:00
|
|
|
if (!file_exists($testFile) && $throwOnMissingFile) {
|
2011-05-28 23:19:14 +00:00
|
|
|
throw new Exception(__d('cake_dev', 'Test case %s not found', $testFile));
|
|
|
|
}
|
|
|
|
|
2011-10-18 09:36:30 +00:00
|
|
|
$testCase = substr($testFile, 0, -8);
|
2011-05-28 23:19:14 +00:00
|
|
|
$testCase = str_replace(DS, '/', $testCase);
|
|
|
|
$testCase = preg_replace('@.*Test/Case/@', '', $testCase);
|
|
|
|
|
|
|
|
return $testCase;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* For the given file, what category of test is it? returns app, core or the name of the plugin
|
|
|
|
*
|
|
|
|
* @param mixed $file
|
|
|
|
* @access protected
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function _mapFileToCategory($file) {
|
|
|
|
$_file = realpath($file);
|
|
|
|
if ($_file) {
|
|
|
|
$file = $_file;
|
|
|
|
}
|
|
|
|
|
|
|
|
$file = str_replace(DS, '/', $file);
|
|
|
|
if (strpos($file, 'lib/Cake/') !== false) {
|
|
|
|
return 'core';
|
|
|
|
} elseif (preg_match('@(?:plugins|Plugin)/([^/]*)@', $file, $match)) {
|
|
|
|
return $match[1];
|
|
|
|
}
|
|
|
|
return 'app';
|
|
|
|
}
|
2012-03-03 23:55:07 +00:00
|
|
|
|
2011-07-26 01:46:52 +00:00
|
|
|
}
|