Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

edgreenberg's avatar

'visit' a url and then check the session

In my test, I 'visit' a page as follows:

        $this->visit('user')
            ->type('johnsmith', 'username')
            ->type('[email protected]', 'email')
            ->type('311-555-2368', 'phone')
            ->type('John', 'first_name')
            ->type('Smith', 'last_name')
            ->type('Frobozz123!', 'password')
            ->type('Frobozz123!', 'password_confirmation')
            ->type('secret', 'existing_password')
            ->press('Submit')
            ->....

What I would like to do after the visit runs is check the session, since the controller will have written something like 'User johnsmith has been added.' into the session variable 'status'. When I call the method ->assertSessionHas('status','User johnsmith has been added.') I get Failed asserting that null matches expected 'User johnsmith has been added'. Using assertSessionMissing('status') I discover that I don't have a status variable.

Is there any way to get my session in the test, so I can see if my controller indeed added the session variable before it redirected?

Thanks,

Ed G

0 likes
0 replies

Please or to participate in this conversation.