Skip to content

Commit

Permalink
Merge [808].
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jul 19, 2007
1 parent 7fc0877 commit c5a7850
Show file tree
Hide file tree
Showing 8 changed files with 368 additions and 33 deletions.
7 changes: 7 additions & 0 deletions PHPUnit/TextUI/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ protected static function handleArguments()
}

if (extension_loaded('xdebug')) {
$longOptions[] = 'coverage-xml=';
$longOptions[] = 'report=';
}

Expand Down Expand Up @@ -193,6 +194,11 @@ protected static function handleArguments()

foreach ($options[0] as $option) {
switch ($option[0]) {
case '--coverage-xml': {
$arguments['coverageXML'] = $option[1];
}
break;

case 'd': {
$ini = explode('=', $option[1]);

Expand Down Expand Up @@ -425,6 +431,7 @@ public static function showHelp()
" --log-xml <file> Log test execution in XML format to file.\n\n";

if (extension_loaded('xdebug')) {
print " --coverage-xml <file> Write code coverage information in XML format.\n";
print " --report <dir> Generate combined test/coverage report in HTML format.\n\n";
}

Expand Down
20 changes: 18 additions & 2 deletions PHPUnit/TextUI/TestRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@
require_once 'PHPUnit/Runner/Version.php';
require_once 'PHPUnit/TextUI/ResultPrinter.php';
require_once 'PHPUnit/Util/TestDox/ResultPrinter.php';
require_once 'PHPUnit/Util/Database.php';
require_once 'PHPUnit/Util/PDO.php';
require_once 'PHPUnit/Util/Filter.php';
require_once 'PHPUnit/Util/Report.php';
require_once 'PHPUnit/Util/Report/GraphViz.php';
require_once 'PHPUnit/Util/Timer.php';
require_once 'PHPUnit/Util/Log/CodeCoverage/Database.php';
require_once 'PHPUnit/Util/Log/CodeCoverage/XML.php';
require_once 'PHPUnit/Util/Log/Database.php';
require_once 'PHPUnit/Util/Log/GraphViz.php';
require_once 'PHPUnit/Util/Log/JSON.php';
Expand Down Expand Up @@ -228,6 +229,10 @@ public function doRun(PHPUnit_Framework_Test $suite, array $parameters = array()
}
}

if (isset($parameters['coverageXML']) && extension_loaded('xdebug')) {
$result->collectCodeCoverageInformation(TRUE);
}

if (isset($parameters['reportDirectory']) &&
extension_loaded('xdebug')) {
if (class_exists('Image_GraphViz', FALSE)) {
Expand Down Expand Up @@ -298,10 +303,21 @@ public function doRun(PHPUnit_Framework_Test $suite, array $parameters = array()
$this->printer->printResult($result);
}

if (isset($parameters['coverageXML']) && extension_loaded('xdebug')) {
$this->printer->write("\nWriting code coverage data to XML file, this may take a moment.");

$writer = new PHPUnit_Util_Log_CodeCoverage_XML(
$parameters['coverageXML']
);

$writer->process($result);
$this->printer->write("\n");
}

if ($writeToTestDatabase && extension_loaded('xdebug')) {
$this->printer->write("\nStoring code coverage data in database, this may take a moment.");

$testDb = new PHPUnit_Util_Database($dbh);
$testDb = new PHPUnit_Util_Log_CodeCoverage_Database($dbh);
$testDb->storeCodeCoverage(
$result, $parameters['testDatabaseLogRevision']
);
Expand Down
44 changes: 23 additions & 21 deletions PHPUnit/Util/CodeCoverage.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
abstract class PHPUnit_Util_CodeCoverage
{
protected static $lineToTestMap = array();
protected static $summary = array();

/**
* Returns the names of the covered files.
Expand Down Expand Up @@ -140,41 +141,42 @@ public static function getCoveringTests(array &$data, $file, $line, $clear = FAL
* </code>
*
* @param array $data
* @param boolean $clear
* @return array
* @access public
* @static
*/
public static function getSummary(array &$data)
public static function getSummary(array &$data, $clear = FALSE)
{
$summary = array();
if (empty(self::$summary) || $clear) {
foreach ($data as $test) {
foreach ($test['files'] as $file => $lines) {
if (!self::isFile($file)) {
continue;
}

foreach ($data as $test) {
foreach ($test['files'] as $file => $lines) {
if (!self::isFile($file)) {
continue;
}
foreach ($lines as $line => $flag) {
// +1: Line is executable and was executed.
if ($flag == 1) {
if (!isset(self::$summary[$file][$line]) ||
!is_array(self::$summary[$file][$line])) {
self::$summary[$file][$line] = array();
}

foreach ($lines as $line => $flag) {
// +1: Line is executable and was executed.
if ($flag == 1) {
if (!isset($summary[$file][$line]) ||
!is_array($summary[$file][$line])) {
$summary[$file][$line] = array();
self::$summary[$file][$line][] = $test['test'];
}

$summary[$file][$line][] = $test['test'];
}

// -1: Line is executable and was not executed.
// -2: Line is dead code.
else if (!(isset($summary[$file][$line]) && is_array($summary[$file][$line]))) {
$summary[$file][$line] = $flag;
// -1: Line is executable and was not executed.
// -2: Line is dead code.
else if (!(isset(self::$summary[$file][$line]) && is_array(self::$summary[$file][$line]))) {
self::$summary[$file][$line] = $flag;
}
}
}
}
}

return $summary;
return self::$summary;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version SVN: $Id$
* @link http://www.phpunit.de/
* @since File available since Release 3.1.0
* @since File available since Release 3.1.4
*/

require_once 'PHPUnit/Framework.php';
Expand All @@ -62,9 +62,9 @@
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 3.1.0
* @since Class available since Release 3.1.4
*/
class PHPUnit_Util_Database
class PHPUnit_Util_Log_CodeCoverage_Database
{
/**
* @var PDO
Expand Down
Loading

0 comments on commit c5a7850

Please sign in to comment.