From f91ab1018de2b6c5ec7dbd2a90b04f916757abd0 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Mon, 12 Aug 2019 09:50:43 +0200 Subject: [PATCH 1/1] --- README.rst | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 README.rst diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..cd07c5a --- /dev/null +++ b/README.rst @@ -0,0 +1,32 @@ +When using a method that requires a session in a unit test of a laravel based application, I encountered the following crash:: + + RuntimeException: Session store not set on request. + + .../vendor/laravel/framework/src/Illuminate/Http/Request.php:415 + .../vendor/kris/laravel-form-builder/src/Kris/LaravelFormBuilder/Fields/FormField.php:531 + .../vendor/kris/laravel-form-builder/src/Kris/LaravelFormBuilder/Fields/FormField.php:284 + .../vendor/kris/laravel-form-builder/src/Kris/LaravelFormBuilder/Fields/FormField.php:552 + .../vendor/kris/laravel-form-builder/src/Kris/LaravelFormBuilder/Fields/FormField.php:121 + .../vendor/kris/laravel-form-builder/src/Kris/LaravelFormBuilder/Form.php:181 + [...] + +I tried to solve it with the code given in https://github.com/laravel/framework/issues/9632 :: + + $this->app['request']->setSession($this->app['session']->driver('array')); + +but now I got another exception:: + + TypeError: + Argument 1 passed to Symfony\Component\HttpFoundation\Request::setSession() + must be an instance of + Symfony\Component\HttpFoundation\Session\SessionInterface, + instance of Illuminate\Session\Store given + +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. + +My solution was to force the session into the request at the beginning of my test:: + + $req = $this->app['request']; + $sessionProp = new \ReflectionProperty($req, 'session'); + $sessionProp->setAccessible(true); + $sessionProp->setValue($req, $this->app['session']->driver('array')); -- 2.30.2