Renaming CodeCoverageManager::start() to init().

Adding a start(), stop(), and clear() methods to CodeCoverageManager.
Making CakeBaseReporter toggle code coverage on and off as needed.
Updating test case for CodeCoverageManager.
This commit is contained in:
Mark Story 2010-01-10 13:23:37 -05:00
parent b83f3d37c8
commit da26124add
2 changed files with 41 additions and 9 deletions

View file

@ -66,11 +66,11 @@ class CodeCoverageManagerTest extends CakeTestCase {
if (PHP_SAPI != 'cli') {
$reporter =& new CakeHtmlReporter(null, array('group' => false, 'app' => false, 'plugin' => false));
CodeCoverageManager::start(substr(md5(microtime()), 0, 5), $reporter);
CodeCoverageManager::init(substr(md5(microtime()), 0, 5), $reporter);
CodeCoverageManager::report(false);
$this->assertError();
CodeCoverageManager::start('tests' . DS . 'lib' . DS . basename(__FILE__), $reporter);
CodeCoverageManager::init('tests' . DS . 'lib' . DS . basename(__FILE__), $reporter);
CodeCoverageManager::report(false);
$this->assertError();
@ -96,7 +96,7 @@ class CodeCoverageManagerTest extends CakeTestCase {
$contents[1] = array_filter($contents[1], "remove");
foreach ($contents[1] as $file) {
CodeCoverageManager::start('libs'.DS.$file, $reporter);
CodeCoverageManager::init('libs'.DS.$file, $reporter);
CodeCoverageManager::report(false);
$this->assertNoErrors('libs'.DS.$file);
}

View file

@ -87,15 +87,14 @@ class CodeCoverageManager {
}
/**
* Starts a new Coverage Analyzation for a given test case file
* @TODO: Works with $_GET now within the function body, which will make it hard when we do code coverage reports for CLI
* Initializes a new Coverage Analyzation for a given test case file
*
* @param string $testCaseFile
* @param string $reporter
* @param string $testCaseFile The test case file being covered.
* @param object $reporter Instance of the reporter running.
* @return void
* @static
*/
function start($testCaseFile, &$reporter) {
function init($testCaseFile, &$reporter) {
$manager =& CodeCoverageManager::getInstance();
$manager->reporter =& $reporter;
$testCaseFile = str_replace(DS . DS, DS, $testCaseFile);
@ -106,9 +105,41 @@ class CodeCoverageManager {
}
$manager->setParams($reporter);
$manager->testCaseFile = $testCaseFile;
CodeCoverageManager::start();
}
/**
* Start/resume Code coverage collection.
*
* @return void
* @static
*/
function start() {
xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
}
/**
* Stops/pauses code coverage collection. Does not clean the
* code coverage memory. Use clean() to clear code coverage memory
*
* @return void
* @static
*/
function stop() {
xdebug_stop_code_coverage(false);
}
/**
* Clears the existing code coverage information. Also stops any
* running collection.
*
* @return void
* @static
*/
function clear() {
xdebug_stop_code_coverage();
}
/**
* Set the parameters from a reporter to the CodeCoverageManager
*
@ -137,6 +168,8 @@ class CodeCoverageManager {
function report($output = true) {
$manager =& CodeCoverageManager::getInstance();
CodeCoverageManager::stop();
if (!$manager->groupTest) {
$testObjectFile = $manager->__testObjectFileFromCaseFile($manager->testCaseFile, $manager->appTest);
@ -145,7 +178,6 @@ class CodeCoverageManager {
return ;
}
$dump = xdebug_get_code_coverage();
xdebug_stop_code_coverage();
$coverageData = array();
foreach ($dump as $file => $data) {