Laravel Dusk, how to destroy session data between tests
In my case, tearDown()
was not enough, for some reason, a logged users was still persisted between tests, so I placed deleteAllCookies()
at setUp()
.
So, in my DuskTestCase.php I added:
/** * Temporal solution for cleaning up session */protected function setUp(){ parent::setUp(); foreach (static::$browsers as $browser) { $browser->driver->manage()->deleteAllCookies(); }}
It was the only way I could flush up session around all tests. I hope it helps.
Note: I'm using Homestead and Windows 10.
If you just want to logout your signed in user, after login test, simply use:
$browser->visit('/login') ->loginAs(\App\User::find(1)) ... some assertions ... ->logout();
You could flush the session in a tearDown()
method:
class LoginTest extends DuskTestCase{ // Your tests public function tearDown() { session()->flush(); parent::tearDown(); }}