PHPUnit mock objects and method type hinting PHPUnit mock objects and method type hinting php php

PHPUnit mock objects and method type hinting


Update

Oh, actually, the problem is pretty simple, but somehow hard to spot. Instead of:

$observer = $this->getMock('SplObserver', array('update'))                 ->expects($this->once())                 ->method('update');

You have to write:

$observer = $this->getMock('SplObserver', array('update'));$observer->expects($this->once())         ->method('update');

That's because getMock() returns a different thing than method(), that's why you got the error. You passed the wrong object to attach.

Original answer

I think you have to fully qualify the type of the mock:

$observer = $this->getMock('\SplObserver', array('update'));