2017 © Pedro Peláez
 

library php-real-coverage

Calculate the real coverage based on an existing php-code-coverage report

image

julianseeger/php-real-coverage

Calculate the real coverage based on an existing php-code-coverage report

  • Thursday, March 13, 2014
  • by julianseeger
  • Repository
  • 3 Watchers
  • 3 Stars
  • 19 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Build Status Code Coverage Scrutinizer Quality Score License Latest Stable Version, (*1)

What is "real" coverage?

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)

QuickStart

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

Roadmap to Version 0.1-Beta

  • add proxy-autoloader
  • handle non-composer autoloader (wrap existing autoloaders)
  • keep original method signature in the polymorphic proxies (strict support)
  • allow non-namespaced classes
  • support for magic methods
  • rewrite the prototype of RealCoverageRun (the "main" method)
  • pass appropriate arguments to phpunit
  • support bootstrapping (like "--bootstrap" in phpunit)

Roadmap to Version 1.0

  • integrate symfony/console
  • run only those tests that cover the modified lines (huge speedup)
  • add hooks into main algorithm to allow listeners/printers/etc
  • support all default phpunit coverage writers (html, text, clover, php)
  • review and restructure the architecture

Limitations

  • 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)

Contribute

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)

The Versions

13/03 2014

dev-master

9999999-dev

Calculate the real coverage based on an existing php-code-coverage report

  Sources   Download

GPL v2

The Requires

 

The Development Requires

by Julian Seeger