There is a problem during unit testing when Input::old() is being called. It then throws an RuntimeException("Session store not set on request."); I am not sure what is the reason of that, but the problem exists in both Laravel 4.2 and 5.1. Is that bug or something that was intended and if so what is the solution to fix this besides of checking App::isRunningUnitTests() which I would rather like to avoid ? Session driver in config is set to array.
I came across this issue too actually, a few weeks before 5.0 shipped, and never got this fixed actually.
Is anyone able to shed some light on this?
The solution I used in my case was setting session to request manually in setUp method of PHPUnit. Like
$this->app['request']->setSession($this->app['session']->driver('array'));
Not sure if that's the best solution, it worked for me, still not optimal as it should be handled by framework I believe.
That seems like a hack to me.
Yeah, exacly, it is just a workaround for this problem so it would be cool if someone close to the framework would explain this behaviour or just fix it :) Looking forward for some reply.
We used https://github.com/orchestral/testbench package for testing so we didn't have to worry about things like this, once you get this sorted you'll probably keep running into annoying things its worth a try which handles all the dependencies.
The issue still shows up in testbench. Infact, that's what I was using when I came across it. :)
That's strange because we got forms that are using Input::old() and we aren't getting any errors.
Maybe this would help
<?php
$app['config']->set('session', [
'driver' => 'array',
'lifetime' => 120,
'expire_on_close' => false,
'encrypt' => false,
'lottery' => [2, 100],
'path' => '/',
'domain' => 'localhost',
]);
$kernel = app('Illuminate\Contracts\Http\Kernel');
$kernel->pushMiddleware('Illuminate\Session\Middleware\StartSession');
?>
Edit: That is alongside testbench so the SessionServiceProvider and Request are already loaded in.
If I cast my mind back, I probably wasn't setting that middleware. I suspect that will solve everything. Thanks. :)
And what about 4.2 version ? Should I threat this as not being solved ?
Laravel 4.2 will only be getting security fixes. No bug fixes will be applied to anything older than 5.1, sorry.
Also, I could never replicate this on 4.2, only on 5.0, and 5.0 turned out to be a usage issue rather than an actual bug.
I am also getting this error in 5.1, if I have a test that uses the WithoutMiddleware trait and $request->old() is being called during the test. I'm not using testbench.
I am also getting this error in 5.1, if I have a test that uses the WithoutMiddleware trait and $request->old() is being called during the test. I'm not using testbench.
That is the expected behaviour. You can't get the old input unless you have the session middleware.
Ah, of course... that makes sense. Thank you!
Well, the problem is when testing forms you probably want to use DisableMiddleware for avoiding problems with csrf protection. So there is no way of testing a form using the old() helper as the session middleware is disabled too.
It worked, thanks for the tip !
Pierre
2015-11-25 19:31 GMT+01:00 Vinh Quốc Nguyễn [email protected]:
@pmall https://github.com/pmall Manually pushing session middleware for
only Session will work. Like setup this up in setup method$kernel = app('Illuminate\Contracts\Http\Kernel');
$kernel->pushMiddleware('Illuminate\Session\Middleware\StartSession');And you can till use WithoutMiddleware in test to not loading any
middleware..—
Reply to this email directly or view it on GitHub
https://github.com/laravel/framework/issues/9632#issuecomment-159695194.
Did Sladewill's comment actually work? I tried setting it in the TestCase.php. When unit testing, it generates a session properly, but I still get the 'Session store not set on request.' in /var/www/html/vendor/laravel/framework/src/Illuminate/Http/Request.php:852 error. Middleware is turned on.
Most helpful comment
The solution I used in my case was setting session to request manually in
setUpmethod of PHPUnit. Like$this->app['request']->setSession($this->app['session']->driver('array'));Not sure if that's the best solution, it worked for me, still not optimal as it should be handled by framework I believe.