dev-master
9999999-devCalculate the real coverage based on an existing php-code-coverage report
GPL v2
The Requires
The Development Requires
by Julian Seeger
Wallogit.com
2017 © Pedro Peláez
Calculate the real coverage based on an existing php-code-coverage report
Given you have a simple class, (*2)
class SomeClass
{
public function someFunction()
{
$instance = "important message"; // this line is important
$a = "This code";
$b = "is completely";
$c = "usesless";
$instance .= "!!!"; // this one is important too
if (true) {
$f = "and has";
$g = "100% coverage";
}
$c .= "!";
return $instance; // and this one is important
}
}
And a pretty useless test for this class, that leaves most of the behavior untested, (*3)
class SomeClassTest extends \PHPUnit_Framework_TestCase
{
public function testThisTestIsStupid()
{
$sut = new SomeClass();
$instance = $sut->someFunction();
$this->assertEquals("important message!!!", $instance);
}
}
But nevertheless, the test produces 100% coverage for this class, (*4)
, (*5)
When you run php-real-coverage on this project, (*6)
Then you will know, what lines are actually tested, (*7)
, (*8)
In this example, only line 8, 12 and 18 are neccessary to make the test pass., (*9)
Add it to your composer.json, (*10)
"require-dev": {
"julianseeger/php-real-coverage": "*"
}
Generate a coverage-report with phpunit, (*11)
./vendor/bin/phpunit --coverage-php coverage.php
And let php-real-coverage test the quality of your coverage, (*12)
./vendor/bin/php-real-coverage coverage.php
only works with phpunit, (*13)
looking forward to extend it for other frameworks, given there is an audience for it, (*14)
no support for phpunit 4, (*15)
as soon as phpunit 4 is stable, I will integrate support for phpunit 3 and 4 simultanuously, (*16)
maybe you will run into problems when you abuse reflections or dynamic loading in your project, so php-real-coverage probably won't work for doctrine, etc. But it is basically meant for straight-forward test-driven projects, (*17)
no support for hhvm, (*18)
I'm currently lacking any experience with hhvm, but as it seems to support phpunit I'm looking forward to change this., (*19)
Execute the tests, (*20)
composer install --prefer-dist --dev ./vendor/bin/phpunit
Make your changes tested and in PSR-2, (*21)
Execute the the tests again, (*22)
And make your Pull Request, (*23)
~~PS: The build will fail if the testcoverage falls below 100%~~, (*24)
Calculate the real coverage based on an existing php-code-coverage report
GPL v2