Skip to content

Commit

Permalink
Tester: added option --coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Mar 8, 2014
1 parent cb2a7b1 commit f5a0994
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
7 changes: 7 additions & 0 deletions Tester/Framework/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class Environment
/** Test is runned by Runner */
const RUNNER = 'NETTE_TESTER_RUNNER';

/** Code coverage file */
const COVERAGE = 'NETTE_TESTER_COVERAGE';


/** @var bool used for debugging Tester itself */
public static $debugMode = TRUE;
Expand Down Expand Up @@ -68,6 +71,10 @@ class_exists('Tester\Assert');
}
});

if (getenv(self::COVERAGE)) {
CodeCoverage\Collector::start(getenv(self::COVERAGE));
}

ob_start(function($s) {
return Environment::$useColors ? $s : Dumper::removeColors($s);
}, PHP_VERSION_ID < 50400 ? 2 : 1);
Expand Down
14 changes: 12 additions & 2 deletions Tester/tester.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
-i | --info Show tests environment info and exit.
--setup <path> Script for runner setup.
--colors [1|0] Enable or disable colors.
--coverage <path> Generate code coverage report to file.
-h | --help This help.
XX
Expand Down Expand Up @@ -103,6 +104,17 @@
exit;
}

if ($options['--coverage']) {
if (!$php->hasXdebug()) {

This comment has been minimized.

Copy link
@JanTvrdik

JanTvrdik Oct 1, 2015

Contributor

This checks whether the interpreter running tester.php has xdebug. Jobs may use different interpreter entirely.

throw new Exception("Code coverage functionality requires Xdebug extension (used {$php->getCommandLine()})");
}
file_put_contents($options['--coverage'], '');
$coverageFile = realpath($options['--coverage']);
putenv(Tester\Environment::COVERAGE . '=' . $coverageFile);
echo "Code coverage: {$coverageFile}\n";
}


$runner = new Tester\Runner\Runner($php);
$runner->paths = $options['paths'];
$runner->threadCount = max(1, (int) $options['-j']);
Expand All @@ -129,8 +141,6 @@
ob_end_flush();
}

@unlink(__DIR__ . '/coverage.dat'); // @ - file may not exist

if (!$options['--watch']) {
die($runner->run() ? 0 : 1);
}
Expand Down
4 changes: 0 additions & 4 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
require __DIR__ . '/../Tester/bootstrap.php';


if (extension_loaded('xdebug')) {
Tester\CodeCoverage\Collector::start(__DIR__ . '/coverage.dat');
}

date_default_timezone_set('Europe/Prague');


Expand Down

0 comments on commit f5a0994

Please sign in to comment.