PHP code coverage - Understanding path coverage

78 Views Asked by At

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?

0

There are 0 best solutions below