Skip to content

Commit 9d5daca

Browse files
author
Spencer Rinehart
committed
Use phpunit as a library.
This enables more programmatic access to phpunit, especially when it comes to code coverage. By using the code coverage report object directly we can remove the clover.xml generation and libxml dependency.
1 parent e714dc8 commit 9d5daca

3 files changed

Lines changed: 128 additions & 64 deletions

File tree

build.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,19 @@
2121
exit(1);
2222
}
2323

24-
passthru('vendor/bin/phpunit --coverage-html coverage --coverage-clover clover.xml', $returnStatus);
25-
if ($returnStatus !== 0) {
24+
$phpunitConfiguration = PHPUnit_Util_Configuration::getInstance(__DIR__ . '/phpunit.xml');
25+
$phpunitArguments = array('coverageHtml' => __DIR__ . '/coverage', 'configuration' => $phpunitConfiguration);
26+
$testRunner = new PHPUnit_TextUI_TestRunner();
27+
$result = $testRunner->doRun($phpunitConfiguration->getTestSuiteConfiguration(), $phpunitArguments);
28+
if (!$result->wasSuccessful()) {
2629
exit(1);
2730
}
2831

29-
$xml = new SimpleXMLElement(file_get_contents('clover.xml'));
30-
foreach ($xml->xpath('//file/metrics') as $metric) {
31-
if ((int)$metric['elements'] !== (int)$metric['coveredelements']) {
32-
file_put_contents('php://stderr', "Code coverage was NOT 100%\n");
33-
exit(1);
34-
}
32+
$coverageFactory = new PHP_CodeCoverage_Report_Factory();
33+
$coverageReport = $coverageFactory->create($result->getCodeCoverage());
34+
if ($coverageReport->getNumExecutedLines() !== $coverageReport->getNumExecutableLines()) {
35+
file_put_contents('php://stderr', "Code coverage was NOT 100%\n");
36+
exit(1);
3537
}
3638

3739
echo "Code coverage was 100%\n";

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
},
2727
"require-dev": {
2828
"dominionenterprises/dws-coding-standard": "~1.1",
29-
"phpunit/phpunit": "~4.0",
30-
"lib-libxml": "*"
29+
"phpunit/phpunit": "~4.0"
3130
},
3231
"autoload": {
3332
"psr-4": { "DominionEnterprises\\Mongo\\": "src/" }

composer.lock

Lines changed: 117 additions & 54 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)