From 8d0cf770dbf8995995145e99cb8a7f13b8bc528b Mon Sep 17 00:00:00 2001 From: Mark Story Date: Sun, 9 Mar 2014 21:39:31 -0400 Subject: [PATCH] Remove the remaining test suite infrastructure. With the removal of the webrunner there isn't much point in keeping all the test harness infrastructure in place. TestShell also serves little purpose now, as a tiny wrapper around phpunit is not super useful. If there is strife around this change we can always reconsider and come to a better compromise. --- src/Console/Command/TestShell.php | 404 +----------------- src/TestSuite/Coverage/BaseCoverageReport.php | 182 -------- src/TestSuite/Coverage/HtmlCoverageReport.php | 225 ---------- src/TestSuite/Coverage/TextCoverageReport.php | 61 --- src/TestSuite/Reporter/BaseReporter.php | 216 ---------- src/TestSuite/Reporter/HtmlReporter.php | 385 ----------------- src/TestSuite/Reporter/TextReporter.php | 183 -------- src/TestSuite/TestLoader.php | 127 ------ src/TestSuite/TestRunner.php | 108 ----- src/TestSuite/TestSuiteCommand.php | 141 ------ src/TestSuite/TestSuiteDispatcher.php | 277 ------------ src/TestSuite/templates/footer.php | 35 -- src/TestSuite/templates/header.php | 147 ------- src/TestSuite/templates/menu.php | 50 --- .../templates/missing_connection.php | 25 -- src/TestSuite/templates/phpunit.php | 33 -- src/TestSuite/templates/xdebug.php | 25 -- .../Console/Command/TestShellTest.php | 342 --------------- .../TestSuite/HtmlCoverageReportTest.php | 234 ---------- 19 files changed, 13 insertions(+), 3187 deletions(-) delete mode 100644 src/TestSuite/Coverage/BaseCoverageReport.php delete mode 100644 src/TestSuite/Coverage/HtmlCoverageReport.php delete mode 100644 src/TestSuite/Coverage/TextCoverageReport.php delete mode 100644 src/TestSuite/Reporter/BaseReporter.php delete mode 100644 src/TestSuite/Reporter/HtmlReporter.php delete mode 100644 src/TestSuite/Reporter/TextReporter.php delete mode 100644 src/TestSuite/TestLoader.php delete mode 100644 src/TestSuite/TestRunner.php delete mode 100644 src/TestSuite/TestSuiteCommand.php delete mode 100644 src/TestSuite/TestSuiteDispatcher.php delete mode 100644 src/TestSuite/templates/footer.php delete mode 100644 src/TestSuite/templates/header.php delete mode 100644 src/TestSuite/templates/menu.php delete mode 100644 src/TestSuite/templates/missing_connection.php delete mode 100644 src/TestSuite/templates/phpunit.php delete mode 100644 src/TestSuite/templates/xdebug.php delete mode 100644 tests/TestCase/Console/Command/TestShellTest.php delete mode 100644 tests/TestCase/TestSuite/HtmlCoverageReportTest.php diff --git a/src/Console/Command/TestShell.php b/src/Console/Command/TestShell.php index ac22872a761..b460532223c 100644 --- a/src/Console/Command/TestShell.php +++ b/src/Console/Command/TestShell.php @@ -26,253 +26,20 @@ use Cake\Utility\Inflector; /** - * Provides a CakePHP wrapper around PHPUnit. - * Adds in CakePHP's fixtures and gives access to plugin, app and core test cases + * Stub that tells people how to run tests with PHPUnit. * + * @deprecated */ class TestShell extends Shell { -/** - * Dispatcher object for the run. - * - * @var CakeTestDispatcher - */ - protected $_dispatcher = null; - -/** - * Gets the option parser instance and configures it. - * - * @return ConsoleOptionParser - */ - public function getOptionParser() { - $parser = new ConsoleOptionParser($this->name); - $parser->description([ - __d('cake_console', 'The CakePHP Testsuite allows you to run test cases from the command line'), - ])->addArgument('category', [ - 'help' => __d('cake_console', 'The category for the test, or test file, to test.'), - 'required' => false, - ])->addArgument('file', [ - 'help' => __d('cake_console', 'The path to the file, or test file, to test.'), - 'required' => false, - ])->addOption('log-junit', [ - 'help' => __d('cake_console', ' Log test execution in JUnit XML format to file.'), - 'default' => false - ])->addOption('log-json', [ - 'help' => __d('cake_console', ' Log test execution in JSON format to file.'), - 'default' => false - ])->addOption('log-tap', [ - 'help' => __d('cake_console', ' Log test execution in TAP format to file.'), - 'default' => false - ])->addOption('log-dbus', [ - 'help' => __d('cake_console', 'Log test execution to DBUS.'), - 'default' => false - ])->addOption('coverage-html', [ - 'help' => __d('cake_console', ' Generate code coverage report in HTML format.'), - 'default' => false - ])->addOption('coverage-clover', [ - 'help' => __d('cake_console', ' Write code coverage data in Clover XML format.'), - 'default' => false - ])->addOption('testdox-html', [ - 'help' => __d('cake_console', ' Write agile documentation in HTML format to file.'), - 'default' => false - ])->addOption('testdox-text', [ - 'help' => __d('cake_console', ' Write agile documentation in Text format to file.'), - 'default' => false - ])->addOption('filter', [ - 'help' => __d('cake_console', ' Filter which tests to run.'), - 'default' => false - ])->addOption('group', [ - 'help' => __d('cake_console', ' Only runs tests from the specified group(s).'), - 'default' => false - ])->addOption('exclude-group', [ - 'help' => __d('cake_console', ' Exclude tests from the specified group(s).'), - 'default' => false - ])->addOption('list-groups', [ - 'help' => __d('cake_console', 'List available test groups.'), - 'boolean' => true - ])->addOption('loader', [ - 'help' => __d('cake_console', 'TestSuiteLoader implementation to use.'), - 'default' => false - ])->addOption('repeat', [ - 'help' => __d('cake_console', ' Runs the test(s) repeatedly.'), - 'default' => false - ])->addOption('tap', [ - 'help' => __d('cake_console', 'Report test execution progress in TAP format.'), - 'boolean' => true - ])->addOption('testdox', [ - 'help' => __d('cake_console', 'Report test execution progress in TestDox format.'), - 'default' => false, - 'boolean' => true - ])->addOption('no-colors', [ - 'help' => __d('cake_console', 'Do not use colors in output.'), - 'boolean' => true - ])->addOption('stderr', [ - 'help' => __d('cake_console', 'Write to STDERR instead of STDOUT.'), - 'boolean' => true - ])->addOption('stop-on-error', [ - 'help' => __d('cake_console', 'Stop execution upon first error or failure.'), - 'boolean' => true - ])->addOption('stop-on-failure', [ - 'help' => __d('cake_console', 'Stop execution upon first failure.'), - 'boolean' => true - ])->addOption('stop-on-skipped', [ - 'help' => __d('cake_console', 'Stop execution upon first skipped test.'), - 'boolean' => true - ])->addOption('stop-on-incomplete', [ - 'help' => __d('cake_console', 'Stop execution upon first incomplete test.'), - 'boolean' => true - ])->addOption('strict', [ - 'help' => __d('cake_console', 'Mark a test as incomplete if no assertions are made.'), - 'boolean' => true - ])->addOption('wait', [ - 'help' => __d('cake_console', 'Waits for a keystroke after each test.'), - 'boolean' => true - ])->addOption('process-isolation', [ - 'help' => __d('cake_console', 'Run each test in a separate PHP process.'), - 'boolean' => true - ])->addOption('no-globals-backup', [ - 'help' => __d('cake_console', 'Do not backup and restore $GLOBALS for each test.'), - 'boolean' => true - ])->addOption('static-backup', [ - 'help' => __d('cake_console', 'Backup and restore static attributes for each test.'), - 'boolean' => true - ])->addOption('syntax-check', [ - 'help' => __d('cake_console', 'Try to check source files for syntax errors.'), - 'boolean' => true - ])->addOption('bootstrap', [ - 'help' => __d('cake_console', ' A "bootstrap" PHP file that is run before the tests.'), - 'default' => false - ])->addOption('configuration', [ - 'help' => __d('cake_console', ' Read configuration from XML file.'), - 'default' => false - ])->addOption('no-configuration', [ - 'help' => __d('cake_console', 'Ignore default configuration file (phpunit.xml).'), - 'boolean' => true - ])->addOption('include-path', [ - 'help' => __d('cake_console', ' Prepend PHP include_path with given path(s).'), - 'default' => false - ])->addOption('directive', [ - 'help' => __d('cake_console', 'key[=value] Sets a php.ini value.'), - 'default' => false - ])->addOption('fixture', [ - 'help' => __d('cake_console', 'Choose a custom fixture manager.'), - ])->addOption('debug', [ - 'help' => __d('cake_console', 'More verbose output.'), - ]); - - return $parser; - } - -/** - * Initialization method installs PHPUnit and loads all plugins - * - * @return void - * @throws \Exception - */ - public function initialize() { - $this->_dispatcher = new TestSuiteDispatcher(); - $sucess = $this->_dispatcher->loadTestFramework(); - if (!$sucess) { - throw new \Exception('Please install PHPUnit framework (http://www.phpunit.de)'); - } - } - -/** - * Parse the CLI options into an array Cake\TestSuite\TestDispatcher can use. - * - * @return array Array of params for Cake\TestSuite\TestDispatcher - */ - protected function _parseArgs() { - if (empty($this->args)) { - return; - } - $params = [ - 'core' => false, - 'app' => false, - 'plugin' => null, - 'output' => 'text', - ]; - - 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') { - $params['core'] = true; - } elseif ($category === 'app') { - $params['app'] = true; - } else { - $params['plugin'] = $category; - } - - return $params; - } - -/** - * Converts the options passed to the shell as options for the PHPUnit cli runner - * - * @return array Array of params for Cake\TestSuite\TestDispatcher - */ - protected function _runnerOptions() { - $options = []; - $params = $this->params; - unset($params['help']); - - if (!empty($params['no-colors'])) { - unset($params['no-colors'], $params['colors']); - } else { - $params['colors'] = true; - } - - foreach ($params as $param => $value) { - if ($value === false) { - continue; - } - $options[] = '--' . $param; - if (is_string($value)) { - $options[] = $value; - } - } - return $options; - } - /** * Main entry point to this shell * * @return void */ public function main() { - $this->out(__d('cake_console', 'CakePHP Test Shell')); - $this->hr(); - - $args = $this->_parseArgs(); - - if (empty($args['case'])) { - return $this->available(); - } - - $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 = []) { - restore_error_handler(); - restore_error_handler(); - - $testCli = new TestSuiteCommand('Cake\TestSuite\TestLoader', $runnerArgs); - $testCli->run($options); + $this->outputWarning(); + return 255; } /** @@ -281,162 +48,17 @@ protected function _run($runnerArgs, $options = []) { * @return void */ public function available() { - $params = $this->_parseArgs(); - $testCases = TestLoader::generateTestList($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; - } - - if (empty($testCases)) { - $this->out(__d('cake_console', "No test cases available \n\n")); - return $this->out($this->OptionParser->help()); - } - - $this->out($title); - $i = 1; - $cases = []; - foreach ($testCases as $testCase) { - $case = str_replace('Test.php', '', $testCase); - $this->out("[$i] $case"); - $cases[$i] = $case; - $i++; - } - - while ($choice = $this->in(__d('cake_console', '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]; - $this->_run($this->_parseArgs(), $this->_runnerOptions()); - break; - } - - if (is_string($choice) && in_array($choice, $cases)) { - $this->args[0] = $category; - $this->args[1] = $choice; - $this->_run($this->_parseArgs(), $this->_runnerOptions()); - break; - } - - if ($choice === 'q') { - break; - } - } - } - -/** - * Find the test case for the passed file. The file could itself be a test. - * - * @param string $file - * @param string $category - * @param boolean $throwOnMissingFile - * @return array [type, case] - * @throws \Exception - */ - protected function _mapFileToCase($file, $category, $throwOnMissingFile = true) { - if (!$category || (substr($file, -4) !== '.php')) { - return false; - } - - $_file = realpath($file); - if ($_file) { - $file = $_file; - } - - $testFile = $testCase = null; - - if (preg_match('@Test[\\\/]@', $file)) { - - if (substr($file, -8) === 'Test.php') { - - $testCase = substr($file, 0, -8); - $testCase = str_replace(DS, '/', $testCase); - - if ($testCase = preg_replace('@.*Test\/TestCase\/@', '', $testCase)) { - - if ($category === 'core') { - $testCase = str_replace('lib/Cake', '', $testCase); - } - - return $testCase; - } - - throw new \Exception(sprintf('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 = ROOT . '/tests/TestCase/' . $testCase . 'Test.php'; - - if (!file_exists($testFile) && $throwOnMissingFile) { - throw new \Exception(sprintf('Test case %s not found', $testFile)); - } - - return $testCase; - } - - if ($category === 'app') { - $testFile = str_replace(APP, APP . 'tests/TestCase/', $file) . 'Test.php'; - } else { - $testFile = preg_replace( - "@((?:plugins|Plugin)[\\/]{$category}[\\/])(.*)$@", - '\1tests/TestCase/\2Test.php', - $file - ); - } - - if (!file_exists($testFile) && $throwOnMissingFile) { - throw new \Exception(sprintf('Test case %s not found', $testFile)); - } - - $testCase = substr($testFile, 0, -8); - $testCase = str_replace(DS, '/', $testCase); - $testCase = preg_replace('@.*tests/TestCase/@', '', $testCase); - - return $testCase; + $this->outputWarning(); + return 255; } -/** - * For the given file, what category of test is it? returns app, core or the name of the plugin - * - * @param string $file - * @return string - */ - protected function _mapFileToCategory($file) { - $_file = realpath($file); - if ($_file) { - $file = $_file; - } - - $file = str_replace(DS, '/', $file); - if (preg_match('@(?:plugins|Plugin)/([^/]*)@', $file, $match)) { - return $match[1]; - } - if (strpos($file, APP) !== false) { - return 'app'; - } - $file = preg_replace( - ['#^Cake/#', '#^Test/#'], - ['src/', 'tests/'], - $file - ); - if (file_exists(ROOT . DS . $file) || strpos($file, ROOT . DS) !== false) { - return 'core'; - } - return 'app'; + public function outputWarning() { + $this->err('Test Shell has been removed.'); + $this->err(''); + $this->err('TestShell has been removed and replaced with phpunit.'); + $this->err(''); + $this->err('To run your application tests run phpunit --stderr'); + $this->err('To run plugin tests, cd into the plugin directory and run phpunit --stderr'); } } diff --git a/src/TestSuite/Coverage/BaseCoverageReport.php b/src/TestSuite/Coverage/BaseCoverageReport.php deleted file mode 100644 index 508b2ca314a..00000000000 --- a/src/TestSuite/Coverage/BaseCoverageReport.php +++ /dev/null @@ -1,182 +0,0 @@ -_rawCoverage = $coverage; - $this->_setParams($reporter); - } - -/** - * Pulls params out of the reporter. - * - * @param \Cake\TestSuite\Reporter\BaseReporter $reporter Reporter to suck params out of. - * @return void - */ - protected function _setParams(BaseReporter $reporter) { - if ($reporter->params['app']) { - $this->appTest = true; - } - if ($reporter->params['plugin']) { - $this->pluginTest = Inflector::camelize($reporter->params['plugin']); - } - } - -/** - * Set the coverage data array - * - * @param array $coverage Coverage data to use. - * @return void - */ - public function setCoverage($coverage) { - $this->_rawCoverage = $coverage; - } - -/** - * Gets the base path that the files we are interested in live in. - * - * @return string Path - */ - public function getPathFilter() { - $path = ROOT . DS; - if ($this->appTest) { - $path .= APP_DIR . DS; - } elseif ($this->pluginTest) { - $path = App::pluginPath($this->pluginTest); - } else { - $path = CAKE; - } - return $path; - } - -/** - * Filters the coverage data by path. Files not in the provided path will be removed. - * - * @param string $path Path to filter files by. - * @return array Array of coverage data for files that match the given path. - */ - public function filterCoverageDataByPath($path) { - $files = array(); - foreach ($this->_rawCoverage as $fileName => $fileCoverage) { - if (strpos($fileName, $path) !== 0) { - continue; - } - $files[$fileName] = $fileCoverage; - } - return $files; - } - -/** - * Calculates how many lines are covered and what the total number of executable lines is. - * - * Handles both PHPUnit3.5 and 3.6 formats. - * - * 3.5 uses -1 for uncovered, and -2 for dead. - * 3.6 uses array() for uncovered and null for dead. - * - * @param array $fileLines - * @param array $coverageData - * @return array Array of covered, total lines. - */ - protected function _calculateCoveredLines($fileLines, $coverageData) { - $covered = $total = 0; - - //shift line numbers forward one - array_unshift($fileLines, ' '); - unset($fileLines[0]); - - foreach ($fileLines as $lineno => $line) { - if (!isset($coverageData[$lineno])) { - continue; - } - if (is_array($coverageData[$lineno]) && !empty($coverageData[$lineno])) { - $covered++; - $total++; - } elseif ($coverageData[$lineno] === -1 || $coverageData[$lineno] === array()) { - $total++; - } - } - return array($covered, $total); - } - -/** - * Generates report to display. - * - * @return string compiled html report. - */ - abstract public function report(); - -/** - * Generates an coverage 'diff' for $file based on $coverageData. - * - * @param string $filename Name of the file having coverage generated - * @param array $fileLines File data as an array. See file() for how to get one of these. - * @param array $coverageData Array of coverage data to use to generate HTML diffs with - * @return string prepared report for a single file. - */ - abstract public function generateDiff($filename, $fileLines, $coverageData); - -} diff --git a/src/TestSuite/Coverage/HtmlCoverageReport.php b/src/TestSuite/Coverage/HtmlCoverageReport.php deleted file mode 100644 index d75f67be818..00000000000 --- a/src/TestSuite/Coverage/HtmlCoverageReport.php +++ /dev/null @@ -1,225 +0,0 @@ -getPathFilter(); - $coverageData = $this->filterCoverageDataByPath($pathFilter); - if (empty($coverageData)) { - return '

No files to generate coverage for

'; - } - $output = $this->coverageScript(); - $output .= <<Code coverage results - Toggle all files - -HTML; - foreach ($coverageData as $file => $coverageData) { - $fileData = file($file); - $output .= $this->generateDiff($file, $fileData, $coverageData); - } - - $percentCovered = 100; - if ($this->_total > 0) { - $percentCovered = round(100 * $this->_covered / $this->_total, 2); - } - $output .= '
Overall coverage: ' . $percentCovered . '%
'; - return $output; - } - -/** - * Generates an HTML diff for $file based on $coverageData. - * - * Handles both PHPUnit3.5 and 3.6 formats. - * - * 3.5 uses -1 for uncovered, and -2 for dead. - * 3.6 uses array() for uncovered and null for dead. - * - * @param string $filename Name of the file having coverage generated - * @param array $fileLines File data as an array. See file() for how to get one of these. - * @param array $coverageData Array of coverage data to use to generate HTML diffs with - * @return string HTML diff. - */ - public function generateDiff($filename, $fileLines, $coverageData) { - $output = ''; - $diff = array(); - - list($covered, $total) = $this->_calculateCoveredLines($fileLines, $coverageData); - $this->_covered += $covered; - $this->_total += $total; - - //shift line numbers forward one; - array_unshift($fileLines, ' '); - unset($fileLines[0]); - - foreach ($fileLines as $lineno => $line) { - $class = 'ignored'; - $coveringTests = array(); - if (!empty($coverageData[$lineno]) && is_array($coverageData[$lineno])) { - $coveringTests = array(); - foreach ($coverageData[$lineno] as $test) { - $class = (is_array($test) && isset($test['id'])) ? $test['id'] : $test; - $testReflection = new \ReflectionClass(current(explode('::', $class))); - $this->_testNames[] = $this->_guessSubjectName($testReflection); - $coveringTests[] = $class; - } - $class = 'covered'; - } elseif (isset($coverageData[$lineno]) && ($coverageData[$lineno] === -1 || $coverageData[$lineno] === array())) { - $class = 'uncovered'; - } elseif (array_key_exists($lineno, $coverageData) && ($coverageData[$lineno] === -2 || $coverageData[$lineno] === null)) { - $class .= ' dead'; - } - $diff[] = $this->_paintLine($line, $lineno, $class, $coveringTests); - } - - $percentCovered = 100; - if ($total > 0) { - $percentCovered = round(100 * $covered / $total, 2); - } - $output .= $this->coverageHeader($filename, $percentCovered); - $output .= implode("", $diff); - $output .= $this->coverageFooter(); - return $output; - } - -/** - * Guess the class name the test was for based on the test case filename. - * - * @param ReflectionClass $testReflection. - * @return string Possible test subject name. - */ - protected function _guessSubjectName($testReflection) { - $basename = basename($testReflection->getFilename()); - if (strpos($basename, '.test') !== false) { - list($subject, ) = explode('.', $basename, 2); - return $subject; - } - $subject = str_replace('Test.php', '', $basename); - return $subject; - } - -/** - * Renders the HTML for a single line in the HTML diff. - * - * @param string $line - * @param integer $linenumber - * @param string $class - * @param array $coveringTests - * @return string - */ - protected function _paintLine($line, $linenumber, $class, $coveringTests) { - $coveredBy = ''; - if (!empty($coveringTests)) { - $coveredBy = "Covered by:\n"; - foreach ($coveringTests as $test) { - $coveredBy .= $test . "\n"; - } - } - - return sprintf( - '
%s%s
', - $class, - $coveredBy, - $linenumber, - htmlspecialchars($line) - ); - } - -/** - * generate some javascript for the coverage report. - * - * @return string - */ - public function coverageScript() { - return << - function coverage_show_hide(selector) { - var element = document.getElementById(selector); - element.style.display = (element.style.display === 'none') ? '' : 'none'; - } - function coverage_toggle_all() { - var divs = document.querySelectorAll('div.coverage-container'); - var i = divs.length; - while (i--) { - if (divs[i] && divs[i].className.indexOf('primary') == -1) { - divs[i].style.display = (divs[i].style.display === 'none') ? '' : 'none'; - } - } - } - -HTML; - } - -/** - * Generate an HTML snippet for coverage headers - * - * @param string $filename - * @param string $percent - * @return string - */ - public function coverageHeader($filename, $percent) { - $filename = basename($filename); - list($file) = explode('.', $filename); - $display = in_array($file, $this->_testNames) ? 'block' : 'none'; - $primary = $display === 'block' ? 'primary' : ''; - return << -

- - $filename Code coverage: $percent% - -

- "; - } - -} diff --git a/src/TestSuite/Coverage/TextCoverageReport.php b/src/TestSuite/Coverage/TextCoverageReport.php deleted file mode 100644 index 4290fc1a2da..00000000000 --- a/src/TestSuite/Coverage/TextCoverageReport.php +++ /dev/null @@ -1,61 +0,0 @@ -getPathFilter(); - $coverageData = $this->filterCoverageDataByPath($pathFilter); - if (empty($coverageData)) { - return 'No files to generate coverage for'; - } - $output = "\nCoverage Report:\n\n"; - foreach ($coverageData as $file => $coverageData) { - $fileData = file($file); - $output .= $this->generateDiff($file, $fileData, $coverageData); - } - return $output; - } - -/** - * Generates a 'diff' report for a file. - * Since diffs are too big for plain text reports a simple file => % covered is done. - * - * @param string $filename Name of the file having coverage generated - * @param array $fileLines File data as an array. See file() for how to get one of these. - * @param array $coverageData Array of coverage data to use to generate HTML diffs with - * @return string - */ - public function generateDiff($filename, $fileLines, $coverageData) { - list($covered, $total) = $this->_calculateCoveredLines($fileLines, $coverageData); - $percentCovered = round(100 * $covered / $total, 2); - return "$filename : $percentCovered%\n"; - } - -} diff --git a/src/TestSuite/Reporter/BaseReporter.php b/src/TestSuite/Reporter/BaseReporter.php deleted file mode 100644 index 5f2a4387310..00000000000 --- a/src/TestSuite/Reporter/BaseReporter.php +++ /dev/null @@ -1,216 +0,0 @@ - - * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) - * - * Licensed under The MIT License - * For full copyright and license information, please see the LICENSE.txt - * Redistributions of files must retain the above copyright notice - * - * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) - * @link http://cakephp.org CakePHP(tm) Project - * @since CakePHP(tm) v 1.3 - * @license http://www.opensource.org/licenses/mit-license.php MIT License - */ -namespace Cake\TestSuite\Reporter; - -use Cake\TestSuite\TestLoader; - -/** - * BaseReporter contains common reporting features used in the CakePHP Test suite - * - */ -class BaseReporter extends \PHPUnit_TextUI_ResultPrinter { - -/** - * Headers sent - * - * @var boolean - */ - protected $_headerSent = false; - -/** - * Array of request parameters. Usually parsed GET params. - * - * @var array - */ - public $params = array(); - -/** - * Character set for the output of test reporting. - * - * @var string - */ - protected $_characterSet; - -/** - * Does nothing yet. The first output will - * be sent on the first test start. - * - * ### Params - * - * - show_passes - Should passes be shown - * - plugin - Plugin test being run? - * - core - Core test being run. - * - case - The case being run - * - codeCoverage - Whether the case/group being run is being code covered. - * - * @param string $charset The character set to output with. Defaults to UTF-8 - * @param array $params Array of request parameters the reporter should use. See above. - */ - public function __construct($charset = 'utf-8', $params = array()) { - if (!$charset) { - $charset = 'utf-8'; - } - $this->_characterSet = $charset; - $this->params = $params; - } - -/** - * Retrieves a list of test cases from the active Manager class, - * displaying it in the correct format for the reporter subclass - * - * @return mixed - */ - public function testCaseList() { - $testList = TestLoader::generateTestList($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. - * - * @return void - */ - public function paintDocumentStart() { - } - -/** - * Paints the end of the response from the test suite. - * Used to paint things like in an html page. - * - * @return void - */ - public function paintDocumentEnd() { - } - -/** - * Paint a list of test sets, core, app, and plugin test sets - * available. - * - * @return void - */ - public function paintTestMenu() { - } - -/** - * Get the baseUrl if one is available. - * - * @return string The base URL for the request. - */ - public function baseUrl() { - if (!empty($_SERVER['PHP_SELF'])) { - return $_SERVER['PHP_SELF']; - } - return ''; - } - -/** - * Paint result - * - * @param \PHPUnit_Framework_TestResult $result - */ - public function printResult(\PHPUnit_Framework_TestResult $result) { - $this->paintFooter($result); - } - -/** - * An error occurred. - * - * @param \PHPUnit_Framework_Test $test - * @param \Exception $e - * @param float $time - */ - public function addError(\PHPUnit_Framework_Test $test, \Exception $e, $time) { - $this->paintException($e, $test); - } - -/** - * A failure occurred. - * - * @param \PHPUnit_Framework_Test $test - * @param \PHPUnit_Framework_AssertionFailedError $e - * @param float $time - */ - public function addFailure(\PHPUnit_Framework_Test $test, \PHPUnit_Framework_AssertionFailedError $e, $time) { - $this->paintFail($e, $test); - } - -/** - * Incomplete test. - * - * @param \PHPUnit_Framework_Test $test - * @param \Exception $e - * @param float $time - */ - public function addIncompleteTest(\PHPUnit_Framework_Test $test, \Exception $e, $time) { - $this->paintSkip($e, $test); - } - -/** - * Skipped test. - * - * @param \PHPUnit_Framework_Test $test - * @param \Exception $e - * @param float $time - */ - public function addSkippedTest(\PHPUnit_Framework_Test $test, \Exception $e, $time) { - $this->paintSkip($e, $test); - } - -/** - * A test suite started. - * - * @param \PHPUnit_Framework_TestSuite $suite - */ - public function startTestSuite(\PHPUnit_Framework_TestSuite $suite) { - if (!$this->_headerSent) { - echo $this->paintHeader(); - } - echo sprintf('Running %s', $suite->getName()) . "\n"; - } - -/** - * A test suite ended. - * - * @param \PHPUnit_Framework_TestSuite $suite - */ - public function endTestSuite(\PHPUnit_Framework_TestSuite $suite) { - } - -/** - * A test started. - * - * @param \PHPUnit_Framework_Test $test - */ - public function startTest(\PHPUnit_Framework_Test $test) { - } - -/** - * A test ended. - * - * @param \PHPUnit_Framework_Test $test - * @param float $time - */ - public function endTest(\PHPUnit_Framework_Test $test, $time) { - $this->numAssertions += $test->getNumAssertions(); - if ($test->hasFailed()) { - return; - } - $this->paintPass($test, $time); - } - -} diff --git a/src/TestSuite/Reporter/HtmlReporter.php b/src/TestSuite/Reporter/HtmlReporter.php deleted file mode 100644 index ecfb8bc14db..00000000000 --- a/src/TestSuite/Reporter/HtmlReporter.php +++ /dev/null @@ -1,385 +0,0 @@ - - * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) - * - * Licensed under The MIT License - * For full copyright and license information, please see the LICENSE.txt - * Redistributions of files must retain the above copyright notice - * - * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) - * @link http://cakephp.org CakePHP(tm) Project - * @since CakePHP(tm) v 1.2.0.4433 - * @license http://www.opensource.org/licenses/mit-license.php MIT License - */ -namespace Cake\TestSuite\Reporter; - -use Cake\Core\App; -use Cake\Core\Configure; -use Cake\TestSuite\Coverage\HtmlCoverageReport; -use Cake\Utility\Inflector; -use PHPUnit_Util_Diff; - -/** - * HtmlReporter Reports Results of TestSuites and Test Cases - * in an HTML format / context. - * - */ -class HtmlReporter extends BaseReporter { - -/** - * Paints the top of the web page setting the - * title to the name of the starting test. - * - * @return void - */ - public function paintHeader() { - $this->_headerSent = true; - $this->sendContentType(); - $this->sendNoCacheHeaders(); - $this->paintDocumentStart(); - $this->paintTestMenu(); - echo "
    \n"; - } - -/** - * Set the content-type header so it is in the correct encoding. - * - * @return void - */ - public function sendContentType() { - if (!headers_sent()) { - header('Content-Type: text/html; charset=' . Configure::read('App.encoding')); - } - } - -/** - * Paints the document start content contained in header.php - * - * @return void - */ - public function paintDocumentStart() { - ob_start(); - $baseDir = $this->params['baseDir']; - include CAKE . 'TestSuite/templates/header.php'; - } - -/** - * Paints the menu on the left side of the test suite interface. - * Contains all of the various plugin, core, and app buttons. - * - * @return void - */ - public function paintTestMenu() { - $cases = $this->baseUrl() . '?show=cases'; - $plugins = App::objects('plugin', null, false); - sort($plugins); - include CAKE . 'TestSuite/templates/menu.php'; - } - -/** - * Retrieves and paints the list of tests cases in an HTML format. - * - * @return void - */ - public function testCaseList() { - $testCases = parent::testCaseList(); - $core = $this->params['core']; - $plugin = $this->params['plugin']; - - $buffer = "

    App Test Cases:

    \n
      "; - $urlExtra = null; - if ($core) { - $buffer = "

      Core Test Cases:

      \n
        "; - $urlExtra = '&core=true'; - } elseif ($plugin) { - $buffer = "

        " . Inflector::humanize($plugin) . " Test Cases:

        \n
          "; - $urlExtra = '&plugin=' . $plugin; - } - - if (count($testCases) < 1) { - $buffer .= "EMPTY"; - } - - foreach ($testCases as $testCase) { - $title = explode(DS, str_replace('.test.php', '', $testCase)); - $title[count($title) - 1] = Inflector::camelize($title[count($title) - 1]); - $title = implode(' / ', $title); - $buffer .= "
        • " . $title . "
        • \n"; - } - $buffer .= "
        \n"; - echo $buffer; - } - -/** - * Send the headers necessary to ensure the page is - * reloaded on every request. Otherwise you could be - * scratching your head over out of date test data. - * - * @return void - */ - public function sendNoCacheHeaders() { - if (!headers_sent()) { - header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); - header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); - header("Cache-Control: no-store, no-cache, must-revalidate"); - header("Cache-Control: post-check=0, pre-check=0", false); - header("Pragma: no-cache"); - } - } - -/** - * Paints the end of the test with a summary of - * the passes and failures. - * - * @param PHPUnit_Framework_TestResult $result Result object - * @return void - */ - public function paintFooter($result) { - ob_end_flush(); - $colour = ($result->failureCount() + $result->errorCount() > 0 ? "red" : "green"); - echo "
      \n"; - echo "
      "; - echo ($result->count() - $result->skippedCount()) . "/" . $result->count(); - echo " test methods complete:\n"; - echo "" . count($result->passed()) . " passes, "; - echo "" . $result->failureCount() . " fails, "; - echo "" . $this->numAssertions . " assertions and "; - echo "" . $result->errorCount() . " exceptions."; - echo "
      \n"; - echo '
      '; - echo '

      Time: ' . $result->time() . ' seconds

      '; - echo '

      Peak memory: ' . number_format(memory_get_peak_usage()) . ' bytes

      '; - echo $this->_paintLinks(); - echo '
      '; - if (isset($this->params['codeCoverage']) && $this->params['codeCoverage']) { - $coverage = $result->getCodeCoverage(); - if (method_exists($coverage, 'getSummary')) { - $report = $coverage->getSummary(); - echo $this->paintCoverage($report); - } - if (method_exists($coverage, 'getData')) { - $report = $coverage->getData(); - echo $this->paintCoverage($report); - } - } - $this->paintDocumentEnd(); - } - -/** - * Paints a code coverage report. - * - * @param array $coverage - * @return void - */ - public function paintCoverage(array $coverage) { - $reporter = new HtmlCoverageReport($coverage, $this); - echo $reporter->report(); - } - -/** - * Renders the links that for accessing things in the test suite. - * - * @return void - */ - protected function _paintLinks() { - $show = $query = array(); - if (!empty($this->params['case'])) { - $show['show'] = 'cases'; - } - - if (!empty($this->params['core'])) { - $show['core'] = $query['core'] = 'true'; - } - if (!empty($this->params['plugin'])) { - $show['plugin'] = $query['plugin'] = $this->params['plugin']; - } - if (!empty($this->params['case'])) { - $query['case'] = $this->params['case']; - } - $show = $this->_queryString($show); - $query = $this->_queryString($query); - - echo "

      Run more tests | Show Passes | \n"; - echo "Enable Debug Output | \n"; - echo "Analyze Code Coverage

      \n"; - } - -/** - * Convert an array of parameters into a query string url - * - * @param array $url Url hash to be converted - * @return string Converted url query string - */ - protected function _queryString($url) { - $out = '?'; - $params = array(); - foreach ($url as $key => $value) { - $params[] = "$key=$value"; - } - $out .= implode('&', $params); - return $out; - } - -/** - * Paints the end of the document html. - * - * @return void - */ - public function paintDocumentEnd() { - $baseDir = $this->params['baseDir']; - include CAKE . 'TestSuite/templates/footer.php'; - if (ob_get_length()) { - ob_end_flush(); - } - } - -/** - * Paints the test failure with a breadcrumbs - * trail of the nesting test suites below the - * top level test. - * - * @param PHPUnit_Framework_AssertionFailedError $message Failure object displayed in - * the context of the other tests. - * @param mixed $test - * @return void - */ - public function paintFail($message, $test) { - $trace = $this->_getStackTrace($message); - $testName = get_class($test) . '(' . $test->getName() . ')'; - - $actualMsg = $expectedMsg = null; - if (method_exists($message, 'getComparisonFailure')) { - $failure = $message->getComparisonFailure(); - if (is_object($failure)) { - $actualMsg = $failure->getActualAsString(); - $expectedMsg = $failure->getExpectedAsString(); - } - } - - echo "
    • \n"; - echo "Failed"; - echo "
      " . $this->_htmlEntities($message->toString());
      -
      -		if ((is_string($actualMsg) && is_string($expectedMsg)) || (is_array($actualMsg) && is_array($expectedMsg))) {
      -			echo "
      " . PHPUnit_Util_Diff::diff($expectedMsg, $actualMsg); - } - - echo "
      \n"; - echo "
      " . sprintf('Test case: %s', $testName) . "
      \n"; - echo "
      " . 'Stack trace:' . '
      ' . $trace . "
      \n"; - echo "
    • \n"; - } - -/** - * Paints the test pass with a breadcrumbs - * trail of the nesting test suites below the - * top level test. - * - * @param \PHPUnit_Framework_Test test method that just passed - * @param float $time time spent to run the test method - * @return void - */ - public function paintPass(\PHPUnit_Framework_Test $test, $time = null) { - if (isset($this->params['showPasses']) && $this->params['showPasses']) { - echo "
    • \n"; - echo "Passed "; - - echo "
      " . $this->_htmlEntities($test->getName()) . " ($time seconds)\n"; - echo "
    • \n"; - } - } - -/** - * Paints a PHP exception. - * - * @param Exception $exception Exception to display. - * @param mixed $test - * @return void - */ - public function paintException($exception, $test) { - $trace = $this->_getStackTrace($exception); - $testName = get_class($test) . '(' . $test->getName() . ')'; - - echo "
    • \n"; - echo "" . get_class($exception) . ""; - - echo "
      " . $this->_htmlEntities($exception->getMessage()) . "
      \n"; - echo "
      " . sprintf('Test case: %s', $testName) . "
      \n"; - echo "
      " . 'Stack trace:' . '
      ' . $trace . "
      \n"; - echo "
    • \n"; - } - -/** - * Prints the message for skipping tests. - * - * @param string $message Text of skip condition. - * @param PHPUnit_Framework_TestCase $test the test method skipped - * @return void - */ - public function paintSkip($message, $test) { - echo "
    • \n"; - echo "Skipped "; - echo $test->getName() . ': ' . $this->_htmlEntities($message->getMessage()); - echo "
    • \n"; - } - -/** - * Paints formatted text such as dumped variables. - * - * @param string $message Text to show. - * @return void - */ - public function paintFormattedMessage($message) { - echo '
      ' . $this->_htmlEntities($message) . '
      '; - } - -/** - * Character set adjusted entity conversion. - * - * @param string $message Plain text or Unicode message. - * @return string Browser readable message. - */ - protected function _htmlEntities($message) { - return htmlentities($message, ENT_COMPAT, $this->_characterSet); - } - -/** - * Gets a formatted stack trace. - * - * @param \Exception $e Exception to get a stack trace for. - * @return string Generated stack trace. - */ - protected function _getStackTrace(\Exception $e) { - $trace = $e->getTrace(); - $out = array(); - foreach ($trace as $frame) { - if (isset($frame['file']) && isset($frame['line'])) { - $out[] = $frame['file'] . ' : ' . $frame['line']; - } elseif (isset($frame['class']) && isset($frame['function'])) { - $out[] = $frame['class'] . '::' . $frame['function']; - } else { - $out[] = '[internal]'; - } - } - return implode('
      ', $out); - } - -/** - * A test suite started. - * - * @param \PHPUnit_Framework_TestSuite $suite - * @return void - */ - public function startTestSuite(\PHPUnit_Framework_TestSuite $suite) { - if (!$this->_headerSent) { - echo $this->paintHeader(); - } - echo '

      ' . sprintf('Running %s', $suite->getName()) . '

      '; - } - -} diff --git a/src/TestSuite/Reporter/TextReporter.php b/src/TestSuite/Reporter/TextReporter.php deleted file mode 100644 index 93d19206ad1..00000000000 --- a/src/TestSuite/Reporter/TextReporter.php +++ /dev/null @@ -1,183 +0,0 @@ - - * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) - * - * Licensed under The MIT License - * For full copyright and license information, please see the LICENSE.txt - * Redistributions of files must retain the above copyright notice - * - * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) - * @link http://cakephp.org CakePHP(tm) Project - * @since CakePHP(tm) v 1.3 - * @license http://www.opensource.org/licenses/mit-license.php MIT License - */ -namespace Cake\TestSuite\Reporter; - -use Cake\TestSuite\Coverage\TextCoverageReport; -use Cake\Utility\Inflector; - -/** - * TextReporter contains reporting features used for plain text based output - * - */ -class TextReporter extends BaseReporter { - -/** - * Sets the text/plain header if the test is not a CLI test. - * - * @return void - */ - public function paintDocumentStart() { - if (!headers_sent()) { - header('Content-type: text/plain'); - } - } - -/** - * Paints a pass - * - * @return void - */ - public function paintPass() { - echo '.'; - } - -/** - * Paints a failing test. - * - * @param PHPUnit_Framework_AssertionFailedError $message Failure object displayed in - * the context of the other tests. - * @return void - */ - public function paintFail($message) { - $context = $message->getTrace(); - $realContext = $context[3]; - $context = $context[2]; - - printf( - "FAIL on line %s\n%s in\n%s %s()\n\n", - $context['line'], $message->toString(), $context['file'], $realContext['function'] - ); - } - -/** - * Paints the end of the test with a summary of - * the passes and failures. - * - * @param PHPUnit_Framework_TestResult $result Result object - * @return void - */ - public function paintFooter($result) { - if ($result->failureCount() + $result->errorCount()) { - echo "FAILURES!!!\n"; - } else { - echo "\nOK\n"; - } - - echo "Test cases run: " . $result->count() . - "/" . ($result->count() - $result->skippedCount()) . - ', Passes: ' . $this->numAssertions . - ', Failures: ' . $result->failureCount() . - ', Exceptions: ' . $result->errorCount() . "\n"; - - echo 'Time: ' . $result->time() . " seconds\n"; - echo 'Peak memory: ' . number_format(memory_get_peak_usage()) . " bytes\n"; - - if (isset($this->params['codeCoverage']) && $this->params['codeCoverage']) { - $coverage = $result->getCodeCoverage()->getSummary(); - echo $this->paintCoverage($coverage); - } - } - -/** - * Paints the title only. - * - * @return void - */ - public function paintHeader() { - $this->paintDocumentStart(); - flush(); - } - -/** - * Paints a PHP exception. - * - * @param Exception $exception Exception to describe. - * @return void - */ - public function paintException($exception) { - $message = 'Unexpected exception of type [' . get_class($exception) . - '] with message [' . $exception->getMessage() . - '] in [' . $exception->getFile() . - ' line ' . $exception->getLine() . ']'; - echo $message . "\n\n"; - } - -/** - * Prints the message for skipping tests. - * - * @param string $message Text of skip condition. - * @return void - */ - public function paintSkip($message) { - printf("Skip: %s\n", $message->getMessage()); - } - -/** - * Paints formatted text such as dumped variables. - * - * @param string $message Text to show. - * @return void - */ - public function paintFormattedMessage($message) { - echo "$message\n"; - flush(); - } - -/** - * Generate a test case list in plain text. - * Creates as series of URLs for tests that can be run. - * One case per line. - * - * @return void - */ - public function testCaseList() { - $testCases = parent::testCaseList(); - $app = $this->params['app']; - $plugin = $this->params['plugin']; - - $buffer = "Core Test Cases:\n"; - if ($app) { - $buffer = "App Test Cases:\n"; - } elseif ($plugin) { - $buffer = Inflector::humanize($plugin) . " Test Cases:\n"; - } - - if (count($testCases) < 1) { - $buffer .= 'EMPTY'; - echo $buffer; - } - - foreach ($testCases as $testCase) { - $buffer .= $_SERVER['SERVER_NAME'] . $this->baseUrl() . "?case=" . $testCase . "&output=text\n"; - } - - $buffer .= "\n"; - echo $buffer; - } - -/** - * Generates a Text summary of the coverage data. - * - * @param array $coverage Array of coverage data. - * @return void - */ - public function paintCoverage($coverage) { - $reporter = new TextCoverageReport($coverage, $this); - echo $reporter->report(); - } - -} diff --git a/src/TestSuite/TestLoader.php b/src/TestSuite/TestLoader.php deleted file mode 100644 index fd74ad0859d..00000000000 --- a/src/TestSuite/TestLoader.php +++ /dev/null @@ -1,127 +0,0 @@ -_resolveTestFile($filePath, $params); - return parent::load('', $file); - } - -/** - * Convert path fragments used by CakePHP's test runner to absolute paths that can be fed to PHPUnit. - * - * @param string $filePath - * @param string $params - * @return void - */ - protected function _resolveTestFile($filePath, $params) { - $basePath = $this->_basePath($params) . DS . $filePath; - $ending = 'Test.php'; - return (strpos($basePath, $ending) === (strlen($basePath) - strlen($ending))) ? $basePath : $basePath . $ending; - } - -/** - * Generates the base path to a set of tests based on the parameters. - * - * @param array $params - * @return string The base path. - */ - protected static function _basePath($params) { - $result = null; - if (!empty($params['core'])) { - $result = CORE_TEST_CASES; - } elseif (!empty($params['plugin'])) { - if (!Plugin::loaded($params['plugin'])) { - try { - Plugin::load($params['plugin']); - $result = Plugin::path($params['plugin']) . 'Test/TestCase'; - } catch (Error\MissingPluginException $e) { - } - } else { - $result = Plugin::path($params['plugin']) . 'Test/TestCase'; - } - } elseif (!empty($params['app'])) { - $result = APP_TEST_CASES; - } - return $result; - } - -/** - * Get the list of files for the test listing. - * - * @param string $params - * @return array - */ - public static function generateTestList($params) { - $directory = static::_basePath($params); - $fileList = static::_getRecursiveFileList($directory); - - $testCases = array(); - foreach ($fileList as $testCaseFile) { - $case = str_replace($directory . DS, '', $testCaseFile); - $case = str_replace('Test.php', '', $case); - $testCases[$testCaseFile] = $case; - } - sort($testCases); - return $testCases; - } - -/** - * Gets a recursive list of files from a given directory and matches then against - * a given fileTestFunction, like isTestCaseFile() - * - * @param string $directory The directory to scan for files. - * @return array - */ - protected static function _getRecursiveFileList($directory = '.') { - $fileList = array(); - if (!is_dir($directory)) { - return $fileList; - } - - $files = new \RegexIterator( - new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory)), - '/.*Test.php$/' - ); - - foreach ($files as $file) { - $fileList[] = $file->getPathname(); - } - return $fileList; - } - -} diff --git a/src/TestSuite/TestRunner.php b/src/TestSuite/TestRunner.php deleted file mode 100644 index 5b3130bae08..00000000000 --- a/src/TestSuite/TestRunner.php +++ /dev/null @@ -1,108 +0,0 @@ -_params = $params; - } - -/** - * Actually run a suite of tests. Cake initializes fixtures here using the chosen fixture manager - * - * @param \PHPUnit_Framework_Test $suite - * @param array $arguments - * @return void - */ - public function doRun(\PHPUnit_Framework_Test $suite, array $arguments = array()) { - if (isset($arguments['printer'])) { - static::$versionStringPrinted = true; - } - - $autoloader = new ClassLoader('TestApp', dirname(__DIR__) . '/Test'); - $autoloader->register(); - - $fixture = $this->_getFixtureManager($arguments); - foreach ($suite->getIterator() as $test) { - if ($test instanceof TestCase) { - $fixture->fixturize($test); - $test->fixtureManager = $fixture; - } - } - - $return = parent::doRun($suite, $arguments); - $fixture->shutdown(); - return $return; - } - -// @codingStandardsIgnoreStart PHPUnit overrides don't match CakePHP -/** - * Create the test result and splice on our code coverage reports. - * - * @return PHPUnit_Framework_TestResult - */ - protected function createTestResult() { - $result = new \PHPUnit_Framework_TestResult; - if (!empty($this->_params['codeCoverage'])) { - if (method_exists($result, 'collectCodeCoverageInformation')) { - $result->collectCodeCoverageInformation(true); - } - if (method_exists($result, 'setCodeCoverage')) { - $result->setCodeCoverage(new \PHP_CodeCoverage()); - } - } - return $result; - } -// @codingStandardsIgnoreEnd - -/** - * Get the fixture manager class specified or use the default one. - * - * @param array $arguments - * @return mixed instance of a fixture manager. - * @throws \RuntimeException When fixture manager class cannot be loaded. - */ - protected function _getFixtureManager($arguments) { - if (isset($arguments['fixtureManager'])) { - $class = App::classname($arguments['fixtureManager'], 'TestSuite/Fixture'); - if (class_exists($class)) { - return new $class; - } - throw new \RuntimeException(sprintf('Could not find fixture manager %s.', $arguments['fixtureManager'])); - } - $class = App::classname('FixtureManager', 'TestSuite/Fixture'); - return new $class(); - } - -} diff --git a/src/TestSuite/TestSuiteCommand.php b/src/TestSuite/TestSuiteCommand.php deleted file mode 100644 index 45a2473a608..00000000000 --- a/src/TestSuite/TestSuiteCommand.php +++ /dev/null @@ -1,141 +0,0 @@ - $loader)); - } - $this->arguments['loader'] = $loader; - $this->arguments['test'] = $params['case']; - $this->arguments['testFile'] = $params; - $this->_params = $params; - - $this->longOptions['fixture='] = 'handleFixture'; - $this->longOptions['output='] = 'handleReporter'; - } - -/** - * Ugly hack to get around PHPUnit having a hard coded class name for the Runner. :( - * - * @param array $argv - * @param boolean $exit - */ - public function run(array $argv, $exit = true) { - $this->handleArguments($argv); - - $runner = $this->getRunner($this->arguments['loader']); - - if (is_object($this->arguments['test']) && - $this->arguments['test'] instanceof \PHPUnit_Framework_Test) { - $suite = $this->arguments['test']; - } else { - $suite = $runner->getTest( - $this->arguments['test'], - $this->arguments['testFile'] - ); - } - - if ($this->arguments['listGroups']) { - \PHPUnit_TextUI_TestRunner::printVersionString(); - - print "Available test group(s):\n"; - - $groups = $suite->getGroups(); - sort($groups); - - foreach ($groups as $group) { - print " - $group\n"; - } - - exit(\PHPUnit_TextUI_TestRunner::SUCCESS_EXIT); - } - - unset($this->arguments['test']); - unset($this->arguments['testFile']); - - try { - $result = $runner->doRun($suite, $this->arguments); - } catch (\PHPUnit_Framework_Exception $e) { - print $e->getMessage() . "\n"; - } - - if ($exit) { - if (isset($result) && $result->wasSuccessful()) { - exit(\PHPUnit_TextUI_TestRunner::SUCCESS_EXIT); - } elseif (!isset($result) || $result->errorCount() > 0) { - exit(\PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT); - } else { - exit(\PHPUnit_TextUI_TestRunner::FAILURE_EXIT); - } - exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT); - } - } - -/** - * Create a runner for the command. - * - * @param mixed $loader The loader to be used for the test run. - * @return \Cake\TestSuite\TestRunner - */ - public function getRunner($loader) { - return new TestRunner($loader, $this->_params); - } - -/** - * Handler for customizing the FixtureManager class/ - * - * @param string $class Name of the class that will be the fixture manager - * @return void - */ - public function handleFixture($class) { - $this->arguments['fixtureManager'] = $class; - } - -/** - * Handles output flag used to change printing on webrunner. - * - * @param string $reporter - * @return void - */ - public function handleReporter($reporter) { - $reporter = ucwords($reporter); - $class = App::classname($reporter, 'TestSuite/Reporter', 'Reporter'); - $object = new $class(null, $this->_params); - - return $this->arguments['printer'] = $object; - } - -} diff --git a/src/TestSuite/TestSuiteDispatcher.php b/src/TestSuite/TestSuiteDispatcher.php deleted file mode 100644 index 7ad5cd4ea39..00000000000 --- a/src/TestSuite/TestSuiteDispatcher.php +++ /dev/null @@ -1,277 +0,0 @@ - - * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) - * - * Licensed under The MIT License - * For full copyright and license information, please see the LICENSE.txt - * Redistributions of files must retain the above copyright notice - * - * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) - * @link http://cakephp.org CakePHP(tm) Project - * @since CakePHP(tm) v 1.3 - * @license http://www.opensource.org/licenses/mit-license.php MIT License - */ -namespace Cake\TestSuite; - -use Cake\Core\App; -use Cake\Error; - -define('CORE_TEST_CASES', CAKE . 'Test/TestCase'); -define('APP_TEST_CASES', TESTS . 'TestCase'); - -/** - * TestSuiteDispatcher handles web requests to the test suite and runs the correct action. - * - */ -class TestSuiteDispatcher { - -/** - * 'Request' parameters - * - * @var array - */ - public $params = array( - 'codeCoverage' => false, - 'case' => null, - 'core' => false, - 'app' => true, - 'plugin' => null, - 'output' => 'html', - 'show' => 'groups', - 'show_passes' => false, - 'filter' => false, - 'fixture' => null - ); - -/** - * Baseurl for the request - * - * @var string - */ - protected $_baseUrl; - -/** - * Base dir of the request. Used for accessing assets. - * - * @var string - */ - protected $_baseDir; - -/** - * boolean to set auto parsing of params. - * - * @var boolean - */ - protected $_paramsParsed = false; - -/** - * reporter instance used for the request - * - * @var \Cake\TestSuite\Reporter\BaseReporter - */ - protected static $_Reporter = null; - -/** - * Constructor - */ - public function __construct() { - $this->_baseUrl = $_SERVER['PHP_SELF']; - $dir = rtrim(dirname($this->_baseUrl), '\\'); - $this->_baseDir = ($dir === '/') ? $dir : $dir . '/'; - } - -/** - * Runs the actions required by the URL parameters. - * - * @return void - */ - public function dispatch() { - $this->_checkPHPUnit(); - $this->_parseParams(); - - if ($this->params['case']) { - $value = $this->_runTestCase(); - } else { - $value = $this->_testCaseList(); - } - - $output = ob_get_clean(); - echo $output; - return $value; - } - -/** - * Static method to initialize the test runner, keeps global space clean - * - * @return void - */ - public static function run() { - $dispatcher = new TestSuiteDispatcher(); - $dispatcher->dispatch(); - } - -/** - * Checks that PHPUnit is installed. Will exit if it doesn't - * - * @return void - */ - protected function _checkPHPUnit() { - $found = $this->loadTestFramework(); - if (!$found) { - $baseDir = $this->_baseDir; - include CAKE . 'TestSuite/templates/phpunit.php'; - exit(); - } - } - -/** - * Checks for the existence of the test framework files - * - * @return boolean true if found, false otherwise - */ - public function loadTestFramework() { - if (class_exists('PHPUnit_Framework_TestCase')) { - return true; - } - foreach (App::path('vendors') as $vendor) { - $vendor = rtrim($vendor, DS); - if (is_dir($vendor . DS . 'PHPUnit')) { - ini_set('include_path', $vendor . PATH_SEPARATOR . ini_get('include_path')); - break; - } - } - include 'PHPUnit' . DS . 'Autoload.php'; - return class_exists('PHPUnit_Framework_TestCase'); - } - -/** - * Checks for the xdebug extension required to do code coverage. Displays an error - * if xdebug isn't installed. - * - * @return void - */ - protected function _checkXdebug() { - if (!extension_loaded('xdebug')) { - $baseDir = $this->_baseDir; - include CAKE . 'TestSuite/templates/xdebug.php'; - exit(); - } - } - -/** - * Generates a page containing the a list of test cases that could be run. - * - * @return void - */ - protected function _testCaseList() { - $command = new TestSuiteCommand('', $this->params); - $Reporter = $command->handleReporter($this->params['output']); - $Reporter->paintDocumentStart(); - $Reporter->paintTestMenu(); - $Reporter->testCaseList(); - $Reporter->paintDocumentEnd(); - } - -/** - * Sets the params, calling this will bypass the auto parameter parsing. - * - * @param array $params Array of parameters for the dispatcher - * @return void - */ - public function setParams($params) { - $this->params = $params; - $this->_paramsParsed = true; - } - -/** - * Parse URL params into a 'request' - * - * @return void - */ - protected function _parseParams() { - if (!$this->_paramsParsed) { - if (!isset($_SERVER['SERVER_NAME'])) { - $_SERVER['SERVER_NAME'] = ''; - } - foreach ($this->params as $key => $value) { - if (isset($_GET[$key])) { - $this->params[$key] = $_GET[$key]; - } - } - if (isset($_GET['code_coverage'])) { - $this->params['codeCoverage'] = true; - $this->_checkXdebug(); - } - } - if (empty($this->params['plugin']) && empty($this->params['core'])) { - $this->params['app'] = true; - } - $this->params['baseUrl'] = $this->_baseUrl; - $this->params['baseDir'] = $this->_baseDir; - } - -/** - * Runs a test case file. - * - * @return void - */ - protected function _runTestCase() { - $commandArgs = array( - 'case' => $this->params['case'], - 'core' => $this->params['core'], - 'app' => $this->params['app'], - 'plugin' => $this->params['plugin'], - 'codeCoverage' => $this->params['codeCoverage'], - 'showPasses' => !empty($this->params['show_passes']), - 'baseUrl' => $this->_baseUrl, - 'baseDir' => $this->_baseDir, - ); - - $options = array( - '--filter', $this->params['filter'], - '--output', $this->params['output'], - '--fixture', $this->params['fixture'] - ); - restore_error_handler(); - - try { - static::time(); - $command = new TestSuiteCommand('Cake\TestSuite\TestLoader', $commandArgs); - $result = $command->run($options); - } catch (Error\MissingConnectionException $exception) { - ob_end_clean(); - $baseDir = $this->_baseDir; - include CAKE . 'TestSuite/templates/missing_connection.php'; - exit(); - } - } - -/** - * Sets a static timestamp - * - * @param boolean $reset to set new static timestamp. - * @return integer timestamp - */ - public static function time($reset = false) { - static $now; - if ($reset || !$now) { - $now = time(); - } - return $now; - } - -/** - * Returns formatted date string using static time - * This method is being used as formatter for created, modified and updated fields in Model::save() - * - * @param string $format format to be used. - * @return string formatted date - */ - public static function date($format) { - return date($format, static::time()); - } - -} diff --git a/src/TestSuite/templates/footer.php b/src/TestSuite/templates/footer.php deleted file mode 100644 index 817feffcc34..00000000000 --- a/src/TestSuite/templates/footer.php +++ /dev/null @@ -1,35 +0,0 @@ - - * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) - * - * Licensed under The MIT License - * For full copyright and license information, please see the LICENSE.txt - * Redistributions of files must retain the above copyright notice - * - * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) - * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests - * @since CakePHP(tm) v 1.2.0.4433 - * @license http://www.opensource.org/licenses/mit-license.php MIT License - */ -use Cake\View\View; - -?> - - - element('sql_dump'); - ?> - - - diff --git a/src/TestSuite/templates/header.php b/src/TestSuite/templates/header.php deleted file mode 100644 index d70028b7263..00000000000 --- a/src/TestSuite/templates/header.php +++ /dev/null @@ -1,147 +0,0 @@ - - * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) - * - * Licensed under The MIT License - * For full copyright and license information, please see the LICENSE.txt - * Redistributions of files must retain the above copyright notice - * - * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) - * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests - * @since CakePHP(tm) v 1.2.0.4433 - * @license http://www.opensource.org/licenses/mit-license.php MIT License - */ - -use Cake\Core\Configure; - -?> - - - - - CakePHP Test Suite <?= Configure::version(); ?> - - - - -
      - -
      -

      CakePHP Test Suite

      diff --git a/src/TestSuite/templates/menu.php b/src/TestSuite/templates/menu.php deleted file mode 100644 index 4db8d70a359..00000000000 --- a/src/TestSuite/templates/menu.php +++ /dev/null @@ -1,50 +0,0 @@ - - * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) - * - * Licensed under The MIT License - * For full copyright and license information, please see the LICENSE.txt - * Redistributions of files must retain the above copyright notice - * - * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) - * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests - * @since CakePHP(tm) v 1.2.0.4433 - * @license http://www.opensource.org/licenses/mit-license.php MIT License - */ -?> -
      -
        -
      • - App - -
      • - -
      • - Plugins - -
          -
        • - -
            -
          • Tests', $cases, $plugin); ?>
          • -
          -
        • -
        - -
      • - -
      • - Core - -
      • -
      -
      -
      diff --git a/src/TestSuite/templates/missing_connection.php b/src/TestSuite/templates/missing_connection.php deleted file mode 100644 index 32018916fe0..00000000000 --- a/src/TestSuite/templates/missing_connection.php +++ /dev/null @@ -1,25 +0,0 @@ - - * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) - * - * Licensed under The MIT License - * For full copyright and license information, please see the LICENSE.txt - * Redistributions of files must retain the above copyright notice - * - * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) - * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests - * @since CakePHP(tm) v 1.2.0.4433 - * @license http://www.opensource.org/licenses/mit-license.php MIT License - */ -?> - -
      -

      Missing Test Database Connection

      -

      getMessage(); ?>

      -
      getTraceAsString(); ?>
      -
      - - * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) - * - * Licensed under The MIT License - * For full copyright and license information, please see the LICENSE.txt - * Redistributions of files must retain the above copyright notice - * - * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) - * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests - * @since CakePHP(tm) v 1.2.0.4433 - * @license http://www.opensource.org/licenses/mit-license.php MIT License - */ -?> - -
      -

      PHPUnit is not installed!

      -

      You must install PHPUnit to use the CakePHP(tm) Test Suite.

      -

      PHPUnit can be installed with pear, using the pear installer.

      -

      To install with the PEAR installer run the following commands:

      -
        -
      • pear config-set auto_discover 1
      • -
      • pear install pear.phpunit.de/PHPUnit
      • -
      -

      Once PHPUnit is installed make sure its located on PHP's include_path by checking your php.ini

      -

      For full instructions on how to install PHPUnit, see the PHPUnit installation guide.

      -

      Download PHPUnit

      -
      - - * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) - * - * Licensed under The MIT License - * For full copyright and license information, please see the LICENSE.txt - * Redistributions of files must retain the above copyright notice - * - * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) - * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests - * @since CakePHP(tm) v 1.2.0.4433 - * @license http://www.opensource.org/licenses/mit-license.php MIT License - */ -?> - -
      -

      Xdebug is not installed

      -

      You must install Xdebug to use the CakePHP(tm) Code Coverage Analyzation.

      -

      Learn How To Install Xdebug

      -
      -_mapFileToCase($file, $category, $throwOnMissingFile); - } - - public function mapFileToCategory($file) { - return $this->_mapFileToCategory($file); - } - -} - -/** - * Class TestShellTest - * - */ -class TestShellTest extends TestCase { - -/** - * setUp test case - * - * @return void - */ - public function setUp() { - parent::setUp(); - $out = $this->getMock('Cake\Console\ConsoleOutput', array(), array(), '', false); - $in = $this->getMock('Cake\Console\ConsoleInput', array(), array(), '', false); - - $this->Shell = $this->getMock( - __NAMESPACE__ . '\TestTestShell', - array('in', 'out', 'hr', 'help', 'error', 'err', '_stop', 'initialize', '_run', 'clear'), - array($out, $out, $in) - ); - $this->Shell->OptionParser = $this->getMock('Cake\Console\ConsoleOptionParser', array(), array(null, false)); - } - -/** - * tearDown method - * - * @return void - */ - public function tearDown() { - parent::tearDown(); - unset($this->Dispatch, $this->Shell); - } - -/** - * testMapCoreFileToCategory - * - * @return void - */ - public function testMapCoreFileToCategory() { - $this->Shell->startup(); - - $return = $this->Shell->mapFileToCategory('Cake/basics.php'); - $this->assertSame('core', $return); - - $return = $this->Shell->mapFileToCategory('Cake/Core/App.php'); - $this->assertSame('core', $return); - - $return = $this->Shell->mapFileToCategory('Cake/Some/Deeply/Nested/Structure.php'); - $this->assertSame('app', $return); - } - -/** - * testMapCoreFileToCase - * - * basics.php is a slightly special case - it's the only file in the core with a test that isn't Capitalized - * - * @return void - */ - public function testMapCoreFileToCase() { - $this->Shell->startup(); - - $return = $this->Shell->mapFileToCase('lib/Cake/basics.php', 'core'); - $this->assertSame('Basics', $return); - - $return = $this->Shell->mapFileToCase('lib/Cake/Core/App.php', 'core'); - $this->assertSame('Core/App', $return); - - $return = $this->Shell->mapFileToCase('lib/Cake/Some/Deeply/Nested/Structure.php', 'core', false); - $this->assertSame('Some/Deeply/Nested/Structure', $return); - } - -/** - * testMapAppFileToCategory - * - * @return void - */ - public function testMapAppFileToCategory() { - $this->Shell->startup(); - - $return = $this->Shell->mapFileToCategory(APP . 'Controller/ExampleController.php'); - $this->assertSame('app', $return); - - $return = $this->Shell->mapFileToCategory(APP . 'My/File/Is/Here.php'); - $this->assertSame('app', $return); - } - -/** - * testMapAppFileToCase - * - * @return void - */ - public function testMapAppFileToCase() { - $this->Shell->startup(); - - $return = $this->Shell->mapFileToCase(APP . 'Controller/ExampleController.php', 'app', false); - $this->assertSame('Controller/ExampleController', $return); - - $return = $this->Shell->mapFileToCase(APP . 'My/File/Is/Here.php', 'app', false); - $this->assertSame('My/File/Is/Here', $return); - } - -/** - * testMapPluginFileToCategory - * - * @return void - */ - public function testMapPluginFileToCategory() { - $this->Shell->startup(); - - $return = $this->Shell->mapFileToCategory(APP . 'Plugin/awesome/Controller/ExampleController.php'); - $this->assertSame('awesome', $return); - - $return = $this->Shell->mapFileToCategory(dirname(CAKE) . 'plugins/awesome/Controller/ExampleController.php'); - $this->assertSame('awesome', $return); - } - -/** - * testMapPluginFileToCase - * - * @return void - */ - public function testMapPluginFileToCase() { - $this->Shell->startup(); - - $return = $this->Shell->mapFileToCase(APP . 'Plugin/awesome/Controller/ExampleController.php', 'awesome', false); - $this->assertSame('Controller/ExampleController', $return); - - $return = $this->Shell->mapFileToCase(dirname(CAKE) . 'plugins/awesome/Controller/ExampleController.php', 'awesome', false); - $this->assertSame('Controller/ExampleController', $return); - } - -/** - * testMapCoreTestToCategory - * - * @return void - */ - public function testMapCoreTestToCategory() { - $this->Shell->startup(); - - $return = $this->Shell->mapFileToCategory('Test/TestCase/BasicsTest.php'); - $this->assertSame('core', $return); - - $return = $this->Shell->mapFileToCategory('Test/TestCase/BasicsTest.php'); - $this->assertSame('core', $return); - - $return = $this->Shell->mapFileToCategory('Test/TestCase/Some/Deeply/Nested/StructureTest.php'); - $this->assertSame('app', $return); - } - -/** - * testMapCoreTestToCase - * - * basics.php is a slightly special case - it's the only file in the core with a test that isn't Capitalized - * - * @return void - */ - public function testMapCoreTestToCase() { - $this->Shell->startup(); - - $return = $this->Shell->mapFileToCase('lib/Cake/Test/TestCase/BasicsTest.php', 'core'); - $this->assertSame('Basics', $return); - - $return = $this->Shell->mapFileToCase('lib/Cake/Test/TestCase/Core/AppTest.php', 'core'); - $this->assertSame('Core/App', $return); - - $return = $this->Shell->mapFileToCase('lib/Cake/Test/TestCase/Some/Deeply/Nested/StructureTest.php', 'core', false); - $this->assertSame('Some/Deeply/Nested/Structure', $return); - } - -/** - * testMapAppTestToCategory - * - * @return void - */ - public function testMapAppTestToCategory() { - $this->Shell->startup(); - - $return = $this->Shell->mapFileToCategory(APP . 'Test/TestCase/Controller/ExampleControllerTest.php'); - $this->assertSame('app', $return); - - $return = $this->Shell->mapFileToCategory(APP . 'Test/TestCase/My/File/Is/HereTest.php'); - $this->assertSame('app', $return); - } - -/** - * testMapAppTestToCase - * - * @return void - */ - public function testMapAppTestToCase() { - $this->Shell->startup(); - - $return = $this->Shell->mapFileToCase(APP . 'Test/TestCase/Controller/ExampleControllerTest.php', 'app', false); - $this->assertSame('Controller/ExampleController', $return); - - $return = $this->Shell->mapFileToCase(APP . 'Test/TestCase/My/File/Is/HereTest.php', 'app', false); - $this->assertSame('My/File/Is/Here', $return); - } - -/** - * testMapPluginTestToCategory - * - * @return void - */ - public function testMapPluginTestToCategory() { - $this->Shell->startup(); - - $return = $this->Shell->mapFileToCategory(APP . 'Plugin/awesome/Test/TestCase/Controller/ExampleControllerTest.php'); - $this->assertSame('awesome', $return); - - $return = $this->Shell->mapFileToCategory(dirname(CAKE) . 'plugins/awesome/Test/TestCase/Controller/ExampleControllerTest.php'); - $this->assertSame('awesome', $return); - } - -/** - * testMapPluginTestToCase - * - * @return void - */ - public function testMapPluginTestToCase() { - $this->Shell->startup(); - - $return = $this->Shell->mapFileToCase(APP . 'Plugin/awesome/Test/TestCase/Controller/ExampleControllerTest.php', 'awesome', false); - $this->assertSame('Controller/ExampleController', $return); - - $return = $this->Shell->mapFileToCase(dirname(CAKE) . 'plugins/awesome/Test/TestCase/Controller/ExampleControllerTest.php', 'awesome', false); - $this->assertSame('Controller/ExampleController', $return); - } - -/** - * testMapNotTestToNothing - * - * @return void - */ - public function testMapNotTestToNothing() { - $this->Shell->startup(); - - $return = $this->Shell->mapFileToCategory(APP . 'Test/TestCase/NotATestFile.php'); - $this->assertSame('app', $return); - - $return = $this->Shell->mapFileToCase(APP . 'Test/TestCase/NotATestFile.php', false, false); - $this->assertFalse($return); - - $return = $this->Shell->mapFileToCategory(APP . 'Test/Fixture/SomeTest.php'); - $this->assertSame('app', $return); - - $return = $this->Shell->mapFileToCase(APP . 'Test/Fixture/SomeTest.php', false, false); - $this->assertFalse($return); - } - -/** - * test available list of test cases for an empty category - * - * @return void - */ - public function testAvailableWithEmptyList() { - $this->Shell->startup(); - $this->Shell->args = array('unexistant-category'); - $this->Shell->expects($this->at(0))->method('out')->with(__d('cake_console', "No test cases available \n\n")); - $this->Shell->OptionParser->expects($this->once())->method('help'); - $this->Shell->available(); - } - -/** - * test available list of test cases for core category - * - * @return void - */ - public function testAvailableCoreCategory() { - $this->Shell->startup(); - $this->Shell->args = array('core'); - $this->Shell->expects($this->at(0))->method('out')->with('Core Test Cases:'); - $this->Shell->expects($this->at(1))->method('out') - ->with($this->stringContains('[1]')); - $this->Shell->expects($this->at(2))->method('out') - ->with($this->stringContains('[2]')); - - $this->Shell->expects($this->once())->method('in') - ->with(__d('cake_console', 'What test case would you like to run?'), null, 'q') - ->will($this->returnValue('1')); - - $this->Shell->expects($this->once())->method('_run'); - $this->Shell->available(); - $this->assertEquals(array('core', 'Basics'), $this->Shell->args); - } - -/** - * Tests that correct option for test runner are passed - * - * @return void - */ - public function testRunnerOptions() { - $this->Shell->startup(); - $this->Shell->args = array('core', 'Basics'); - $this->Shell->params = array('filter' => 'myFilter', 'colors' => true, 'verbose' => true); - - $this->Shell->expects($this->once())->method('_run') - ->with( - array('app' => false, 'plugin' => null, 'core' => true, 'output' => 'text', 'case' => 'Basics'), - array('--filter', 'myFilter', '--colors', '--verbose') - ); - $this->Shell->main(); - } -} diff --git a/tests/TestCase/TestSuite/HtmlCoverageReportTest.php b/tests/TestCase/TestSuite/HtmlCoverageReportTest.php deleted file mode 100644 index 9a64c5e8b61..00000000000 --- a/tests/TestCase/TestSuite/HtmlCoverageReportTest.php +++ /dev/null @@ -1,234 +0,0 @@ -params = array('app' => false, 'plugin' => false, 'group' => false); - $coverage = array(); - $this->Coverage = new HtmlCoverageReport($coverage, $reporter); - } - -/** - * test getting the path filters. - * - * @return void - */ - public function testGetPathFilter() { - $this->Coverage->appTest = false; - $result = $this->Coverage->getPathFilter(); - $this->assertEquals(CAKE, $result); - - $this->Coverage->appTest = true; - $result = $this->Coverage->getPathFilter(); - $this->assertEquals(ROOT . DS . APP_DIR . DS, $result); - - $this->Coverage->appTest = false; - $this->Coverage->pluginTest = 'TestPlugin'; - $result = $this->Coverage->getPathFilter(); - $this->assertEquals(Plugin::path('TestPlugin'), $result); - } - -/** - * test filtering coverage data. - * - * @return void - */ - public function testFilterCoverageDataByPathRemovingElements() { - $data = array( - CAKE . 'Dispatcher.php' => array( - 10 => -1, - 12 => 1 - ), - APP . 'AppModel.php' => array( - 50 => 1, - 52 => -1 - ) - ); - $this->Coverage->setCoverage($data); - $result = $this->Coverage->filterCoverageDataByPath(APP); - $this->assertArrayNotHasKey(CAKE . 'Dispatcher.php', $result); - $this->assertArrayHasKey(APP . 'AppModel.php', $result); - } - -/** - * test generating HTML reports from file arrays. - * - * @return void - */ - public function testGenerateDiff() { - $file = array( - 'line 1', - 'line 2', - 'line 3', - 'line 4', - 'line 5', - 'line 6', - 'line 7', - 'line 8', - 'line 9', - 'line 10', - ); - $coverage = array( - 1 => array(array('id' => __NAMESPACE__ . '\HtmlCoverageReportTest::testGenerateDiff')), - 2 => -2, - 3 => array(array('id' => __NAMESPACE__ . '\HtmlCoverageReportTest::testGenerateDiff')), - 4 => array(array('id' => __NAMESPACE__ . '\HtmlCoverageReportTest::testGenerateDiff')), - 5 => -1, - 6 => array(array('id' => __NAMESPACE__ . '\HtmlCoverageReportTest::testGenerateDiff')), - 7 => array(array('id' => __NAMESPACE__ . '\HtmlCoverageReportTest::testGenerateDiff')), - 8 => array(array('id' => __NAMESPACE__ . '\HtmlCoverageReportTest::testGenerateDiff')), - 9 => -1, - 10 => array(array('id' => __NAMESPACE__ . '\HtmlCoverageReportTest::testGenerateDiff')) - ); - $result = $this->Coverage->generateDiff('myfile.php', $file, $coverage); - $this->assertRegExp('/myfile\.php Code coverage\: \d+\.?\d*\%/', $result); - $this->assertRegExp('/
      assertRegExp('/
      /', $result);
      -		foreach ($file as $i => $line) {
      -			$this->assertTrue(strpos($line, $result) !== 0, 'Content is missing ' . $i);
      -			$class = 'covered';
      -			if (in_array($i + 1, array(5, 9, 2))) {
      -				$class = 'uncovered';
      -			}
      -			if ($i + 1 == 2) {
      -				$class .= ' dead';
      -			}
      -			$this->assertTrue(strpos($class, $result) !== 0, 'Class name is wrong ' . $i);
      -		}
      -	}
      -
      -/**
      - * Test that coverage works with phpunit 3.6 as the data formats from coverage are totally different.
      - *
      - * @return void
      - */
      -	public function testPhpunit36Compatibility() {
      -		$file = array(
      -			'line 1',
      -			'line 2',
      -			'line 3',
      -			'line 4',
      -			'line 5',
      -			'line 6',
      -			'line 7',
      -			'line 8',
      -			'line 9',
      -			'line 10',
      -		);
      -		$coverage = array(
      -			1 => array(__NAMESPACE__ . '\HtmlCoverageReportTest::testGenerateDiff'),
      -			2 => null,
      -			3 => array(__NAMESPACE__ . '\HtmlCoverageReportTest::testGenerateDiff'),
      -			4 => array(__NAMESPACE__ . '\HtmlCoverageReportTest::testGenerateDiff'),
      -			5 => array(),
      -			6 => array(__NAMESPACE__ . '\HtmlCoverageReportTest::testGenerateDiff'),
      -			7 => array(__NAMESPACE__ . '\HtmlCoverageReportTest::testGenerateDiff'),
      -			8 => array(__NAMESPACE__ . '\HtmlCoverageReportTest::testGenerateDiff'),
      -			9 => array(),
      -			10 => array(__NAMESPACE__ . '\HtmlCoverageReportTest::testSomething', __NAMESPACE__ . '\HtmlCoverageReportTest::testGenerateDiff')
      -		);
      -
      -		$result = $this->Coverage->generateDiff('myfile.php', $file, $coverage);
      -		$this->assertRegExp('/myfile\.php Code coverage\: \d+\.?\d*\%/', $result);
      -		$this->assertRegExp('/
      assertRegExp('/
      /', $result);
      -		foreach ($file as $i => $line) {
      -			$this->assertTrue(strpos($line, $result) !== 0, 'Content is missing ' . $i);
      -			$class = 'covered';
      -			if (in_array($i + 1, array(5, 9, 2))) {
      -				$class = 'uncovered';
      -			}
      -			if ($i + 1 == 2) {
      -				$class .= ' dead';
      -			}
      -			$this->assertTrue(strpos($class, $result) !== 0, 'Class name is wrong ' . $i);
      -		}
      -	}
      -
      -/**
      - * test that covering methods show up as title attributes for lines.
      - *
      - * @return void
      - */
      -	public function testCoveredLinesTitleAttributes() {
      -		$file = array(
      -			'line 1',
      -			'line 2',
      -			'line 3',
      -			'line 4',
      -			'line 5',
      -		);
      -
      -		$coverage = array(
      -			1 => array(array('id' => __NAMESPACE__ . '\HtmlCoverageReportTest::testAwesomeness')),
      -			2 => -2,
      -			3 => array(array('id' => __NAMESPACE__ . '\HtmlCoverageReportTest::testCakeIsSuperior')),
      -			4 => array(array('id' => __NAMESPACE__ . '\HtmlCoverageReportTest::testOther')),
      -			5 => -1
      -		);
      -
      -		$result = $this->Coverage->generateDiff('myfile.php', $file, $coverage);
      -
      -		$this->assertTrue(
      -			strpos($result, "title=\"Covered by:\n" . __NAMESPACE__ . "\HtmlCoverageReportTest::testAwesomeness\n\">1") !== false,
      -			'Missing method coverage for line 1'
      -		);
      -		$this->assertTrue(
      -			strpos($result, "title=\"Covered by:\n" . __NAMESPACE__ . "\HtmlCoverageReportTest::testCakeIsSuperior\n\">3") !== false,
      -			'Missing method coverage for line 3'
      -		);
      -		$this->assertTrue(
      -			strpos($result, "title=\"Covered by:\n" . __NAMESPACE__ . "\HtmlCoverageReportTest::testOther\n\">4") !== false,
      -			'Missing method coverage for line 4'
      -		);
      -		$this->assertTrue(
      -			strpos($result, "title=\"\">5") !== false,
      -			'Coverage report is wrong for line 5'
      -		);
      -	}
      -
      -/**
      - * tearDown
      - *
      - * @return void
      - */
      -	public function tearDown() {
      -		Plugin::unload();
      -		unset($this->Coverage);
      -		parent::tearDown();
      -	}
      -}