1 When using a method that requires a session in a unit test of a laravel based application, I encountered the following crash::
\r
3 RuntimeException: Session store not set on request.
\r
5 .../vendor/laravel/framework/src/Illuminate/Http/Request.php:415
\r
6 .../vendor/kris/laravel-form-builder/src/Kris/LaravelFormBuilder/Fields/FormField.php:531
\r
7 .../vendor/kris/laravel-form-builder/src/Kris/LaravelFormBuilder/Fields/FormField.php:284
\r
8 .../vendor/kris/laravel-form-builder/src/Kris/LaravelFormBuilder/Fields/FormField.php:552
\r
9 .../vendor/kris/laravel-form-builder/src/Kris/LaravelFormBuilder/Fields/FormField.php:121
\r
10 .../vendor/kris/laravel-form-builder/src/Kris/LaravelFormBuilder/Form.php:181
\r
13 I tried to solve it with the code given in https://github.com/laravel/framework/issues/9632 ::
\r
15 $this->app['request']->setSession($this->app['session']->driver('array'));
\r
17 but now I got another exception::
\r
20 Argument 1 passed to Symfony\Component\HttpFoundation\Request::setSession()
\r
21 must be an instance of
\r
22 Symfony\Component\HttpFoundation\Session\SessionInterface,
\r
23 instance of Illuminate\Session\Store given
\r
25 I do not know why the Illuminate Session Store does not implement Symfony's SessionInterface in Laravel 5.5. Looks like a bug to me.
\r
27 My solution was to force the session into the request at the beginning of my test::
\r
29 $req = $this->app['request'];
\r
30 $sessionProp = new \ReflectionProperty($req, 'session');
\r
31 $sessionProp->setAccessible(true);
\r
32 $sessionProp->setValue($req, $this->app['session']->driver('array'));
\r