<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed><type>rich</type><version>1.0</version><provider_name>phorkie</provider_name><provider_url>https://p.cweiske.de/</provider_url><title>Laravel phpunit: RuntimeException: Session store not set on request.</title><author_name>Christian Weiske</author_name><cache_age>86400</cache_age><width>900</width><height>900</height><html>&lt;!-- embedding all files of https://p.cweiske.de/633 --&gt;
&lt;link rel="stylesheet" href="https://p.cweiske.de/css/embed.css"/&gt;
&lt;div class="phork" id="633"&gt;
    &lt;div class="phork-file"&gt;
 &lt;div class="phork-content"&gt;
  
&lt;div class="document"&gt;


&lt;p&gt;When using a method that requires a session in a unit test of a laravel based application, I encountered the following crash:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
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
[...]
&lt;/pre&gt;
&lt;p&gt;I tried to solve it with the code given in &lt;a class="reference external" href="https://github.com/laravel/framework/issues/9632"&gt;https://github.com/laravel/framework/issues/9632&lt;/a&gt;&lt;/p&gt;
&lt;pre class="literal-block"&gt;
$this-&amp;gt;app['request']-&amp;gt;setSession($this-&amp;gt;app['session']-&amp;gt;driver('array'));
&lt;/pre&gt;
&lt;p&gt;but now I got another exception:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
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
&lt;/pre&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;My solution was to force the session into the request at the beginning of my test:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
$req = $this-&amp;gt;app['request'];
$sessionProp = new \ReflectionProperty($req, 'session');
$sessionProp-&amp;gt;setAccessible(true);
$sessionProp-&amp;gt;setValue($req, $this-&amp;gt;app['session']-&amp;gt;driver('array'));
&lt;/pre&gt;
&lt;/div&gt;

 &lt;/div&gt;
 &lt;div class="phork-meta"&gt;
  &lt;a href="https://p.cweiske.de/633/rev-raw/f91ab1018de2b6c5ec7dbd2a90b04f916757abd0/README.rst" style="float: right"&gt;view raw source&lt;/a&gt;
  &lt;a href="https://p.cweiske.de/633#README.rst"&gt;README.rst&lt;/a&gt;
 &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</html></oembed>
