I think that this issue come with one of the last versions of 4.1.*. I am not able to set a session value in a test. I'm pretty sure that I was able to do that before.
// HomeControllerTest.php
public function testSetSessionValueInHomePage()
{
Session::set('role', 'admin');
$this->call('GET', 'home');
}
// HomeController.php
public function getHome()
{
Session::get('role'); // return null
}
I could use mocks but that's not my goal in my integration tests and that's not simple to mock. I have to do that for now :
$sessionStore = m::mock('Illuminate\Session\Store');
Session::shouldReceive('isStarted')->andReturn(true);
Session::shouldReceive('driver')->andReturn($sessionStore);
Session::shouldReceive('get')->with('role')->andReturn('admin');
Are you using the array driver?
For testing, yes.
Error?
When I set a session value in a controller test, I can't get that value in the controller. Like if it was never set.
Added session helper to TestCase.
$this->session(['foo' => 'bar']);
Also:
$this->flushSession();
Great ! Thanks a lot.
Most helpful comment
Added
sessionhelper to TestCase.Also: