ayekoto's avatar

seeInPage() error with phpunit test

at last, am able to make a post.... happy :),

now here is my challenge:

here is my controller code

    /**
     * process the authentication
     * 
     * @param  Request $request 
     * @return            
     */
    public function postLogin(LoginRequest $request)
    {
        $this->dispatchFrom(AuthenticateCommand::class, $request);

    return redirect()->route('admin.dashboard');    
    }
below is my handler for the logic of the authentication

    public function handle(AuthenticateCommand $command)
    {
        try {
    
            $user = $this->user->findBy('email', $command->email);

            if ( ! Hash::check($command->password, $user->password) )
            {
                throw new PasswordNotCorrectException();                
            }

            $this->auth->login($user);

            return $user;

        } catch (ModelNotFoundException $e) {
            
            throw new UserNotFoundException();
            
        }

    }

here is my auth test

    /** @test */
    public function a_user_may_successfully_login()
    {
        $this->visit('auth/login')
             ->type('email', 'email')
             ->type('password', 'password')
             ->press('Sign in')
                 ->seePageIs(route('admin.dashboard'));
    }

my test for the authentication process keeps failing though if i login manually, my authentication works well. goes to the expected page but my test keeps failing...

here is the error message on from the phpunit test:

1) AuthenticationTest::a_user_may_successfully_login
Did not land on expected page [http://localhost/admin/dashboard].

Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'http://localhost/admin/dashboard'
+'http://localhost/auth/login'

/home/vagrant/Code/propertynew/vendor/laravel/framework/src/Illuminate/Foundation/Testing/InteractsWithPages.php:140
/home/vagrant/Code/propertynew/tests/AuthenticationTest.php:35

Pls i need to know what am doing wrong, thanks everyone

0 likes
2 replies
ifpingram's avatar

@ayekoto do you have the user you are logging in with created in the test database before the start of the test? You will probably need to seed it.

ayekoto's avatar

uhmmm, do i think i will create a user then first, to see the outcome. thanks for your input

Please or to participate in this conversation.