Search code examples
phpgithubphpunitxdebug

PHPUnit and Xdebug coverage for abstract classes are always 0%


Repository for this concrete issue: goph-R/dynart-coverage-test

The issue is as in the subject: for abstract classes I always get 0% coverage whatever I do.

  • I created a TheAbstractClass and a related TheAbstractClassTest
  • In the test I had to instantiate the abstract class, so I created a TheTestableClass for it and it extends the TheAbstractClass. I tried this with the PHPUnit's createMockForAbstractClass() the same issue happens.

After I run the tests, everything will PASS, but the coverage report for TheAbstractClass is 0%, but for TheConcreteClass it is 100%.

What I do wrong, how could I have coverage for my abstract classes?

My configuration:

  • Windows 10
  • PHP 7.4.3
  • Xdebug 2.8.1
  • PHPUnit 9.6.6

Solution

  • The command line test invocation includes this argument:

    -dauto_prepend_file=xdebug_filter.php
    

    Remove this, you don't need it, as the code coverage directory is already being provided by the phpunit.xml.dist file.