Adding the CakePHP testing classes to the coverage ignore filter for PHPUnit. Starting to refactor how coverage is generated, to use more features of PHPUnit.

This commit is contained in:
Mark Story 2010-05-08 16:18:45 -04:00
parent 933378223b
commit 507c3b2d94
7 changed files with 27 additions and 9 deletions

View file

@ -1,5 +1,7 @@
<?php
PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'DEFAULT');
class CakeFixtureManager {
protected static $_initialized = false;
protected static $_db;

View file

@ -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';

View file

@ -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.
*

View file

@ -138,6 +138,8 @@ class CakeTestSuiteDispatcher {
include CAKE_TESTS_LIB . 'templates/simpletest.php';
exit();
}
PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'DEFAULT');
}
/**
@ -233,8 +235,8 @@ class CakeTestSuiteDispatcher {
}
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;
@ -254,7 +256,7 @@ class CakeTestSuiteDispatcher {
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']);
}
}
@ -268,7 +270,7 @@ class CakeTestSuiteDispatcher {
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']);
}
}
?>

View file

@ -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
*

View file

@ -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.
@ -178,7 +180,7 @@ class CakeHtmlReporter extends CakeBaseReporter implements PHPUnit_Framework_Tes
$this->params['codeCoverage'] &&
class_exists('CodeCoverageManager')
) {
CodeCoverageManager::report();
//CodeCoverageManager::report();
}
$this->paintDocumentEnd();
}

View file

@ -22,6 +22,8 @@ define('CORE_TEST_GROUPS', TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'groups'
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.
@ -113,7 +115,7 @@ class TestManager {
* @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)) {
@ -122,7 +124,7 @@ class TestManager {
$testSuite = $this->getTestSuite(sprintf(__('Individual test case: %s', true), $testCaseFile));
$testSuite->addTestFile($testCaseFileWithPath);
return $this->run($reporter);
return $this->run($reporter, $codeCoverage);
}
/**
@ -133,7 +135,7 @@ class TestManager {
* @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)) {
@ -149,7 +151,7 @@ class TestManager {
$suite->setName($group->label);
}
return $this->run($reporter);
return $this->run($reporter, $codeCoverage);
}
/**
@ -158,12 +160,16 @@ class TestManager {
* @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;
}