Search code examples
phpunit-testingphpunitcode-coverage

Using PHPUnit code coverage with interfaces


I'm using PHPUnit (3.6.7) to test and provide code coverage reports on my application, everything is set-up and working as expected.

I have complete coverage for all of the code except for my interfaces, even though I have tests that for classes that implement the interfaces. The report just states that the interface was not executed

Is there a way to cover the interfaces? Or is it a case of telling PHPUnit to ignore them for code coverage?


Solution

  • You can specify that tests for a concrete class cover methods from parent abstract classes/interfaces.

    See Specifying Covered Methods section in Code Coverage Analysis chapter in the manual.

    In the same chapter you'll also find ways to ignore blocks of code or entire files from code coverage analysis.