(no commit message)
[paste/633.git] / README.rst
1 When using a method that requires a session in a unit test of a laravel based application, I encountered the following crash::\r
2 \r
3   RuntimeException: Session store not set on request.\r
4 \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
11   [...]\r
12 \r
13 I tried to solve it with the code given in https://github.com/laravel/framework/issues/9632 ::\r
14 \r
15   $this->app['request']->setSession($this->app['session']->driver('array'));\r
16 \r
17 but now I got another exception::\r
18 \r
19   TypeError:\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
24 \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
26 \r
27 My solution was to force the session into the request at the beginning of my test::\r
28 \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