Skip to content

Commit

Permalink
Renaming CodeCoverageManager::start() to init().
Browse files Browse the repository at this point in the history
Adding a start(), stop(), and clear() methods to CodeCoverageManager.
Making CakeBaseReporter toggle code coverage on and off as needed.
Updating test case for CodeCoverageManager.
  • Loading branch information
markstory committed Jan 10, 2010
1 parent b83f3d3 commit da26124
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 9 deletions.
6 changes: 3 additions & 3 deletions cake/tests/cases/libs/code_coverage_manager.test.php
Expand Up @@ -66,11 +66,11 @@ function testNoTestCaseSupplied() {
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();

Expand All @@ -96,7 +96,7 @@ function remove($var) {
$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);
}
Expand Down
44 changes: 38 additions & 6 deletions cake/tests/lib/code_coverage_manager.php
Expand Up @@ -87,15 +87,14 @@ function &getInstance() {
}

/**
* 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);
Expand All @@ -106,9 +105,41 @@ function start($testCaseFile, &$reporter) {
}
$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
*
Expand Down Expand Up @@ -137,6 +168,8 @@ function setParams(&$reporter) {
function report($output = true) {
$manager =& CodeCoverageManager::getInstance();

CodeCoverageManager::stop();

if (!$manager->groupTest) {
$testObjectFile = $manager->__testObjectFileFromCaseFile($manager->testCaseFile, $manager->appTest);

Expand All @@ -145,7 +178,6 @@ function report($output = true) {
return ;
}
$dump = xdebug_get_code_coverage();
xdebug_stop_code_coverage();
$coverageData = array();

foreach ($dump as $file => $data) {
Expand Down

0 comments on commit da26124

Please sign in to comment.