Search code examples
phpphpunitxdebugphp-code-coverage

How to know if xdebug is right?


I'm running some tests and some reports don't make sense for example:

enter image description here

enter image description here

I also have another example: Why xdebug marks 587 and 588 as not executed and 589 as executed?


Solution

  • If you don't have a test where switch is non–matching then xdebug coverage is correct.

    If execution is only ever returned from switch in tests then end of method (implicit void return) is never ever reached/executed and as such not covered.

    You can be confident that at this time there is no problem here, but over time this is brittle. What if you add a third possibility, but forget to handle it? And so on.

    Coverage does its job here — it points out a (potential) code path that isn’t being tested.