Sessions no longer persisting when using array driver in Codeception tests
I have a new 5.1 project and set up the Codeception testing end of things pretty much the same as my last 5.0 project. I have a .env.testing file which codeception references and that has a SESSION_DRIVER set to array.
However for some reason now, sessions are not persisting.
For example if I do this in a functional test:
session(['test' => true]);
$I->submitForm('.test', ['title' => '']);
dd(session('test'));
$I->seeFormErrorMessages(['title' => 'The title field is required.']);
and run the test, the die and dump outputs 'null'.
If I remove the dd() then the expected formErrorMessage is non existent, but testing it manually in the browser the error message appears as expected.
Interestingly, if I tail the logs I can see that a TokenMismatchException is being thrown.
For interests sake I overrode the handle() method in App\Http\Middleware\VerifyCsrfToken to always return $next($request); and that correctly stops the TokenMismatchException being thrown, but the dd() still returns null, or with the dd() removed from above the test still fails.
If I change my SESSION_DRIVER in .env to file, then the test passes correctly with no errors, but if I try to run more than one test using the file driver, then the first test passes but after that codeception gets stuck on the second test, reporting nothing. I tried using database as a driver as well (I have the relevant session tables setup) and the same thing happened - runs fine with only one test, gets stuck on second test if there are more than one test.
.env.testing relevant variables
APP_ENV=testing
APP_DEBUG=true
DB_HOST=localhost
DB_DATABASE=l5_tests
DB_USERNAME=test
DB_PASSWORD=test
CACHE_DRIVER=array
SESSION_DRIVER=array
QUEUE_DRIVER=sync
Codeception version:
% vendor/bin/codecept
Codeception version 2.1.1
Codeception.yml
actor: Tester
paths:
tests: tests
log: tests/_output
data: tests/_data
helpers: tests/_support
settings:
bootstrap: _bootstrap.php
colors: true
memory_limit: 1024M
modules:
config:
Db:
dsn: 'mysql:host=localhost;dbname=l5_tests'
user: 'test'
password: 'test'
dump: tests/_data/dump.sql
I'll do a clean install of L5 && Codeception in the morning and see if I can continue to replicate the issue, but thought I'd post this here in case anyone else is having the same issue.
Please or to participate in this conversation.