title: Symfony2: Unable to simulate HTTP authentication in functional test
body: <p>I'm trying to use the following technique described on symfony.com : <a href="http://symfony.com/doc/current/cookbook/testing/http_authentication.html" rel="nofollow">http://symfony.com/doc/current/cookbook/testing/http_authentication.html</a>
  in an attempt to functionally test a controller that requires a user to be logged in.</p>
  
  <p>So far, my login form is working, I can login, and the Symfony2 debug web toolbar is showing my user as authenticated. Also, I have already written a functional test for the login process itself, this passes. So I now by two scenarios, that my login is working.</p>
  
  <p>The only problem I'm having, is when trying to simulate HTTP authentication like so for other controllers:</p>
  
  <pre><code>$client = static::createClient(array(), array(
      'PHP_AUTH_USER' =&gt; 'tester',
      'PHP_AUTH_PW'   =&gt; 'testpass',
  ));
  </code></pre>
  
  <p>I can see by inspecting the $client, that I am being redirected to my login page, the moment I try something like this:</p>
  
  <pre><code>$crawler = $client-&gt;request('GET', '/');
  </code></pre>
  
  <p>I know that the user tester with password testpass exists in the DB, as I can login with that account via browser as well.</p>
  
  <p>I can use the following code from the security controller test:</p>
  
  <pre><code>    $client = $this-&gt;createClient(array(), array('HTTP_HOST' =&gt; 'myapp.test'));
  
      // Visit user login page and login
      $crawler = $client-&gt;request('GET', '/login');
      $form = $crawler-&gt;selectButton('Login')-&gt;form();
      $crawler = $client-&gt;submit($form, array('_username' =&gt; 'tester', '_password' =&gt; 'testpass'));
  
      // ... carry on with remainder of tests
  </code></pre>
  
  <p>but I'm not too sure if this is the most efficient way to do this.</p>
  
  <p>I'm a bit stunned as to what is wrong. Any ideas? Was there a change applied to Symfony2 that means that this process has changed and the HTTP authentication simulation now doesn't work or works differently?</p>