Skip to content
Permalink
Browse files

Removing commented code and code never used anymore.

  • Loading branch information...
markstory committed Jun 26, 2010
1 parent b4c061b commit bd43866f5bb534036495b7f46c80d88e6f8b674b
Showing with 4 additions and 234 deletions.
  1. +4 −234 cake/console/libs/testsuite.php
@@ -21,54 +21,6 @@
*/
class TestSuiteShell extends Shell {
/**
* The test category, "app", "core" or the name of a plugin
*
* @var string
* @access public
*/
public $category = '';
/**
* "group", "case" or "all"
*
* @var string
* @access public
*/
public $type = '';
/**
* Path to the test case/group file
*
* @var string
* @access public
*/
public $file = '';
/**
* Storage for plugins that have tests
*
* @var string
* @access public
*/
public $plugins = array();
/**
* Convenience variable to avoid duplicated code
*
* @var string
* @access public
*/
public $isPluginTest = false;
/**
* Stores if the user wishes to get a code coverage analysis report
*
* @var string
* @access public
*/
public $doCoverage = false;
/**
* Dispatcher object for the run.
*
@@ -94,18 +46,6 @@ public function initialize() {
$this->_dispatcher = new CakeTestSuiteDispatcher();
$this->_dispatcher->setParams($params);
/*
$this->__installSimpleTest();
require_once CAKE . 'tests' . DS . 'lib' . DS . 'test_manager.php';
require_once CAKE . 'tests' . DS . 'lib' . DS . 'reporter' . DS . 'cake_cli_reporter.php';
$plugins = App::objects('plugin');
foreach ($plugins as $p) {
$this->plugins[] = Inflector::underscore($p);
}
$this->getManager();
*/
}
/**
@@ -165,21 +105,11 @@ public function main() {
}
$result = $this->_dispatcher->dispatch();
/*
if ($this->__canRun()) {
$message = sprintf(__('Running %s %s %s'), $this->category, $this->type, $this->file);
$this->out($message);
$exitCode = 0;
if (!$this->__run()) {
$exitCode = 1;
}
$this->_stop($exitCode);
} else {
$this->error(__('Sorry, the tests could not be found.'));
$exit = 0;
if ($result instanceof PHPUnit_Framework_TestResult) {
$exit = ($result->errorCount() + $result->failureCount()) > 0;
}
*/
$this->_stop($exitCode);
}
/**
@@ -212,164 +142,4 @@ public function help() {
$this->out('Code Coverage Analysis: ');
$this->out("\n\nAppend 'cov' to any of the above in order to enable code coverage analysis");
}
/**
* Checks if the arguments supplied point to a valid test file and thus the shell can be run.
*
* @return bool true if it's a valid test file, false otherwise
* @access private
*/
function __canRun() {
$isNeitherAppNorCore = !in_array($this->category, array('app', 'core'));
$isPlugin = in_array(Inflector::underscore($this->category), $this->plugins);
if ($isNeitherAppNorCore && !$isPlugin) {
$message = sprintf(
__('%s is an invalid test category (either "app", "core" or name of a plugin)'),
$this->category
);
$this->error($message);
return false;
}
$folder = $this->__findFolderByCategory($this->category);
if (!file_exists($folder)) {
$this->err(sprintf(__('%s not found'), $folder));
return false;
}
if (!in_array($this->type, array('all', 'group', 'case'))) {
$this->err(sprintf(__('%s is invalid. Should be case, group or all'), $this->type));
return false;
}
$fileName = $this->__getFileName($folder, $this->isPluginTest);
if ($fileName === true || file_exists($folder . $fileName)) {
return true;
}
$message = sprintf(
__('%s %s %s is an invalid test identifier'),
$this->category, $this->type, $this->file
);
$this->err($message);
return false;
}
/**
* Executes the tests depending on our settings
*
* @return void
* @access private
*/
function __run() {
$Reporter = new CakeCliReporter('utf-8', array(
'app' => $this->Manager->appTest,
'plugin' => $this->Manager->pluginTest,
'group' => ($this->type === 'group'),
'codeCoverage' => $this->doCoverage
));
if ($this->type == 'all') {
return $this->Manager->runAllTests($Reporter);
}
if ($this->doCoverage) {
if (!extension_loaded('xdebug')) {
$this->out(__('You must install Xdebug to use the CakePHP(tm) Code Coverage Analyzation. Download it from http://www.xdebug.org/docs/install'));
$this->_stop(0);
}
}
if ($this->type == 'group') {
$ucFirstGroup = ucfirst($this->file);
if ($this->doCoverage) {
require_once CAKE . 'tests' . DS . 'lib' . DS . 'code_coverage_manager.php';
CodeCoverageManager::init($ucFirstGroup, $Reporter);
CodeCoverageManager::start();
}
$result = $this->Manager->runGroupTest($ucFirstGroup, $Reporter);
return $result;
}
$folder = $folder = $this->__findFolderByCategory($this->category);
$case = $this->__getFileName($folder, $this->isPluginTest);
if ($this->doCoverage) {
require_once CAKE . 'tests' . DS . 'lib' . DS . 'code_coverage_manager.php';
CodeCoverageManager::init($case, $Reporter);
CodeCoverageManager::start();
}
$result = $this->Manager->runTestCase($case, $Reporter);
return $result;
}
/**
* Gets the concrete filename for the inputted test name and category/type
*
* @param string $folder Folder name to look for files in.
* @param boolean $isPlugin If the test case is a plugin.
* @return mixed Either string filename or boolean false on failure. Or true if the type is 'all'
* @access private
*/
function __getFileName($folder, $isPlugin) {
$ext = $this->Manager->getExtension($this->type);
switch ($this->type) {
case 'all':
return true;
case 'group':
return $this->file . $ext;
case 'case':
if ($this->category == 'app' || $isPlugin) {
return $this->file . $ext;
}
$coreCase = $this->file . $ext;
$coreLibCase = 'libs' . DS . $this->file . $ext;
if ($this->category == 'core' && file_exists($folder . DS . $coreCase)) {
return $coreCase;
} elseif ($this->category == 'core' && file_exists($folder . DS . $coreLibCase)) {
return $coreLibCase;
}
}
return false;
}
/**
* Finds the correct folder to look for tests for based on the input category and type.
*
* @param string $category The category of the test. Either 'app', 'core' or a plugin name.
* @return string the folder path
* @access private
*/
function __findFolderByCategory($category) {
$folder = '';
$paths = array(
'core' => CAKE,
'app' => APP
);
$typeDir = $this->type === 'group' ? 'groups' : 'cases';
if (array_key_exists($category, $paths)) {
$folder = $paths[$category] . 'tests' . DS . $typeDir . DS;
} else {
$pluginPath = App::pluginPath($category);
if (is_dir($pluginPath . 'tests')) {
$folder = $pluginPath . 'tests' . DS . $typeDir . DS;
}
}
return $folder;
}
/**
* tries to install simpletest and exits gracefully if it is not there
*
* @return void
* @access private
*/
function __installSimpleTest() {
if (!App::import('Vendor', 'simpletest' . DS . 'reporter')) {
$this->err(__('Sorry, Simpletest could not be found. Download it from http://simpletest.org and install it to your vendors directory.'));
exit;
}
}
}

0 comments on commit bd43866

Please sign in to comment.
You can’t perform that action at this time.