TBPixel
TBPixel

Reputation: 31

PHP Infection all mutants were not covered by tests

I'm trying to implement the infection/infection php mutation testing library into a new project of mine. I've set up some tests which all pass, then ran infection.

Infection returns the following:

You are running Infection with xdebug enabled.
    ____      ____          __  _
   /  _/___  / __/__  _____/ /_(_)___  ____ 
   / // __ \/ /_/ _ \/ ___/ __/ / __ \/ __ \
 _/ // / / / __/  __/ /__/ /_/ / /_/ / / / /
/___/_/ /_/_/  \___/\___/\__/_/\____/_/ /_/

Running initial test suite...

PHPUnit version: 7.4.0

   23 [============================] < 1 sec

Generate mutants...

Processing source code files: 3/3
Creating mutated files and processes: 14/14
.: killed, M: escaped, S: uncovered, E: fatal error, T: timed out

SSSSSSSSSSSSSS                                       (14 / 14)

14 mutations were generated:
       0 mutants were killed
      14 mutants were not covered by tests
       0 covered mutants were not detected
       0 errors were encountered
       0 time outs were encountered

Metrics:
         Mutation Score Indicator (MSI): 0%
         Mutation Code Coverage: 0%
         Covered Code MSI: 0%

Please note that some mutants will inevitably be harmless (i.e. false positives).

Time: 1s. Memory: 10.00MB

When I dug a little deeper into my infection-log.txt, I found that many of the uncovered mutants were for the Function Signature Visibility mutator.

The issue I am running into is that my tests do cover those methods. I manually changed some of my methods from public to protected, re-ran my phpunit tests and the tests failed. I'm really not sure where to proceed from here. I have a hunch that infection isn't properly detecting my phpunit test suite, but I cannot find any discussion about this being an issue elsewhere.

If anyone has any ideas let me know.

Upvotes: 1

Views: 989

Answers (1)

TBPixel
TBPixel

Reputation: 31

This issue was on me! Running around in circles for hours only to find out it was your own fault is a real pain.

I had the set the phpunit configuration option forceCoversAnnotation which makes it so that

"Code Coverage will only be recorded for tests that use the @Covers annotation documented in @Covers."

At no point was I using @Covers annotations, nor do I think I would normally. I apologise for the confusing issue, thanks!

Upvotes: 2

Related Questions