Support the ongoing development of Laravel.io →
posted 10 years ago
Testing

Here is the code being tested

    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;
        }
    }

Here is my spec code

    function it_should_forgot(Sentry $sentry)
    {
        $email = 'johndavedecano@gmail.com';

        $sentry->findUserByLogin($email)->shouldBeCalled();

        $this->forgot($email);
    }

Here is the error

PHP Fatal error:  Call to a member function getResetPasswordCode() on a non-object in /var/www/laravel/app/Services/SentryService.php on line 103

Does anyone know how to properly test such method? Please also enlighten me why am i getting such error. Thanks inadvance

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.