-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