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
|
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
2010-05-18 22:15:13 -03:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
2010-01-26 14:18:20 -05:00
|
|
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* Licensed under The Open Group Test Suite License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2010-01-26 14:18:20 -05:00
|
|
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-05-18 22:15:13 -03: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
|
|
|
|
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
class TestSuiteShell extends Shell {
|
2009-07-24 21:18:37 +02:00
|
|
|
|
2010-06-26 13:49:21 -04:00
|
|
|
/**
|
|
|
|
* Dispatcher object for the run.
|
|
|
|
*
|
|
|
|
* @var CakeTestDispatcher
|
|
|
|
*/
|
|
|
|
protected $_dispatcher = null;
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Initialization method installs Simpletest and loads all plugins
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 13:19:38 +10:00
|
|
|
public function initialize() {
|
2010-06-26 13:49:21 -04:00
|
|
|
require_once CAKE . 'tests' . DS . 'lib' . DS . 'cake_test_suite_dispatcher.php';
|
|
|
|
|
2009-07-22 09:11:38 -07: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 13:19:16 -07:00
|
|
|
define('TEST_CAKE_CORE_INCLUDE_PATH', CAKE_CORE_INCLUDE_PATH);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2010-06-26 13:49:21 -04:00
|
|
|
$params = $this->parseArgs();
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-06-26 13:49:21 -04:00
|
|
|
$this->_dispatcher = new CakeTestSuiteDispatcher();
|
|
|
|
$this->_dispatcher->setParams($params);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 21:18:37 +02:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2010-06-26 13:49:21 -04:00
|
|
|
* Parse the CLI options into an array CakeTestDispatcher can use.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-06-26 13:49:21 -04:00
|
|
|
* @return array Array of params for CakeTestDispatcher
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 13:19:38 +10:00
|
|
|
public function parseArgs() {
|
2010-01-09 21:25:05 -05:00
|
|
|
if (empty($this->args)) {
|
|
|
|
return;
|
|
|
|
}
|
2010-06-26 13:49:21 -04:00
|
|
|
$params = array(
|
|
|
|
'app' => false,
|
|
|
|
'plugin' => null,
|
|
|
|
'output' => 'text',
|
|
|
|
'codeCoverage' => false,
|
|
|
|
'filter' => false,
|
|
|
|
'case' => null
|
|
|
|
);
|
|
|
|
|
|
|
|
$category = $this->args[0];
|
|
|
|
|
|
|
|
if ($category == 'app') {
|
|
|
|
$params['app'] = true;
|
|
|
|
} elseif ($category != 'core') {
|
|
|
|
$params['plugin'] = $category;
|
2010-01-09 20:20:51 -05:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-01-09 20:20:51 -05:00
|
|
|
if (isset($this->args[1])) {
|
2010-06-26 13:49:21 -04:00
|
|
|
$type = $this->args[1];
|
2010-01-09 20:20:51 -05:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-01-09 20:20:51 -05:00
|
|
|
if (isset($this->args[2])) {
|
|
|
|
if ($this->args[2] == 'cov') {
|
2010-06-26 13:49:21 -04:00
|
|
|
$params['codeCoverage'] = true;
|
2010-01-09 20:20:51 -05:00
|
|
|
} else {
|
2010-06-26 13:49:21 -04:00
|
|
|
$params['case'] = Inflector::underscore($this->args[2]) . '.test.php';
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2010-01-09 20:20:51 -05:00
|
|
|
}
|
|
|
|
if (isset($this->args[3]) && $this->args[3] == 'cov') {
|
2010-06-26 13:49:21 -04:00
|
|
|
$params['codeCoverage'] = true;
|
2010-01-09 20:20:51 -05:00
|
|
|
}
|
2010-06-26 14:07:38 -04:00
|
|
|
if (isset($this->params['filter'])) {
|
|
|
|
$params['filter'] = $this->params['filter'];
|
|
|
|
}
|
2010-06-26 13:49:21 -04:00
|
|
|
return $params;
|
2010-01-09 20:20:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Main entry point to this shell
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 13:19:38 +10:00
|
|
|
public function main() {
|
2010-04-16 01:43:39 +10:00
|
|
|
$this->out(__('CakePHP Test Shell'));
|
2010-01-09 20:20:51 -05:00
|
|
|
$this->hr();
|
|
|
|
|
|
|
|
if (count($this->args) == 0) {
|
2010-04-16 01:43:39 +10:00
|
|
|
$this->error(__('Sorry, you did not pass any arguments!'));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
|
2010-06-26 13:49:21 -04:00
|
|
|
$result = $this->_dispatcher->dispatch();
|
2010-06-26 13:58:49 -04:00
|
|
|
$exit = 0;
|
|
|
|
if ($result instanceof PHPUnit_Framework_TestResult) {
|
|
|
|
$exit = ($result->errorCount() + $result->failureCount()) > 0;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2010-06-26 14:07:38 -04:00
|
|
|
$this->_stop($exit);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 21:18:37 +02:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Help screen
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 13:19:38 +10:00
|
|
|
public function help() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->out('Usage: ');
|
|
|
|
$this->out("\tcake testsuite category test_type file");
|
2009-04-30 23:38:14 +00:00
|
|
|
$this->out("\t\t- category - \"app\", \"core\" or name of a plugin");
|
|
|
|
$this->out("\t\t- test_type - \"case\", \"group\" or \"all\"");
|
|
|
|
$this->out("\t\t- test_file - file name with folder prefix and without the (test|group).php suffix");
|
2009-09-26 23:08:37 +02:00
|
|
|
$this->out();
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->out('Examples: ');
|
2009-04-30 23:38:14 +00:00
|
|
|
$this->out("\t\tcake testsuite app all");
|
|
|
|
$this->out("\t\tcake testsuite core all");
|
2009-09-26 23:08:37 +02:00
|
|
|
$this->out();
|
2009-04-30 23:38:14 +00:00
|
|
|
$this->out("\t\tcake testsuite app case behaviors/debuggable");
|
|
|
|
$this->out("\t\tcake testsuite app case models/my_model");
|
|
|
|
$this->out("\t\tcake testsuite app case controllers/my_controller");
|
2009-09-26 23:08:37 +02:00
|
|
|
$this->out();
|
2010-06-26 13:49:21 -04:00
|
|
|
$this->out("\t\tcake testsuite core case libs/file");
|
|
|
|
$this->out("\t\tcake testsuite core case libs/router");
|
|
|
|
$this->out("\t\tcake testsuite core case libs/set");
|
2009-09-26 23:08:37 +02:00
|
|
|
$this->out();
|
2009-04-30 23:38:14 +00:00
|
|
|
$this->out("\t\tcake testsuite bugs case models/bug");
|
|
|
|
$this->out("\t\t // for the plugin 'bugs' and its test case 'models/bug'");
|
2009-09-26 23:08:37 +02:00
|
|
|
$this->out();
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->out('Code Coverage Analysis: ');
|
|
|
|
$this->out("\n\nAppend 'cov' to any of the above in order to enable code coverage analysis");
|
|
|
|
}
|
|
|
|
}
|