May 25, 2016
4
Level 1
Setting cookies before test
I know neither setcookie nor sessions in general are very test-friendly, I need to test a specific behaviour based on the presence of a cookie, how do I set a cookie before running the test ? For the moment it fails, it behaves likes nothing was set.
Is there a way using ->visit() that I'm not aware of or a way with ->call() where I can set session variables ?
$this->actingAs($user)
->withSession(['user' => $user, 'profile' => $profile]) ;
@setcookie( 'locale_lc', "fr", time() + 60 * 60 * 24 * 900, '/', "domain.com", true, true) ;
$this->visit('/profile') ;
I also tried this, but it does nothing
$cookie = ['locale_lc' => Crypt::encrypt('fr')] ;
$this->actingAs($user)
->withSession(['user' => $user, 'profile' => $profile])
->makeRequest('GET', '/profile', [], $cookie) ;
Level 50
Please or to participate in this conversation.