title: PhpUnit and Laravel 5.4 how to mock Session data during a test
body: <p>I'm testing a class in laravel 5.4 with phpunit that uses the session to get data. Retrieving the session data works when accessing it directly when the app is running aka "session('consumer')" returns a value, however when i try to test a function that uses the session, I get the below error: </p>
  
  <p><strong>ReflectionException: Class session does not exist</strong></p>
  
  <p>Can someone please shed some light on how to accomplish setting session data during a test.</p>
  
  <p>I have tried using:</p>
  
  <p><code>$this-&gt;session()-&gt;put([$array_value])</code> but get an error "class session does not exist on class_im_testing"</p>
  
  <p>Thanks in advance for your help!</p>
  
  <pre><code>public function test_get_user()
  {
      $mockUser =  [
          'id' =&gt; 'cf442564-d076-4198-beb5-edef5aa51a69',
          'name' =&gt; 'John Doe',
          'fname' =&gt; 'John',
          'lname' =&gt; 'Doe',  
      ];
  
      session-&gt;put('consumer', [
          'id' =&gt; 'cf442564-d076-4198-beb5-edef5aa51a69',
          'name' =&gt; 'John Doe',
          'fname' =&gt; 'John',
          'lname' =&gt; 'Doe',  
      ]);
  
      $user = $this-&gt;repo-&gt;getUser();
  
      $this-&gt;assertEqual($user, $mockUser);
  }
  </code></pre>
  
  <hr>
  
  <pre><code>public function getUser()
  {
     $user = new User(session('consumer'));
     return $user;
  }
  </code></pre>