Phpunit: Coverage report shows 90%+ method coverage in classes, zero coverage of class itself

Created on 30 Sep 2014  路  6Comments  路  Source: sebastianbergmann/phpunit

This may be intent rather than bug, but where I have a file with a class with > 90% test coverage, the file's "traits & classes" summary reports test coverage as 0%.

phpunit-coverage

It's possible (but unconfirmed) that this is causing an issue with https://github.com/theseer/phpdox/issues/147, whereby all classes are being considered "untested".

Produced with https://github.com/parsingphase/enigma-simulator/tree/phpdox-no-coverage by running ant install-dev clean build

Installed versions on my system:

 wechsler@tahr:~/host/repos/enigma-simulator$ composer show --installed
 nikic/php-parser             v1.0.0             A PHP parser written in PHP
 ocramius/instantiator        1.1.3              A small, lightweight utility to instantiate objects in PHP without  invoking their constructors
 ocramius/lazy-map            1.0.0              A library that provides lazy instantiation logic for a map of objects
 pdepend/pdepend              2.0.2              Official version of pdepend to be handled with Composer
 phploc/phploc                2.0.6              A tool for quickly measuring the size of a PHP project.
 phpmd/phpmd                  2.1.3              Official version of PHPMD handled with Composer.
 phpunit/php-code-coverage    2.0.11             Library that provides collection, processing, and rendering functionality for PHP code coverage information.
 phpunit/php-file-iterator    1.3.4              FilterIterator implementation that filters files based on a list of suffixes.
 phpunit/php-text-template    1.2.0              Simple template engine.
 phpunit/php-timer            1.0.5              Utility class for timing
 phpunit/php-token-stream     1.3.0              Wrapper around PHP's tokenizer extension.
 phpunit/phpunit              4.2.6              The PHP Unit Testing framework.
 phpunit/phpunit-mock-objects 2.2.1              Mock Object library for PHPUnit
 sebastian/comparator         1.0.0              Provides the functionality to compare PHP values for equality
 sebastian/diff               1.2.0              Diff implementation
 sebastian/environment        1.0.0              Provides functionality to handle HHVM/PHP environments
 sebastian/exporter           1.0.1              Provides the functionality to export PHP variables for visualization
 sebastian/finder-facade      1.1.0              FinderFacade is a convenience wrapper for Symfony's Finder component.
 sebastian/git                1.2.0              Simple wrapper for Git
 sebastian/phpcpd             2.0.1              Copy/Paste Detector (CPD) for PHP code.
 sebastian/version            1.0.3              Library that helps with managing the version number of Git-hosted PHP projects
 squizlabs/php_codesniffer    1.5.5              PHP_CodeSniffer tokenises PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.
 symfony/config               v2.5.5             Symfony Config Component
 symfony/console              v2.5.5             Symfony Console Component
 symfony/dependency-injection v2.5.5             Symfony DependencyInjection Component
 symfony/filesystem           v2.5.5             Symfony Filesystem Component
 symfony/finder               v2.5.5             Symfony Finder Component
 symfony/yaml                 v2.5.5             Symfony Yaml Component
 theseer/directoryscanner     1.3.0              A recursive directory scanner and filter
 theseer/fdomdocument         1.6.0              The classes contained within this repository extend the standard DOM to use exceptions at all occasions of errors instead of PHP warnings or notices. They al...
 theseer/fxsl                 1.1.0              An XSL wrapper / extension to the PHP 5.x XSLTProcessor with Exception and extended Callback support
 theseer/phpdox               dev-master 9392c5e A fast Documentation generator for PHP Code using standard technology (SRC, DOCBLOCK, XML and XSLT) with event based processing

Most helpful comment

This is intentional. Quoting from http://thephp.cc/dates/2014/international-php-conference-spring-edition/code-coverage-covered-in-depth

"PHP_CodeCoverage only considers a function or method as covered when all of its executable lines are covered. [...] PHP_CodeCoverage only considers a class or trait as covered when all of its methods are covered."

All 6 comments

This is intentional. Quoting from http://thephp.cc/dates/2014/international-php-conference-spring-edition/code-coverage-covered-in-depth

"PHP_CodeCoverage only considers a function or method as covered when all of its executable lines are covered. [...] PHP_CodeCoverage only considers a class or trait as covered when all of its methods are covered."

Thanks for clarifying :)

You're welcome. Wondering now whether we should add this information to the documentation.

Probably worth it for completeness? Checking the docs (https://phpunit.de/manual/current/en/code-coverage-analysis.html), I note that "Lines of code that were executed while running the tests are highlighted green" - but this appears to only apply to code executed by the test... methods themselves rather than code executed by dataProvider functions (executed in the ...Test classes but outside the test... methods). Again, quite possibly intended behaviour but an edge case in the docs and not 100% clear.

I just spent a good half hour confused by this as well.

Maybe the reports should clarify by using a better description, e.g. "Full Classes" rather than just "Classes"?

Also, I might want to know how many classes were _partially_ covered, so perhaps the results ought to include all three numbers? e.g. something like Classes: 0.00%~60.00% (0~3/5), which would at least prompt you to ask questions rather than making assumptions?

The information has been added to the documentation.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nicklevett picture nicklevett  路  4Comments

keradus picture keradus  路  4Comments

sebastianbergmann picture sebastianbergmann  路  4Comments

greg0ire picture greg0ire  路  4Comments

joubertredrat picture joubertredrat  路  4Comments