2014-08-31 4 views
-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 

제 질문은 왜 제가이 시험에서 조롱 한 보병을 가지고 있기 때문에이 오류가 발생합니까?

+0

을 어디를 수행

function it_returns_true_if_user_is_found(Sentry $sentry, User $user) { $email = '[email protected]'; $sentry->findUserByLogin($email)->willReturn($user); $this->forgot($email)->shouldReturn(true); } function it_returns_false_if_user_is_not_found(Sentry $sentry) { $email = '[email protected]'; $sentry->willThrow(new UserNotFoundException())->duringFindUserByLogin($email); $this->forgot($email)->shouldReturn(false); } 

을 추천 도서 당신은'findUserByLogin'가 반환하는 것을 조롱합니까? – zerkms

+0

어떻게해야하는지 알려주세요. 감사합니다. –

+0

글쎄, 테스트 메소드를보고'findUserByLogin' 메소드가 리턴해야하는 것을 알려줄 것입니다. – zerkms

답변