我在单元测试中使用了Prophecy,我想模拟用户对象中的所有方法
class User {
public function age()
{
return date("Y") - $this->born();
}
public function born()
{
// Database call or anything else, it's a black box !
}
}
我想测试出生方式改变时的年龄
public function testProphecyAge()
{
$user = $this->prophesize(User::class);
$user->born()
->willReturn(2018)
->shouldBeCalled();
$user = $user->reveal();
$this->assertEquals(1, $user->age());
}
我得到了错误
Prophecy\Exception\Call\UnexpectedCallException: Unexpected method call on Double\User\P1