title: Failed asserting the HTTP status is 200 not 500
body: <p>I am having issues running phpunit tests on our symfony application.</p>
  
  <p>I am using the following assertion code:</p>
  
  <pre><code>namespace Main\MyBundle\Tests\Controller;
  
  use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
  
  class DefaultControllerTest extends WebTestCase
  {
      public function testIndex()
      {
          $client = static::createClient();
  
          $crawler = $client-&gt;request('GET', '/');
  
         var_dump( $client-&gt;getInternalResponse());
  
          //checking home page availability
          $this-&gt;assertEquals(200, $client-&gt;getResponse()-&gt;getStatusCode());
  
      }
  }
  </code></pre>
  
  <p>However I keep getting a failure as you can see from result below:</p>
  
  <pre><code>    mcp@mcp-buildbox:/var/www/my.app.com$ phpunit -c app src/Main/MyBundle
      PHPUnit 3.6.10 by Sebastian Bergmann.
  
      Configuration read from /var/www/my.app.com/app/phpunit.xml.dist
  
      Fclass Symfony\Component\BrowserKit\Response#182 (3) {
        protected $content =&gt;
        string(138299) "&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n    &lt;head&gt;\n        &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/&gt;\n        &lt;meta name="robots" content="noindex,nofollow" /&gt;\n        &lt;title&gt;    Undefined index: SERVER_PORT (500 Internal Server Error)\n&lt;/title&gt;\n        &lt;link href="/bundles/framework/css/structure.css" rel="stylesheet" type="text/css" media="all" /&gt;\n        &lt;link href="/bundles/framework/css/body.css" rel="stylesheet" type="text/css" media="all" /&gt;\n            &lt;link href="/bundles/framework"...
        protected $status =&gt;
        int(500)
        protected $headers =&gt;
        array(3) {
          'cache-control' =&gt;
          array(1) {
            [0] =&gt;
            string(8) "no-cache"
          }
          'date' =&gt;
          array(1) {
            [0] =&gt;
            string(29) "Thu, 08 May 2014 15:32:16 GMT"
          }
          'content-type' =&gt;
          array(1) {
            [0] =&gt;
            string(24) "text/html; charset=UTF-8"
          }
        }
      }
  
  Time: 0 seconds, Memory: 22.25Mb
  
  There was 1 failure:
  
  1) Main\MyBundle\Tests\Controller\DefaultControllerTest::testIndex
  Failed asserting that 500 matches expected 200.
  
  /var/www/my.app.com/src/Main/MyBundle/Tests/Controller/DefaultControllerTest.php:25
  
  FAILURES!
  Tests: 1, Assertions: 1, Failures: 1.
  </code></pre>
  
  <p>Here is my framework settings in config.yml:</p>
  
  <pre><code>framework:
      #esi:             ~
      translator:      { fallback: %locale% }
      secret:          %secret%
      router:
          resource: "%kernel.root_dir%/config/routing.yml"
          strict_requirements: ~
          http_port: 80
          https_port: 443
      form:            ~
      csrf_protection: ~
      validation:      { enable_annotations: true }
      templating:
          engines: ['twig']
          #assets_version: SomeVersionScheme
      default_locale:  "%locale%"
      trusted_proxies: "%trusted_proxies%"
      session:         ~
      fragments:       ~
      trusted_hosts:   ~
  </code></pre>
  
  <p>Also please note that when I do:</p>
  
  <pre><code>curl -I http://my.app.com
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>HTTP/1.1 200 OK
  </code></pre>
  
  <p>I am also using PHP 5.4.9 and on an ubuntu machine. Can someone help? I looked on stack and see someone else had identical issue but the resolution is not clear to me and the answer is not really a solution: </p>
  
  <p><a href="https://stackoverflow.com/questions/19426364/failed-asserting-the-http-status-code-is-200-not-500">Failed asserting the HTTP status code is 200 not 500</a></p>