dimanche 1 novembre 2015

PHPUnit fatal error call to undefined method on mock

I want to test that a method on an object is called. I want to do this by making a mock of Object, rather than any specific class. But the following code throws a fatal error:

class MyTest extends PHPUnit_Framework_TestCase
{
    public function testSomeMethodIsCalled()
    {
        $mock = $this->getMock('Object');
        $mock->expects($this->once())
                ->method('someMethod');
        $mock->someMethod();
    }
}

The above dies with an error:

Fatal error: Call to undefined method Mock_Object_204ac105::someMethod()

I'm sure there was a way to do this, without having to write a class that actually has a someMethod() method?

Aucun commentaire:

Enregistrer un commentaire