php - PHPUnit fatal error call to undefined method on mock -
i want test method on object called. want making mock of object
, rather specific class. following code throws 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 error:
fatal error: call undefined method mock_object_204ac105::somemethod()
i'm sure there way this, without having write class has somemethod()
method?
you must set array of methods should available in mock when create via $this->getmock()
, code should work:
$mock = $this->getmock('object', ['somemethod']);
Comments
Post a Comment