title: Test basic auth
body: <p>I want to test my basic auth protected pages. The test for <em>unauthorization</em> works fine. But I struggle on the authorized login, as I do not know how to set the headers on in the test. </p>
  
  <p>I could not find a hint, how to set headers on <code>$this-&gt;call()</code>. The only information I could find was: </p>
  
  <pre><code>$this-&gt;call($method, $uri, $parameters, $cookies, $files, $server, $content);
  </code></pre>
  
  <p>and there are the headers missing. </p>
  
  <p><strong>How do I easily test basic auth on laravel. Concrete: How do I set the basic auth header for the test request?</strong></p>
  
  <p>What I currently have: </p>
  
  <pre class="lang-php prettyprint-override"><code>class ExampleTest extends TestCase {
      public function test401UnauthorizedOnMe() { 
          $response = $this-&gt;call('GET', '/api/me');
          $this-&gt;assertResponseStatus( 401);
      }
  
      public function testCorrectLoginOnMe() { 
          // http://shortrecipes.blogspot.de/2009/12/testing-basic-http-authentication-using.html
          //send header with correct user and password i.e.
          ////YWRtaW46YWRtaW4xMg== is equal to base64_encode( "admin:admin12")
          $this-&gt;request-&gt;setHeader( 'Authorization','Basic YWRtaW46YWRtaW4xMg==');
          $response = $this-&gt;call('GET', '/api/me');
          $this-&gt;assertResponseStatus(200);
      }
  }
  </code></pre>
  
  <p>I tried <code>$this-&gt;$request-&gt;setHeader();</code> but with this I only get an error: </p>
  
  <pre><code>1) ExampleTest::testCorrectLoginOnMe
  ErrorException: Undefined property: ExampleTest::$request
  </code></pre>