Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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.
  • Loading branch information...
commit da26124add3ef94e6f232b9d8a310e68a357b2fc 1 parent b83f3d3
@markstory markstory authored
View
6 cake/tests/cases/libs/code_coverage_manager.test.php
@@ -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();
@@ -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);
}
View
44 cake/tests/lib/code_coverage_manager.php
@@ -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);
@@ -106,10 +105,42 @@ 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
*
* @return void
@@ -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);
@@ -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) {
Please sign in to comment.
Something went wrong with that request. Please try again.