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

zando's avatar

Session driver failing in application tests

Hi

I'm trying to create an application test, and I'm inserting some data into the session. Since we are using phpunit with the default config, the session driver is "array". When I have a test class with a single test method, and pump some data into my session, the test works as expected. When I add another test method (even with nothing in it!), I get an exception about a view complaining that the "errors" variable is not defined, even though I am running the test with middleware. I have verified that the ShareErrorsFromSession middleware is firing.

Any advice/help appreciated

0 likes
1 reply
Sulfo's avatar

I'm going to bump this thread. Yes, it's a 5 months old thread, but I just ran into the same problem, and I'm unable to find a solution for it.

If I run a single test with phpunit --filter it_is_credited_when_not_credited_before all is OK and green.

But if I run phpuniut, then it_is_credited_when_not_credited_before will fail.

For me it's a ErrorException: Trying to get property of non-object, but I guess it 's diffrent case for case. It's this line there's failing for my test: return Session::get('user.' . $this->id . '.wanted_currency_id');

Anyone who knows why it fails when running phpunit, and not with phpunit --filter it_is_credited_when_not_credited_before?

Please or to participate in this conversation.