sebastianbergmann / phpunit

The PHP Unit Testing framework.
https://phpunit.de/
BSD 3-Clause "New" or "Revised" License
19.71k stars 2.2k forks source link

0% coverage on one class (and only one) #2956

Closed julien-boudry closed 6 years ago

julien-boudry commented 6 years ago
Q A
PHPUnit version 6.5.5
PHP version 7.1.8 / Xdebug 2.5.5 (same thing with Scrutinizer and PHP 7.2)
Installation Method Composer

Hi,

Code coverage seem working correctly for most class.

But one class pass tests successfully ... But stats coverage stay... 0% (line, method, class). I try many things, verify many times, but coverage stay alway at 0%.

I need help, because it's look like au nice bug.

For testing, i make a fork of my project, deleting all other test, and create one test method spécially for show this 0% coverage.

Reproduce (dedicated repository) :

For testing, i make a fork of my project, deleting all other test, and create one test method spécially for show this 0% coverage.

Repository specially for debug purpose : https://github.com/CondorcetPHP/CondorcetCoverageBug

Test : Test pass, but no coverage

image

Reproduce (full repository) :

Bug also real from the original real repository, with many tests and coverage valid: https://github.com/julien-boudry/Condorcet

vendor/bin/phpunit -v --coverage-text
PHPUnit 6.5.5 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.1.8 with Xdebug 2.5.5
Configuration: C:\Program Files (x86)\EasyPHP-Devserver-17\eds-www\Condorcet\phpunit.xml.dist

.Success!
Process in: 0.768s.Success!
Process in: 0.761s.............................................................  63 / 102 ( 61%)
.......................................                         102 / 102 (100%)

Time: 1.2 minutes, Memory: 100.00MB

OK (102 tests, 334 assertions)

Code Coverage Report:        
  2018-01-11 20:15:00        
                             
 Summary:                    
  Classes: 35.29% (12/34)    
  Methods: 48.23% (136/282)  
  Lines:   66.98% (1057/1578)

\Condorcet::CondorcetVersion
  Methods:   0.00% ( 0/ 1)   Lines:  50.00% (  2/  4)
\Condorcet::Condorcet\Candidate
  Methods:  70.00% ( 7/10)   Lines:  80.95% ( 17/ 21)
\Condorcet::Condorcet\Condorcet
  Methods:  25.00% ( 2/ 8)   Lines:  87.04% ( 47/ 54)
\Condorcet::Condorcet\CondorcetException
  Methods:  33.33% ( 1/ 3)   Lines:  92.31% ( 36/ 39)
\Condorcet::Condorcet\Election
  Methods:  40.68% (24/59)   Lines:  65.97% (221/335)
\Condorcet::Condorcet\Result
  Methods:  25.93% ( 7/27)   Lines:  60.94% ( 39/ 64)
\Condorcet::Condorcet\Vote
  Methods:  52.94% (18/34)   Lines:  65.22% (120/184)
\Condorcet::Linkable
  Methods:  42.86% ( 3/ 7)   Lines:  62.50% ( 10/ 16)
\Condorcet\Algo::Condorcet\Algo\Method
  Methods:  50.00% ( 1/ 2)   Lines:  90.00% (  9/ 10)
\Condorcet\Algo::Condorcet\Algo\Pairwise
  Methods:  90.91% (10/11)   Lines:  97.22% ( 35/ 36)
\Condorcet\Algo\Methods::Condorcet\Algo\Methods\CondorcetBasic
  Methods:  50.00% ( 2/ 4)   Lines:  92.31% ( 24/ 26)
\Condorcet\Algo\Methods::Condorcet\Algo\Methods\Copeland
  Methods: 100.00% ( 1/ 1)   Lines: 100.00% (  1/  1)
\Condorcet\Algo\Methods::Condorcet\Algo\Methods\DodgsonQuick
  Methods:  66.67% ( 2/ 3)   Lines:  93.94% ( 31/ 33)
