Skip to content
Permalink
Browse files

Removing 'group tests' PHPUnit implements them as testsuites, which d…

…o not need to be handled differently than test cases.
  • Loading branch information...
markstory committed Jun 26, 2010
1 parent a166ea7 commit 206d4d4722db76deb8aefbd9cf084af5fe522fae
@@ -31,7 +31,6 @@ class CakeTestSuiteDispatcher {
*/
public $params = array(
'codeCoverage' => false,
'group' => null,
'case' => null,
'app' => false,
'plugin' => null,
@@ -96,14 +95,10 @@ function dispatch() {
$this->_checkPHPUnit();
$this->_parseParams();
if ($this->params['group']) {
$this->_runGroupTest();
} elseif ($this->params['case']) {
if ($this->params['case']) {
$this->_runTestCase();
} elseif (isset($_GET['show']) && $_GET['show'] == 'cases') {
$this->_testCaseList();
} else {
$this->_groupTestList();
$this->_testCaseList();
}
$output = ob_get_clean();
@@ -170,19 +165,6 @@ function _testCaseList() {
$Reporter->paintDocumentEnd();
}
/**
* Generates a page containing a list of group tests that could be run.
*
* @return void
*/
function _groupTestList() {
$Reporter =& $this->getReporter();
$Reporter->paintDocumentStart();
$Reporter->paintTestMenu();
$Reporter->groupTestList();
$Reporter->paintDocumentEnd();
}
/**
* Sets the Manager to use for the request.
*
@@ -243,20 +225,6 @@ function _parseParams() {
$this->getManager();
}
/**
* Runs the group test case.
*
* @return void
*/
function _runGroupTest() {
$Reporter = CakeTestSuiteDispatcher::getReporter();
if ('all' == $this->params['group']) {
$this->Manager->runAllTests($Reporter);
} else {
$this->Manager->runGroupTest(ucfirst($this->params['group']), $Reporter, $this->params['codeCoverage']);
}
}
/**
* Runs a test case file.
*
@@ -44,13 +44,6 @@ abstract class BaseCoverageReport {
*/
public $pluginTest = false;
/**
* is the test a group test?
*
* @var string
*/
public $groupTest = false;
/**
* Array of test case file names. Used to do basename() matching with
* files that have coverage to decide which results to show on page load.
@@ -81,9 +74,6 @@ protected function setParams(CakeBaseReporter $reporter) {
if ($reporter->params['app']) {
$this->appTest = true;
}
if ($reporter->params['group']) {
$this->groupTest = true;
}
if ($reporter->params['plugin']) {
$this->pluginTest = Inflector::underscore($reporter->params['plugin']);
}
@@ -94,34 +94,6 @@ function __construct($charset = 'utf-8', $params = array()) {
$this->params = $params;
}
/**
* Signals / Paints the beginning of a TestSuite executing.
* Starts the timer for the TestSuite execution time.
*
* @param string $test_name Name of the test that is being run.
* @param integer $size
* @return void
*/
public function paintGroupStart($test_name, $size) {
if (empty($this->_timeStart)) {
$this->_timeStart = microtime(true);
}
parent::paintGroupStart($test_name, $size);
}
/**
* Signals/Paints the end of a TestSuite. All test cases have run
* and timers are stopped.
*
* @param string $test_name Name of the test that is being run.
* @return void
*/
public function paintGroupEnd($test_name) {
$this->_timeEnd = microtime(true);
$this->_timeDuration = $this->_timeEnd - $this->_timeStart;
parent::paintGroupEnd($test_name);
}
/**
* Retrieves a list of test cases from the active Manager class,
* displaying it in the correct format for the reporter subclass
@@ -133,17 +105,6 @@ public function testCaseList() {
return $testList;
}
/**
* Retrieves a list of group test cases from the active Manager class
* displaying it in the correct format for the reporter subclass.
*
* @return void
*/
public function groupTestList() {
$testList = TestManager::getGroupTestList($this->params);
return $testList;
}
/**
* Paints the start of the response from the test suite.
* Used to paint things like head elements in an html page.
@@ -61,7 +61,6 @@ public function paintDocumentStart() {
* @return void
*/
public function paintTestMenu() {
$groups = $this->baseUrl() . '?show=groups';
$cases = $this->baseUrl() . '?show=cases';
$plugins = App::objects('plugin');
sort($plugins);
@@ -93,7 +92,7 @@ public function testCaseList() {
}
foreach ($testCases as $testCaseFile => $testCase) {
$title = explode(strpos($testCase, '\\') ? '\\' : '/', str_replace('.test.php', '', $testCase));
$title = explode(DS, str_replace('.test.php', '', $testCase));
$title[count($title) - 1] = Inflector::camelize($title[count($title) - 1]);
$title = implode(' / ', $title);
$buffer .= "<li><a href='" . $this->baseUrl() . "?case=" . urlencode($testCase) . $urlExtra ."'>" . $title . "</a></li>\n";
@@ -102,35 +101,6 @@ public function testCaseList() {
echo $buffer;
}
/**
* Retrieves and paints the list of group tests in an HTML format.
*
* @return void
*/
public function groupTestList() {
$groupTests = parent::groupTestList();
$app = $this->params['app'];
$plugin = $this->params['plugin'];
$buffer = "<h3>Core Test Groups:</h3>\n<ul>";
$urlExtra = null;
if ($app) {
$buffer = "<h3>App Test Groups:</h3>\n<ul>";
$urlExtra = '&app=true';
} else if ($plugin) {
$buffer = "<h3>" . Inflector::humanize($plugin) . " Test Groups:</h3>\n<ul>";
$urlExtra = '&plugin=' . $plugin;
}
$buffer .= "<li><a href='" . $this->baseURL() . "?group=all$urlExtra'>All tests</a></li>\n";
foreach ($groupTests as $groupTest) {
$buffer .= "<li><a href='" . $this->baseURL() . "?group={$groupTest}" . "{$urlExtra}'>" . $groupTest . "</a></li>\n";
}
$buffer .= "</ul>\n";
echo $buffer;
}
/**
* Send the headers necessary to ensure the page is
* reloaded on every request. Otherwise you could be
@@ -201,9 +171,7 @@ public function paintCoverage($coverage) {
*/
protected function _paintLinks() {
$show = $query = array();
if (!empty($this->params['group'])) {
$show['show'] = 'groups';
} elseif (!empty($this->params['case'])) {
if (!empty($this->params['case'])) {
$show['show'] = 'cases';
}
@@ -215,9 +183,7 @@ protected function _paintLinks() {
}
if (!empty($this->params['case'])) {
$query['case'] = $this->params['case'];
} elseif (!empty($this->params['group'])) {
$query['group'] = $this->params['group'];
}
}
$show = $this->_queryString($show);
$query = $this->_queryString($query);
@@ -23,8 +23,7 @@
<li>
<span style="font-size: 18px">App</span>
<ul>
<li><a href='<?php echo $groups;?>&amp;app=true'>Test Groups</a></li>
<li><a href='<?php echo $cases;?>&amp;app=true'>Test Cases</a></li>
<li><a href='<?php echo $cases;?>&amp;app=true'>Tests</a></li>
</ul>
</li>
<?php
@@ -39,8 +38,7 @@
<li style="padding-top: 10px">
<span style="font-size: 18px"><?php echo $plugin;?></span>
<ul>
<li><a href='<?php echo $groups;?>&amp;plugin=<?php echo $pluginPath; ?>'>Test Groups</a></li>
<li><a href='<?php echo $cases;?>&amp;plugin=<?php echo $pluginPath; ?>'>Test Cases</a></li>
<li><a href='<?php echo $cases;?>&amp;plugin=<?php echo $pluginPath; ?>'>Tests</a></li>
</ul>
</li>
</ul>
@@ -49,8 +47,7 @@
<li style="padding-top: 10px">
<span style="font-size: 18px">Core</span>
<ul>
<li><a href='<?php echo $groups;?>'>Test Groups</a></li>
<li><a href='<?php echo $cases;?>'>Test Cases</a></li>
<li><a href='<?php echo $cases;?>'>Tests</a></li>
</ul>
</li>
</ul>
@@ -40,13 +40,6 @@ class TestManager {
*/
protected static $_testExtension = '.test.php';
/**
* Extension suffix for group test case files.
*
* @var string
*/
protected static $_groupExtension = '.group.php';
/**
* Is this test an AppTest?
*
@@ -148,35 +141,6 @@ public function runTestCase($testCaseFile, PHPUnit_Framework_TestListener $repor
return $this->run($reporter, $codeCoverage);
}
/**
* Runs a specific group test file
*
* @param string $groupTestName GroupTest that you want to run.
* @param PHPUnit_Framework_TestListener $reporter Reporter instance to use with the group test being run.
* @throws InvalidArgumentException if it was not possible to locate the filename for $groupTestName
* @return mixed Results of group test being run.
*/
public function runGroupTest($groupTestName, $reporter, $codeCoverage = false) {
$filePath = $this->_getTestsPath($reporter->params) . DS . strtolower($groupTestName) . $this->getExtension('group');
if (!file_exists($filePath) || strpos($filePath, '..')) {
throw new InvalidArgumentException(sprintf(
__('Group test %s cannot be found at %s', true),
htmlentities($groupTestName),
htmlentities($filePath)
)
);
}
require_once $filePath;
$class = basename($groupTestName);
$suite = $this->getTestSuite(sprintf(__('%s group test', true), $class));
$groupClassName = Inflector::classify($class) . 'GroupTest';
$suite->addTestSuite($groupClassName);
return $this->run($reporter, $codeCoverage);
}
/**
* Runs the main testSuite and attaches to it a reporter
*
@@ -260,35 +224,6 @@ protected static function &_getTestFileList($directory = '.') {
return $return;
}
/**
* Returns a list of group tests found in the current valid test case path
*
* @access public
* @static
*/
public static function getGroupTestList($params) {
$directory = self::_getTestsPath($params);
$fileList = self::_getTestGroupFileList($directory);
$groupTests = array();
foreach ($fileList as $groupTestFile) {
$groupTests[$groupTestFile] = str_replace(self::$_groupExtension, '', basename($groupTestFile));
}
sort($groupTests);
return $groupTests;
}
/**
* Returns a list of group test files from a given directory
*
* @param string $directory The directory to get group test files from.
* @static
*/
protected static function &_getTestGroupFileList($directory = '.') {
$return = self::_getRecursiveFileList($directory, array('self', '_isTestGroupFile'));
return $return;
}
/**
* Gets a recursive list of files from a given directory and matches then against
* a given fileTestFunction, like isTestCaseFile()
@@ -329,17 +264,6 @@ protected static function _isTestCaseFile($file) {
return self::_hasExpectedExtension($file, self::$_testExtension);
}
/**
* Tests if a file has the correct group test extension
*
* @param string $file
* @return boolean Whether $file is a group
* @static
*/
protected static function _isTestGroupFile($file) {
return self::_hasExpectedExtension($file, self::$_groupExtension);
}
/**
* Check if a file has a specific extension
*
@@ -353,7 +277,7 @@ protected static function _hasExpectedExtension($file, $extension) {
}
/**
* Returns the given path to the test files depending on a given type of tests (cases, group, ..)
* Returns the given path to the test files depending on a given type of tests (core, app, plugin)
*
* @param array $params Array of parameters for getting test paths.
* Can contain app, type, and plugin params.
@@ -363,24 +287,12 @@ protected static function _hasExpectedExtension($file, $extension) {
protected static function _getTestsPath($params) {
$result = null;
if (!empty($params['app'])) {
if ($params['show'] == 'cases' || !empty($params['case'])) {
$result = APP_TEST_CASES;
} else if ($params['show'] == 'groups') {
$result = APP_TEST_GROUPS;
}
$result = APP_TEST_CASES;
} else if (!empty($params['plugin'])) {
$_pluginBasePath = APP . 'plugins/' . $params['plugin'] . '/tests';
$pluginPath = App::pluginPath($params['plugin']);
if (file_exists($pluginPath . DS . 'tests')) {
$_pluginBasePath = $pluginPath . DS . 'tests';
}
$result = $_pluginBasePath . DS . $type;
} elseif (!empty($params['show'])) {
if ($params['show'] == 'cases' || !empty($params['case'])) {
$result = CORE_TEST_CASES;
} else if ($params['show'] == 'groups') {
$result = CORE_TEST_GROUPS;
}
$result = $pluginPath . 'tests' . DS . 'cases';
} else {
$result = CORE_TEST_CASES;
}
return $result;
}

0 comments on commit 206d4d4

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