title: How to send headers with phpunit api request?
body: <p>I am trying to test my web service which is written in laravel 5 using phpunit. I am new to this testing framework. The application uses JWT for authentication which is passed in headers in the requests.</p>
  
  <p>My test look likes so:</p>
  
  <pre><code>$response = $this-&gt;call('POST', 'authenticate', [
      'username' =&gt; 'carparts',
      'email' =&gt; 'admin@admin.com',
      'password' =&gt; 'password'
  ]);
  
  $token = 'Bearer ' . json_decode($response-&gt;getContent())-&gt;token;
  
  $response = $this-&gt;call('POST', 'users', [
      "first_name"    =&gt; "Test",
      "last_name"     =&gt; "Test",
      "email"         =&gt; 'test@test.com',
      "password"      =&gt; "testing",
      "role"          =&gt; "1"
  ], [], [], [
      'Authorization' =&gt; $token
  ]);
  
  dd($response-&gt;getContent());
  </code></pre>
  
  <p>The token is returned fine but when I try to use in the next request to create a new user, it fails saying the token could not parsed from the request. When I do <code>request()-&gt;headers</code> in a middleware to check, even that does not show the header. What am I doing wrong? How to pass headers in a request using PHPUnit?</p>