\Condorcet\Algo\Methods::Condorcet\Algo\Methods\DodgsonTidemanApproximation
  Methods: 100.00% ( 1/ 1)   Lines: 100.00% (  1/  1)
\Condorcet\Algo\Methods::Condorcet\Algo\Methods\KemenyYoung
  Methods:  71.43% ( 5/ 7)   Lines:  94.34% ( 50/ 53)
\Condorcet\Algo\Methods::Condorcet\Algo\Methods\MinimaxMargin
  Methods: 100.00% ( 1/ 1)   Lines: 100.00% (  1/  1)
\Condorcet\Algo\Methods::Condorcet\Algo\Methods\MinimaxOpposition
  Methods: 100.00% ( 1/ 1)   Lines: 100.00% (  1/  1)
\Condorcet\Algo\Methods::Condorcet\Algo\Methods\MinimaxWinning
  Methods: 100.00% ( 1/ 1)   Lines: 100.00% (  1/  1)
\Condorcet\Algo\Methods::Condorcet\Algo\Methods\PairwiseStatsBased_Core
  Methods: 100.00% ( 3/ 3)   Lines: 100.00% ( 25/ 25)
\Condorcet\Algo\Methods::Condorcet\Algo\Methods\RankedPairs_Core
  Methods:  88.89% ( 8/ 9)   Lines:  94.57% ( 87/ 92)
\Condorcet\Algo\Methods::Condorcet\Algo\Methods\SchulzeMargin
  Methods: 100.00% ( 1/ 1)   Lines: 100.00% (  1/  1)
\Condorcet\Algo\Methods::Condorcet\Algo\Methods\SchulzeRatio
  Methods: 100.00% ( 1/ 1)   Lines: 100.00% (  3/  3)
\Condorcet\Algo\Methods::Condorcet\Algo\Methods\SchulzeWinning
  Methods: 100.00% ( 1/ 1)   Lines: 100.00% (  1/  1)
\Condorcet\Algo\Methods::Condorcet\Algo\Methods\Schulze_Core
  Methods: 100.00% ( 5/ 5)   Lines: 100.00% ( 55/ 55)
\Condorcet\Algo\Tools::Condorcet\Algo\Tools\PairwiseStats
  Methods: 100.00% ( 1/ 1)   Lines: 100.00% ( 27/ 27)
\Condorcet\Algo\Tools::Condorcet\Algo\Tools\Permutation
  Methods:  71.43% ( 5/ 7)   Lines:  80.65% ( 25/ 31)
\Condorcet\DataManager::Condorcet\DataManager\ArrayManager
  Methods:  24.14% ( 7/29)   Lines:  35.66% ( 46/129)
\Condorcet\DataManager::Condorcet\DataManager\VotesManager
  Methods:  62.50% ( 5/ 8)   Lines:  65.15% ( 43/ 66)
\Condorcet\Timer::Condorcet\Timer\Chrono
  Methods: 100.00% ( 8/ 8)   Lines: 100.00% ( 16/ 16)
\Condorcet\Timer::Condorcet\Timer\Manager
  Methods:  80.00% ( 4/ 5)   Lines:  90.91% ( 20/ 22)

Thanks for help !

sebastianbergmann commented 6 years ago

This should have been reported on the php-code-coverage project.

I am sorry that I have to close this issue here as GitHub does not support moving issues from one project to another.

kubawerlos commented 6 years ago

@julien-boudry you have forceCoversAnnotation = "true" in your phpunit.xml.dist and no @covers annotation in the test, so the behaviour is perfectly fine.

julien-boudry commented 6 years ago

@kubawerlos : Many thanks. It's working well now.

But that is still not understandable from my point of view. Because if we take the real deposit (not the test deposit that I quoted in the first place): This is the case for all the tests, except this one only defers coverage at 0%. The other classes do not have this problem

I'm satisfied with that, though. Thank you very much.