2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Test Suite Shell
|
|
|
|
*
|
|
|
|
* 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>
|
2010-01-26 19:18:20 +00:00
|
|
|
* Copyright 2005-2010, 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
|
|
|
*
|
2010-01-26 19:18:20 +00:00
|
|
|
* @copyright Copyright 2005-2010, 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
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.console.libs
|
|
|
|
* @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
|
|
|
*/
|
|
|
|
class TestSuiteShell 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() {
|
|
|
|
$parser = new ConsoleOptionParser($this->name, false);
|
|
|
|
$parser->description(array(
|
|
|
|
'The CakPHP Testsuite allows you to run test cases from the command line',
|
|
|
|
'If run with no command line arguments, a list of available core test cases will be shown'
|
|
|
|
))->addArgument('category', array(
|
|
|
|
'help' => __('app, core or name of a plugin.'),
|
|
|
|
'required' => true
|
|
|
|
))->addArgument('file', array(
|
|
|
|
'help' => __('file name with folder prefix and without the test.php suffix.'),
|
|
|
|
'required' => true,
|
|
|
|
));
|
|
|
|
return $parser;
|
|
|
|
}
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Initialization method installs Simpletest and loads all plugins
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function initialize() {
|
2010-06-26 17:49:21 +00:00
|
|
|
require_once CAKE . 'tests' . DS . 'lib' . DS . 'cake_test_suite_dispatcher.php';
|
|
|
|
|
2009-07-22 16:11:38 +00:00
|
|
|
$corePath = App::core('cake');
|
2008-05-30 11:40:08 +00:00
|
|
|
if (isset($corePath[0])) {
|
|
|
|
define('TEST_CAKE_CORE_INCLUDE_PATH', rtrim($corePath[0], DS) . DS);
|
|
|
|
} else {
|
2009-08-02 20:19:16 +00:00
|
|
|
define('TEST_CAKE_CORE_INCLUDE_PATH', CAKE_CORE_INCLUDE_PATH);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2010-07-13 03:54:59 +00:00
|
|
|
|
2010-06-26 17:49:21 +00:00
|
|
|
$this->_dispatcher = new CakeTestSuiteDispatcher();
|
2010-07-07 04:37:22 +00:00
|
|
|
$this->_dispatcher->loadTestFramework();
|
2010-07-13 03:54:59 +00:00
|
|
|
require_once CAKE . 'tests' . DS . 'lib' . DS . 'test_manager.php';
|
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
|
|
|
*/
|
2010-07-07 04:37:22 +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(
|
|
|
|
'app' => false,
|
|
|
|
'plugin' => null,
|
|
|
|
'output' => 'text',
|
|
|
|
);
|
|
|
|
|
|
|
|
$category = $this->args[0];
|
|
|
|
|
|
|
|
if ($category == 'app') {
|
|
|
|
$params['app'] = true;
|
|
|
|
} elseif ($category != 'core') {
|
|
|
|
$params['plugin'] = $category;
|
2010-01-10 01:20:51 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-01-10 01:20:51 +00:00
|
|
|
if (isset($this->args[1])) {
|
2010-07-07 04:41:06 +00:00
|
|
|
$params['case'] = Inflector::underscore($this->args[1]);
|
2010-01-10 01:20:51 +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
|
|
|
|
*/
|
|
|
|
protected function runnerOptions() {
|
|
|
|
$options = array();
|
|
|
|
foreach ($this->params as $param => $value) {
|
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() {
|
2010-04-15 15:43:39 +00:00
|
|
|
$this->out(__('CakePHP Test Shell'));
|
2010-01-10 01:20:51 +00:00
|
|
|
$this->hr();
|
|
|
|
|
2010-07-14 00:53:45 +00:00
|
|
|
$args = $this->parseArgs();
|
|
|
|
|
|
|
|
if (empty($args['case'])) {
|
|
|
|
$this->available();
|
|
|
|
}
|
|
|
|
|
2010-07-14 01:58:21 +00:00
|
|
|
$this->run($args, $this->runnerOptions());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Runs the test case from $runnerArgs
|
|
|
|
*
|
|
|
|
* @param array $runnerArgs list of arguments as obtained from parseArgs()
|
|
|
|
* @param array $options list of options as constructed by runnerOptions()
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function run($runnerArgs, $options = array()) {
|
2010-07-07 04:41:06 +00:00
|
|
|
require_once CAKE . 'tests' . DS . 'lib' . DS . 'test_runner.php';
|
2010-07-14 01:58:21 +00:00
|
|
|
$testCli = new TestRunner($runnerArgs);
|
|
|
|
$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() {
|
|
|
|
$params = $this->parseArgs();
|
|
|
|
$testCases = TestManager::getTestCaseList($params);
|
|
|
|
$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)) {
|
2010-07-14 01:58:21 +00:00
|
|
|
$this->out(__("No test cases available \n\n"));
|
|
|
|
$this->help();
|
|
|
|
$this->_stop();
|
2010-07-13 03:54:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->out($title);
|
|
|
|
$i = 1;
|
|
|
|
$cases = array();
|
|
|
|
foreach ($testCases as $testCaseFile => $testCase) {
|
|
|
|
$case = explode(DS, str_replace('.test.php', '', $testCase));
|
|
|
|
$case[count($case) - 1] = Inflector::camelize($case[count($case) - 1]);
|
|
|
|
$case = implode('/', $case);
|
|
|
|
$this->out("[$i] $case");
|
|
|
|
$cases[$i] = $case;
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
while ($choice = $this->in(__('What test case would you like to run?'), null, 'q')) {
|
|
|
|
if (is_numeric($choice) && isset($cases[$choice])) {
|
|
|
|
$this->args[0] = $category;
|
|
|
|
$this->args[1] = $cases[$choice];
|
2010-07-14 01:58:21 +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;
|
2010-07-14 01:58:21 +00:00
|
|
|
$this->run($this->parseArgs(), $this->runnerOptions());
|
2010-07-13 03:54:59 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($choice == 'q') {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Help screen
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function help() {
|
2010-07-14 00:50:19 +00:00
|
|
|
$this->out('CakePHP Testsuite:');
|
|
|
|
$this->hr();
|
|
|
|
|
2010-07-14 00:52:40 +00:00
|
|
|
$this->out('The CakPHP Testsuite allows you to run test cases from the command line');
|
2010-07-14 00:50:19 +00:00
|
|
|
$this->out('If run with no command line arguments, a list of available core test cases will be shown');
|
|
|
|
$this->hr();
|
|
|
|
|
|
|
|
$this->out("Usage: cake testuite <category> <file> [params]");
|
|
|
|
$this->out("\t- category: app, core or name of a plugin");
|
|
|
|
$this->out("\t- file: file name with folder prefix and without the test.php suffix");
|
|
|
|
$this->hr();
|
|
|
|
|
|
|
|
$this->out("Usage: cake testuite available <category> [params]");
|
|
|
|
$this->out("\t Shows a list of available testcases for the specified category");
|
|
|
|
$this->out("\t Params list will be used for running the selected test case");
|
|
|
|
$this->hr();
|
|
|
|
|
|
|
|
$this->out('Examples:');
|
|
|
|
$this->out('cake testsuite app models/my_model');
|
|
|
|
$this->out("cake testsuite app controllers/my_controller \n");
|
|
|
|
$this->out('cake testsuite core libs/file');
|
|
|
|
$this->out("cake testsuite core libs/set \n");
|
|
|
|
$this->out('cake testsuite bugs models/bug -- for the plugin bugs and its test case models/bug');
|
|
|
|
$this->hr();
|
|
|
|
|
|
|
|
$this->out('Params:');
|
|
|
|
$this->out("--log-junit <file> Log test execution in JUnit XML format to file.");
|
|
|
|
$this->out("--log-json <file> Log test execution in JSON format.");
|
2010-09-29 01:41:43 +00:00
|
|
|
$this->out("--log-tap <file> Log test execution in TAP format to file.");
|
|
|
|
$this->out("--log-dbus Log test execution to DBUS.");
|
2010-07-14 00:50:19 +00:00
|
|
|
|
|
|
|
$this->out("--coverage-html <dir> Generate code coverage report in HTML format.");
|
|
|
|
$this->out("--coverage-clover <file> Write code coverage data in Clover XML format.");
|
|
|
|
|
|
|
|
$this->out("--testdox-html <file> Write agile documentation in HTML format to file.");
|
|
|
|
$this->out("--testdox-text <file> Write agile documentation in Text format to file.");
|
|
|
|
|
|
|
|
$this->out("--filter <pattern> Filter which tests to run.");
|
|
|
|
$this->out("--group ... Only runs tests from the specified group(s).");
|
|
|
|
$this->out("--exclude-group ... Exclude tests from the specified group(s).");
|
|
|
|
$this->out("--filter <pattern> Filter which tests to run.");
|
2010-09-29 01:41:43 +00:00
|
|
|
$this->out("--list-groups List available test groups.");
|
|
|
|
|
2010-07-14 00:50:19 +00:00
|
|
|
$this->out("--loader <loader> TestSuiteLoader implementation to use.");
|
|
|
|
$this->out("--repeat <times> Runs the test(s) repeatedly.");
|
|
|
|
|
|
|
|
$this->out("--tap Report test execution progress in TAP format.");
|
|
|
|
$this->out("--testdox Report test execution progress in TestDox format.");
|
|
|
|
|
|
|
|
$this->out("--colors Use colors in output.");
|
|
|
|
$this->out("--stderr Write to STDERR instead of STDOUT.");
|
|
|
|
$this->out("--stop-on-failure Stop execution upon first error or failure.");
|
2010-09-29 01:41:43 +00:00
|
|
|
$this->out("--stop-on-skipped Stop execution upon first skipped test.");
|
|
|
|
$this->out("--stop-on-incomplete Stop execution upon first incomplete test.");
|
2010-09-29 05:44:14 +00:00
|
|
|
$this->out("--strict Mark a test as incomplete if no assertions are made.");
|
2010-07-14 00:50:19 +00:00
|
|
|
$this->out("--verbose Output more verbose information.");
|
|
|
|
$this->out("--wait Waits for a keystroke after each test.");
|
|
|
|
|
|
|
|
$this->out("--skeleton-class Generate Unit class for UnitTest in UnitTest.php.");
|
|
|
|
$this->out("--skeleton-test Generate UnitTest class for Unit in Unit.php.");
|
|
|
|
|
|
|
|
$this->out("--process-isolation Run each test in a separate PHP process.");
|
|
|
|
$this->out("--no-globals-backup Do not backup and restore \$GLOBALS for each test.");
|
|
|
|
$this->out("--static-backup Backup and restore static attributes for each test.");
|
|
|
|
$this->out("--syntax-check Try to check source files for syntax errors.");
|
|
|
|
|
|
|
|
$this->out("--bootstrap <file> A \"bootstrap\" PHP file that is run before the tests.");
|
|
|
|
$this->out("--configuration <file> Read configuration from XML file.");
|
|
|
|
$this->out("--no-configuration Ignore default configuration file (phpunit.xml).");
|
|
|
|
$this->out("--include-path <path(s)> Prepend PHP's include_path with given path(s).");
|
|
|
|
|
|
|
|
$this->out("-d key[=value] Sets a php.ini value. \n");
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2010-07-14 00:50:19 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|