-1
惩戒时调用一个成员函数这是我试图测试致命错误:在PHPSpec
public function forgot($email)
{
try
{
// Find the user using the user email address
$user =$this->sentry->findUserByLogin($email);
$resetCode = $user->getResetPasswordCode();
return true;
}
catch (UserNotFoundException $e)
{
$this->errors[] = 'User was not found.';
return false;
}
}
下面的代码是我的测试代码
function it_should_forgot(Sentry $sentry)
{
$email = '[email protected]';
$sentry->findUserByLogin($email)->shouldBeCalled();
$this->forgot($email);
}
以下是错误
PHP Fatal error: Call to a member function getResetPasswordCode() on a non-object in /var/www/laravel/app/Services/SentryService.php on line 103
我的问题是为什么我得到这个错误,因为我已经在我的测试中嘲笑哨兵?
那么,做你嘲笑'findUserByLogin'返回什么? – zerkms 2014-08-31 12:58:20
请赐教我应该怎么做。谢谢 – 2014-08-31 13:02:47
那么,看看你的测试方法,并告诉它根据它应该返回'findUserByLogin'方法。 – zerkms 2014-08-31 13:05:04