(no commit message) master
authorChristian Weiske <cweiske@cweiske.de>
Mon, 12 Aug 2019 07:50:43 +0000 (09:50 +0200)
committerwww-cweiske <www-cweiske@ahso3>
Mon, 12 Aug 2019 07:50:43 +0000 (09:50 +0200)
README.rst [new file with mode: 0644]

diff --git a/README.rst b/README.rst
new file mode 100644 (file)
index 0000000..cd07c5a
--- /dev/null
@@ -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::\r
+\r
+  RuntimeException: Session store not set on request.\r
+\r
+  .../vendor/laravel/framework/src/Illuminate/Http/Request.php:415\r
+  .../vendor/kris/laravel-form-builder/src/Kris/LaravelFormBuilder/Fields/FormField.php:531\r
+  .../vendor/kris/laravel-form-builder/src/Kris/LaravelFormBuilder/Fields/FormField.php:284\r
+  .../vendor/kris/laravel-form-builder/src/Kris/LaravelFormBuilder/Fields/FormField.php:552\r
+  .../vendor/kris/laravel-form-builder/src/Kris/LaravelFormBuilder/Fields/FormField.php:121\r
+  .../vendor/kris/laravel-form-builder/src/Kris/LaravelFormBuilder/Form.php:181\r
+  [...]\r
+\r
+I tried to solve it with the code given in https://github.com/laravel/framework/issues/9632 ::\r
+\r
+  $this->app['request']->setSession($this->app['session']->driver('array'));\r
+\r
+but now I got another exception::\r
+\r
+  TypeError:\r
+   Argument 1 passed to Symfony\Component\HttpFoundation\Request::setSession()\r
+   must be an instance of\r
+    Symfony\Component\HttpFoundation\Session\SessionInterface,\r
+   instance of Illuminate\Session\Store given\r
+\r
+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
+\r
+My solution was to force the session into the request at the beginning of my test::\r
+\r
+        $req = $this->app['request'];\r
+        $sessionProp = new \ReflectionProperty($req, 'session');\r
+        $sessionProp->setAccessible(true);\r
+        $sessionProp->setValue($req, $this->app['session']->driver('array'));\r