Skip to content

Commit

Permalink
Adding the CakePHP testing classes to the coverage ignore filter for …
Browse files Browse the repository at this point in the history
…PHPUnit. Starting to refactor how coverage is generated, to use more features of PHPUnit.
  • Loading branch information
markstory committed May 8, 2010
1 parent 9333782 commit 507c3b2
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 9 deletions.
2 changes: 2 additions & 0 deletions cake/tests/lib/cake_fixture_manager.php
@@ -1,5 +1,7 @@
<?php

PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'DEFAULT');

class CakeFixtureManager {
protected static $_initialized = false;
protected static $_db;
Expand Down
2 changes: 2 additions & 0 deletions cake/tests/lib/cake_test_case.php
Expand Up @@ -18,6 +18,8 @@
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/

PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'DEFAULT');

require_once CAKE_TESTS_LIB . 'cake_fixture_manager.php';
require_once CAKE_TESTS_LIB . 'cake_test_model.php';
require_once CAKE_TESTS_LIB . 'cake_test_fixture.php';
Expand Down
2 changes: 2 additions & 0 deletions cake/tests/lib/cake_test_fixture.php
Expand Up @@ -18,6 +18,8 @@
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/

PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'DEFAULT');

/**
* Short description for class.
*
Expand Down
8 changes: 5 additions & 3 deletions cake/tests/lib/cake_test_suite_dispatcher.php
Expand Up @@ -138,6 +138,8 @@ function _checkPHPUnit() {
include CAKE_TESTS_LIB . 'templates/simpletest.php';
exit();
}

PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'DEFAULT');
}

/**
Expand Down Expand Up @@ -233,8 +235,8 @@ function _parseParams() {
}
if (isset($_GET['code_coverage'])) {
$this->params['codeCoverage'] = true;
require_once CAKE_TESTS_LIB . 'code_coverage_manager.php';
$this->_checkXdebug();
require_once CAKE_TESTS_LIB . 'code_coverage_manager.php';
}
$this->params['baseUrl'] = $this->_baseUrl;
$this->params['baseDir'] = $this->_baseDir;
Expand All @@ -254,7 +256,7 @@ function _runGroupTest() {
if ('all' == $this->params['group']) {
$this->Manager->runAllTests($Reporter);
} else {
$this->Manager->runGroupTest(ucfirst($this->params['group']), $Reporter);
$this->Manager->runGroupTest(ucfirst($this->params['group']), $Reporter, $this->params['codeCoverage']);
}
}

Expand All @@ -268,7 +270,7 @@ function _runTestCase() {
if ($this->params['codeCoverage']) {
CodeCoverageManager::init($this->params['case'], $Reporter);
}
$this->Manager->runTestCase($this->params['case'], $Reporter);
$this->Manager->runTestCase($this->params['case'], $Reporter, $this->params['codeCoverage']);
}
}
?>
2 changes: 2 additions & 0 deletions cake/tests/lib/reporter/cake_base_reporter.php
Expand Up @@ -18,6 +18,8 @@
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/

PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'DEFAULT');

/**
* CakeBaseReporter contains common reporting features used in the CakePHP Test suite
*
Expand Down
4 changes: 3 additions & 1 deletion cake/tests/lib/reporter/cake_html_reporter.php
Expand Up @@ -19,6 +19,8 @@
*/
include_once dirname(__FILE__) . DS . 'cake_base_reporter.php';

PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'DEFAULT');

/**
* CakeHtmlReporter Reports Results of TestSuites and Test Cases
* in an HTML format / context.
Expand Down Expand Up @@ -178,7 +180,7 @@ public function paintFooter($result) {
$this->params['codeCoverage'] &&
class_exists('CodeCoverageManager')
) {
CodeCoverageManager::report();
//CodeCoverageManager::report();
}
$this->paintDocumentEnd();
}
Expand Down
16 changes: 11 additions & 5 deletions cake/tests/lib/test_manager.php
Expand Up @@ -22,6 +22,8 @@
define('APP_TEST_CASES', TESTS . 'cases');
define('APP_TEST_GROUPS', TESTS . 'groups');

PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'DEFAULT');

/**
* TestManager is the base class that handles loading and initiating the running
* of TestCase and TestSuite classes that the user has selected.
Expand Down Expand Up @@ -113,7 +115,7 @@ public function runAllTests(&$reporter) {
* @throws InvalidArgumentException if the supplied $testCaseFile does not exists
* @return mixed Result of test case being run.
*/
public function runTestCase($testCaseFile, PHPUnit_Framework_TestListener $reporter) {
public function runTestCase($testCaseFile, PHPUnit_Framework_TestListener $reporter, $codeCoverage = false) {
$testCaseFileWithPath = $this->_getTestsPath() . DS . $testCaseFile;

if (!file_exists($testCaseFileWithPath)) {
Expand All @@ -122,7 +124,7 @@ public function runTestCase($testCaseFile, PHPUnit_Framework_TestListener $repor

$testSuite = $this->getTestSuite(sprintf(__('Individual test case: %s', true), $testCaseFile));
$testSuite->addTestFile($testCaseFileWithPath);
return $this->run($reporter);
return $this->run($reporter, $codeCoverage);
}

/**
Expand All @@ -133,7 +135,7 @@ public function runTestCase($testCaseFile, PHPUnit_Framework_TestListener $repor
* @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) {
public function runGroupTest($groupTestName, $reporter, $codeCoverage = false) {
$filePath = $this->_getTestsPath('groups') . DS . strtolower($groupTestName) . $this->getExtension('group');

if (!file_exists($filePath)) {
Expand All @@ -149,7 +151,7 @@ public function runGroupTest($groupTestName, $reporter) {
$suite->setName($group->label);
}

return $this->run($reporter);
return $this->run($reporter, $codeCoverage);
}

/**
Expand All @@ -158,12 +160,16 @@ public function runGroupTest($groupTestName, $reporter) {
* @param PHPUnit_Framework_TestListener $reporter Reporter instance to use with the group test being run.
* @return mixed Results of group test being run.
*/
protected function run($reporter) {
protected function run($reporter, $codeCoverage = false) {
$result = new PHPUnit_Framework_TestResult;
$result->collectCodeCoverageInformation($codeCoverage);
$result->addListener($reporter);
$reporter->paintHeader();
$this->getTestSuite()->run($result);
$reporter->paintResult($result);
// echo '<pre>';
// var_dump($result->getCodeCoverageInformation());
// echo '</pre>';
return $result;
}

Expand Down

0 comments on commit 507c3b2

Please sign in to comment.