How to know if xdebug is right?

116 Views Asked by At

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?

2

There are 2 best solutions below

4
On BEST ANSWER

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.

6
On

By looking at the example you provided xdebug is actually "right", since the return statements are all inside the switch, you never get to the last line of that function.

Also there are options to allow "strict" coverage, to exclude code invoked recursively, so be careful you are not running some of these if it's not the behaviour you are expecting