AspectMock icon indicating copy to clipboard operation
AspectMock copied to clipboard

Cannot verify parent method invocation

Open mbrodala opened this issue 10 years ago • 2 comments

It seems like method invocation via verifyInvoked*() only works on double instances but not for parent:: method calls. Example:

class ParentClass {
  public function hello() {
    echo 'Hello';
  }
}

class ChildClass extends ParentClass {
  public function hello() {
    parent::hello();
    echo ' World';
  }
}

test::double(ParentClass::class, ['hello']);

$c = new ChildClass();
$c->hello();

How would one verify that ParentClass::hello was invoked?

mbrodala avatar Jun 19 '15 14:06 mbrodala

I have the same problem. If you implement the 'hello' method as a closure and echo something inside it, you can see that this method is actually mocked but verifyInvoked() fails to verfiy this.

msdm avatar Aug 11 '15 12:08 msdm

I think I have found the issue in Mocker.php:

    public function fakeMethodsAndRegisterCalls($class, $declaredClass, $method, $params, $static)
    {
        ...
        if (isset($this->classMap[$class])) Registry::registerClassCall($class, $method, $params);
        return $result;
    }

must be:

    public function fakeMethodsAndRegisterCalls($class, $declaredClass, $method, $params, $static)
    {
        ...
        if (isset($this->classMap[$declaredClass])) Registry::registerClassCall($declaredClass, $method, $params);
        return $result;
    }

msdm avatar Aug 11 '15 14:08 msdm