Skip to content

Merging code coverage reports from phpunit & phpspec returns wrong coverage #498

@stefandoorn

Description

@stefandoorn

It might be similar to #401, but I'm seeing some behaviour I didn't expect. I'm not sure in which library it is, so I just choose this one as I think it might bring together the right people from the same subject. (cc @henrikbjorn)

My use case is that I'm both using phpspec & phpunit for different types of tests. Both suites generate code coverage files (both .cov & HTML output), after which I merge the .cov files using phpcov to generate an overall HTML report.

For one of my files, the result from phpunit is 100% coverage, which is expected. phpspec reports 0% coverage, which is expected. Then merging them, I got lower than 100% coverage, as it seems it's having problems with some opening and closing curly braces. This is not expected.

I have no clue where the error is occuring (phpunit coverage, phpspec coverage, or the phpcov merging), but I will try to give as much information possible in here.

PHP

PHP 7.1.0-2+deb.sury.org xenial+1 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.1.0-dev, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.1.0-2+deb.sury.org xenial+1, Copyright (c) 1999-2016, by Zend Technologies
with Xdebug v2.5.0, Copyright (c) 2002-2016, by Derick Rethans
with blackfire v1.14.1 linux-x64-non_zts71, https://blackfire.io, by Blackfireio Inc.

Packages

PHPUnit 5.7.4 by Sebastian Bergmann and contributors.
phpspec 3.2.2
phpcov 3.1.0 by Sebastian Bergmann.
henrikbjorn/phpspec-code-coverage 3.0.1

PHPUnit .cov

  '/home/vagrant/src/AppBundle/DependencyInjection/AppExtension.php' => 
  array (
    14 => 
    array (
      0 => 'Tests\\AppBundle\\DependencyInjection\\AppExtensionTest::testServices',
    ),
    15 => 
    array (
      0 => 'Tests\\AppBundle\\DependencyInjection\\AppExtensionTest::testServices',
    ),
    16 => 
    array (
      0 => 'Tests\\AppBundle\\DependencyInjection\\AppExtensionTest::testServices',
    ),
    17 => 
    array (
      0 => 'Tests\\AppBundle\\DependencyInjection\\AppExtensionTest::testServices',
    ),
    20 => 
    array (
      0 => 'Tests\\AppBundle\\DependencyInjection\\AppExtensionTest::testServices',
    ),
    21 => 
    array (
      0 => 'Tests\\AppBundle\\DependencyInjection\\AppExtensionTest::testServices',
    ),
    22 => 
    array (
      0 => 'Tests\\AppBundle\\DependencyInjection\\AppExtensionTest::testServices',
    ),
    26 => 
    array (
      0 => 'Tests\\AppBundle\\DependencyInjection\\AppExtensionTest::testServices',
    ),
    27 => NULL,
  ),

PHPSpec .cov

  '/home/vagrant/src/AppBundle/DependencyInjection/AppExtension.php' => 
  array (
    13 => 
    array (
    ),
    14 => 
    array (
    ),
    15 => 
    array (
    ),
    16 => 
    array (
    ),
    17 => 
    array (
    ),
    18 => 
    array (
    ),
    20 => 
    array (
    ),
    21 => 
    array (
    ),
    22 => 
    array (
    ),
    25 => 
    array (
    ),
    26 => 
    array (
    ),
    27 => 
    array (
    ),
  ),

.xml result after merge (vendor/bin/phpcov merge . --html=_coverage --clover coverage-merged.xml)

 <file name="/home/vagrant/src/AppBundle/DependencyInjection/AppExtension.php">
        <class name="AppExtension" namespace="AppBundle\DependencyInjection">
          <metrics complexity="3" methods="2" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="12" coveredstatements="8" elements="14" coveredelements="8"/>
        </class>
        <line num="12" type="method" name="load" visibility="public" complexity="2" crap="2.04" count="1"/>
        <line num="13" type="stmt" count="0"/>
        <line num="14" type="stmt" count="1"/>
        <line num="15" type="stmt" count="1"/>
        <line num="16" type="stmt" count="1"/>
        <line num="17" type="stmt" count="1"/>
        <line num="18" type="stmt" count="0"/>
        <line num="20" type="stmt" count="1"/>
        <line num="21" type="stmt" count="1"/>
        <line num="22" type="stmt" count="1"/>
        <line num="24" type="method" name="getAlias" visibility="public" complexity="1" crap="1.30" count="1"/>
        <line num="25" type="stmt" count="0"/>
        <line num="26" type="stmt" count="1"/>
        <line num="27" type="stmt" count="0"/>
        <metrics loc="28" ncloc="28" classes="1" methods="2" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="12" coveredstatements="8" elements="14" coveredelements="8"/>
      </file>

HTML output phpunit

screen shot 2016-12-28 at 19 56 28

HTML output phpspec

screen shot 2016-12-28 at 19 56 22

HTML output combined

screen shot 2016-12-28 at 19 56 41

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions