1

I just started working on a piece of software using PHP 7.4.27 with PHPUnit 9.5.7 and Xdebug 2.9.8. I am collection code coverage including branch and path coverage information for all my unit tests. In class "Content" I have a method named "unwrap" for which I am not able to interpret the results of the path coverage data.

This is the method in question:

public function unwrap(string $elementToUnwrap = null): self
{
    if (empty($elementToUnwrap)) {
        $this->content = $this->unwrapData();

        return $this;
    }

    $value = $this->get($elementToUnwrap);

    if (!is_array($value) && !is_object($value)) {
        throw new InvalidArgumentException('The element to unwrap must exist and it must be of type array or object.');
    }

    $this->content = $value;

    return $this;
}

And these are the path coverage results for "unwrap": enter image description here Can anybody please tell me

  1. the difference between the two yellow marked paths
  2. the difference between the two blue marked paths

I do not understand why sometimes a line is repeated three times (if (!is_array($value) && !is_object($value)) {) and sometimes only two times?

4
  • I think there is a bug somewhere in the xdebug code coverage collection of data. The lines should not be repeated in the code coverage analysis. Commented Dec 27, 2021 at 13:47
  • Thank you very much. Sounds like a logical explanation. Commented Dec 27, 2021 at 13:53
  • I just dont understand why. Did you maybe make changes to the file while xdebug was collecting data for code coverage? Commented Dec 27, 2021 at 13:54
  • No, I did not. Xdebug seems to think that there are 5 paths but I don't understand why. Commented Dec 27, 2021 at 14:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.