title: "Undefined index: localhost" PHPUnit exception in Codeception with Symfony2 module
body: <p>I've got this very simple acceptance test using Codeception and its Symfony2 module:</p>
  
  <pre class="lang-php prettyprint-override"><code>public function myTest(AcceptanceTester $I)
  {
      $I-&gt;wantTo('test something');
      $I-&gt;amOnRoute("acme_site_home.es");
      $I-&gt;dontSee('hello');
  }
  </code></pre>
  
  <p>When I run it I get an <code>Undefined index: localhost</code> PHPUnit_Framework_Exception triggered by a call to <code>$request-&gt;server-&gt;get("HTTP_HOST")</code> in my route action.</p>
  
  <p>I already tried the following:</p>
  
  <ul>
  <li>Adding this to phpunit.xml:</li>
  </ul>
  
  <pre class="lang-xml prettyprint-override"><code>    &lt;phpunit&gt;
          &lt;php&gt;
              &lt;server name='HTTP_HOST' value='http://some.host.com' /&gt;
          &lt;/php&gt;
      &lt;/phpunit&gt;
  </code></pre>
  
  <ul>
  <li>Adding this to my test:</li>
  </ul>
  
  <pre class="lang-php prettyprint-override"><code>    $_SERVER['HOST_NAME'] = "some.host.com";
  </code></pre>
  
  <ul>
  <li>Adding this to my test:</li>
  </ul>
  
  <pre class="lang-php prettyprint-override"><code>    $_SERVER['HTTP_HOST'] = "some.host.com";
  </code></pre>
  
  <p>None of this works, I always get the same error message.</p>
  
  <p>How could I fix this?</p>
  
  <hr>
  
  <h2>Notes</h2>
  
  <p><em>[everything given here is sanitized (passwords, hostnames, etc.) and some line breaks and indentation were added for readability]</em></p>
  
  <p>Just in case, my acceptance suite settings are as follows:</p>
  
  <pre class="lang-yml prettyprint-override"><code>class_name: AcceptanceTester
  modules:
      enabled:
          - Asserts
          - Db
          - Symfony2
          - Doctrine2
          - \Tests\Helper\Acceptance
  </code></pre>
  
  <p>And my Codeception settings:</p>
  
  <pre class="lang-yml prettyprint-override"><code>namespace: Tests
  actor: Tester
  paths:
      tests: tests
      log: tests/_output
      data: tests/_data
      support: tests/_support
      envs: tests/_envs
  settings:
      bootstrap: _bootstrap.php
      colors: true
      memory_limit: 1024M
  extensions:
      enabled: [ Codeception\Extension\RunFailed ]
  modules:
      config:
          Db:
              dsn: 'mysql:host=localhost;dbname=acme_test'
              user: 'root'
              password: 'blahblah'
              dump: 'tests/_data/dump.sql'
              populate: false
              cleanup: false
          Doctrine2:
              depends: Symfony2
              cleanup: false
          PhpBrowser:
              url: http://acme.com
          WebDriver:
               browser: firefox
               url: http://acme.com
          REST:
              depends: Symfony2
              url: http://acme.com
  </code></pre>
  
  <p>Here is the result of running the test with the <code>-vvv</code> flag:</p>
  
  <pre class="lang-none prettyprint-override"><code>$ bin/codecept run tests/acceptance/ExtranetBundle/Controller/DefaultControllerCest.php -vvv
  
  Codeception PHP Testing Framework v2.1.3
  Powered by PHPUnit 4.8.13 by Sebastian Bergmann and contributors.
  
  Tests.acceptance Tests (1) ---------------------------------------------------------------------------------------------------------------------------
  Modules: Asserts, Db, Symfony2, Doctrine2, \Tests\Helper\Acceptance
  ------------------------------------------------------------------------------------------------------------------------------------------------------
  Test something (Acceptance\ExtranetBundle\Controller\DefaultControllerCest::myTest)
  Scenario:
  * I am on route "acme_site_home.es"
  
  [Page] http://localhost/es
  [User] anon. []
  * I don't see "hello"
  FAIL
  
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  ------------------------------------------------------------------------------------------------------------------------------------------------------
  
  
  Time: 4.13 seconds, Memory: 65.75Mb
  
  There was 1 failure:
  
  ---------
  1) Failed to test something in Tests\Acceptance\ExtranetBundle\Controller\DefaultControllerCest::myTest (tests/acceptance/ExtranetBundle/Controller/DefaultControllerCest.php)
  
  Step  I don't see "hello"
  Fail  Failed asserting that   /es
  --&gt;
  
  Undefined index: localhost (500 Internal Server Error)
  
  [Content too long to display. See complete response in '_output' directory]
  --&gt; does not contain "hello".
  
  Scenario Steps:
  
  2. $I-&gt;dontSee("hello") at tests/acceptance/ExtranetBundle/Controller/DefaultControllerCest.php:15
  1. $I-&gt;amOnRoute("acme_site_home.es") at tests/acceptance/ExtranetBundle/Controller/DefaultControllerCest.php:14
  
  /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/phpunit/phpunit/src/Framework/Constraint/Not.php:100
  /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/phpunit/phpunit/src/Framework/Assert.php:2255
  /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/Util/Shared/Asserts.php:280
  /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/Lib/InnerBrowser.php:1263
  /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/Lib/InnerBrowser.php:284
  /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/Step.php:193
  /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/TestCase/Shared/Actor.php:99
  /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/Scenario.php:101
  /Volumes/Utilisateurs/marc/Sites/acme.com/tests/_support/_generated/AcceptanceTesterActions.php:831
  /Volumes/Utilisateurs/marc/Sites/acme.com/tests/acceptance/ExtranetBundle/Controller/DefaultControllerCest.php:15
  /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/Lib/Di.php:112
  /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/TestCase/Cest.php:127
  /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/TestCase/Cest.php:136
  /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/TestCase/Cest.php:66
  /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/phpunit/phpunit/src/Framework/TestCase.php:909
  /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/phpunit/phpunit/src/Framework/TestCase.php:768
  /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/phpunit/phpunit/src/Framework/TestResult.php:612
  /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/phpunit/phpunit/src/Framework/TestCase.php:724
  /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/phpunit/phpunit/src/Framework/TestSuite.php:747
  /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/PHPUnit/Runner.php:89
  /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/SuiteManager.php:153
  /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/Codecept.php:203
  /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/Codecept.php:172
  /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/Command/Run.php:184
  /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:259
  /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:878
  /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:195
  /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:126
  /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/codecept:28
  
  
  FAILURES!
  Tests: 1, Assertions: 1, Failures: 1.
  </code></pre>
  
  <p>And here is the error stack trace given by Symfony in the _output directory:</p>
  
  <pre class="lang-none prettyprint-override"><code>PHPUnit_Framework_Exception: Undefined index: localhost
  at n/a
  in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/Subscriber/ErrorHandler.php line 48
  
  at Codeception\Subscriber\ErrorHandler-&gt;errorHandler('8', 'Undefined index: localhost', '/Volumes/Utilisateurs/marc/Sites/acme.com/src/Acme/SiteBundle/Controller/DefaultController.php', '160', array(
      'request' =&gt; object(Request),
      'locale' =&gt; 'es',
      'registrationForm' =&gt; object(Form),
      'typeAppFb' =&gt; array(
          'acme.com' =&gt; array(
              'appId' =&gt; '123456789123456',
              'secret' =&gt; '123456789abcdef123456789abcdef12'
          ),
          'dev.acme.com' =&gt; array(
              'appId' =&gt; '123456789123456',
              'secret' =&gt; '123456789abcdef123456789abcdef12'
          ),
          'www.prod-acme.com' =&gt; array(
              'appId' =&gt; '123456789123456',
              'secret' =&gt; '123456789abcdef123456789abcdef12'
          )
      )
  ))
  in /Volumes/Utilisateurs/marc/Sites/acme.com/src/Acme/SiteBundle/Controller/DefaultController.php line 160
  
  at Acme\SiteBundle\Controller\DefaultController-&gt;homeAction(object(Request))
  in  line
  
  at call_user_func_array(array(object(DefaultController), 'homeAction'), array(object(Request)))
  in /Volumes/Utilisateurs/marc/Sites/acme.com/app/bootstrap.php.cache line 3109
  
  at Symfony\Component\HttpKernel\HttpKernel-&gt;handleRaw(object(Request), '1')
  in /Volumes/Utilisateurs/marc/Sites/acme.com/app/bootstrap.php.cache line 3071
  
  at Symfony\Component\HttpKernel\HttpKernel-&gt;handle(object(Request), '1', true)
  in /Volumes/Utilisateurs/marc/Sites/acme.com/app/bootstrap.php.cache line 3222
  
  at Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel-&gt;handle(object(Request), '1', true)
  in /Volumes/Utilisateurs/marc/Sites/acme.com/app/bootstrap.php.cache line 2444
  
  at Symfony\Component\HttpKernel\Kernel-&gt;handle(object(Request))
  in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Client.php line 81
  
  at Symfony\Component\HttpKernel\Client-&gt;doRequest(object(Request))
  in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/Lib/Connector/Symfony2.php line 38
  
  at Codeception\Lib\Connector\Symfony2-&gt;doRequest(object(Request))
  in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/symfony/symfony/src/Symfony/Component/BrowserKit/Client.php line 327
  
  at Symfony\Component\BrowserKit\Client-&gt;request('GET', '/es', array(), array(), array(), null, true)
  in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/Lib/InnerBrowser.php line 130
  
  at Codeception\Lib\InnerBrowser-&gt;clientRequest('GET', '/es', array(), array(), array(), null)
  in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/Lib/InnerBrowser.php line 159
  
  at Codeception\Lib\InnerBrowser-&gt;_loadPage('GET', '/es')
  in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/Lib/InnerBrowser.php line 203
  
  at Codeception\Lib\InnerBrowser-&gt;amOnPage('/es')
  in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/Module/Symfony2.php line 197
  
  at Codeception\Module\Symfony2-&gt;amOnRoute('acme_site_home.es')
  in  line
  
  at call_user_func_array(array(object(Symfony2), 'amOnRoute'), array('acme_site_home.es'))
  in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/Step.php line 193
  
  at Codeception\Step-&gt;run(object(ModuleContainer))
  in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/TestCase/Shared/Actor.php line 99
  
  at Codeception\TestCase\Cest-&gt;runStep(object(Condition))
  in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/Scenario.php line 101
  
  at Codeception\Scenario-&gt;runStep(object(Condition))
  in /Volumes/Utilisateurs/marc/Sites/acme.com/tests/_support/_generated/AcceptanceTesterActions.php line 579
  
  at Tests\AcceptanceTester-&gt;amOnRoute('acme_site_home.es')
  in /Volumes/Utilisateurs/marc/Sites/acme.com/tests/acceptance/ExtranetBundle/Controller/DefaultControllerCest.php line 14
  
  at Tests\Acceptance\ExtranetBundle\Controller\DefaultControllerCest-&gt;myTest(object(AcceptanceTester))
  in  line
  
  at ReflectionMethod-&gt;invokeArgs(object(DefaultControllerCest), array(object(AcceptanceTester)))
  in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/Lib/Di.php line 112
  
  at Codeception\Lib\Di-&gt;injectDependencies(object(DefaultControllerCest), 'myTest', array(object(AcceptanceTester), object(Scenario)))
  in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/TestCase/Cest.php line 127
  
  at Codeception\TestCase\Cest-&gt;invoke('myTest', array(object(AcceptanceTester), object(Scenario)))
  in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/TestCase/Cest.php line 136
  
  at Codeception\TestCase\Cest-&gt;executeTestMethod(object(AcceptanceTester))
  in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/TestCase/Cest.php line 66
  
  at Codeception\TestCase\Cest-&gt;testCodecept()
  in  line
  
  at ReflectionMethod-&gt;invokeArgs(object(Cest), array())
  in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/phpunit/phpunit/src/Framework/TestCase.php line 909
  
  at PHPUnit_Framework_TestCase-&gt;runTest()
  in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/phpunit/phpunit/src/Framework/TestCase.php line 768
  
  at PHPUnit_Framework_TestCase-&gt;runBare()
  in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/phpunit/phpunit/src/Framework/TestResult.php line 612
  
  at PHPUnit_Framework_TestResult-&gt;run(object(Cest))
  in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/phpunit/phpunit/src/Framework/TestCase.php line 724
  
  at PHPUnit_Framework_TestCase-&gt;run(object(PHPUnit_Framework_TestResult))
  in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/phpunit/phpunit/src/Framework/TestSuite.php line 747
  
  at PHPUnit_Framework_TestSuite-&gt;run(object(PHPUnit_Framework_TestResult))
  in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/PHPUnit/Runner.php line 89
  
  at Codeception\PHPUnit\Runner-&gt;doEnhancedRun(object(Suite), object(PHPUnit_Framework_TestResult), array(
      'silent' =&gt; false,
      'debug' =&gt; false,
      'steps' =&gt; false,
      'html' =&gt; false,
      'xml' =&gt; false,
      'json' =&gt; false,
      'tap' =&gt; false,
      'report' =&gt; false,
      'colors' =&gt; true,
      'coverage' =&gt; false,
      'coverage-xml' =&gt; false,
      'coverage-html' =&gt; false,
      'coverage-text' =&gt; false,
      'groups' =&gt; null,
      'excludeGroups' =&gt; null,
      'filter' =&gt; null,
      'env' =&gt; null,
      'fail-fast' =&gt; false,
      'verbosity' =&gt; '4',
      'interactive' =&gt; true,
      'no-rebuild' =&gt; false,
      'bootstrap' =&gt; '_bootstrap.php',
      'memory_limit' =&gt; '1024M',
      'log' =&gt; false,
      'strict_xml' =&gt; false,
      'verbose' =&gt; true
  ))
  in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/SuiteManager.php line 153
  
  at Codeception\SuiteManager-&gt;run(object(Runner), object(PHPUnit_Framework_TestResult), array(
      'silent' =&gt; false,
      'debug' =&gt; false,
      'steps' =&gt; false,
      'html' =&gt; false,
      'xml' =&gt; false,
      'json' =&gt; false,
      'tap' =&gt; false,
      'report' =&gt; false,
      'colors' =&gt; true,
      'coverage' =&gt; false,
      'coverage-xml' =&gt; false,
      'coverage-html' =&gt; false,
      'coverage-text' =&gt; false,
      'groups' =&gt; null,
      'excludeGroups' =&gt; null,
      'filter' =&gt; null,
      'env' =&gt; null,
      'fail-fast' =&gt; false,
      'verbosity' =&gt; '4',
      'interactive' =&gt; true,
      'no-rebuild' =&gt; false,
      'bootstrap' =&gt; '_bootstrap.php',
      'memory_limit' =&gt; '1024M',
      'log' =&gt; false,
      'strict_xml' =&gt; false,
      'verbose' =&gt; true
  ))
  in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/Codecept.php line 203
  
  at Codeception\Codecept-&gt;runSuite(array(
      'class_name' =&gt; 'AcceptanceTester',
          'modules' =&gt; array(
              'enabled' =&gt; array(
                  'Asserts',
                  'Db',
                  'Symfony2',
                  'Doctrine2',
                  '\Tests\Helper\Acceptance'
              ),
              'config' =&gt; array(
                  'Db' =&gt; array(
                      'dsn' =&gt; 'mysql:host=localhost;dbname=acme_test',
                      'user' =&gt; 'root',
                      'password' =&gt; 'blahblah',
                      'dump' =&gt; 'tests/_data/dump.sql',
                      'populate' =&gt; false,
                      'cleanup' =&gt; false
                  ),
                  'PhpBrowser' =&gt; array(
                      'url' =&gt; 'http://acme.com'
                  ),
                  'WebDriver' =&gt; array(
                      'url' =&gt; 'http://acme.com',
                      'browser' =&gt; 'firefox'
                  ),
                  'REST' =&gt; array(
                      'url' =&gt; 'http://acme.com',
                      'depends' =&gt; 'Symfony2'
                  ),
                  'Doctrine2' =&gt; array(
                      'depends' =&gt; 'Symfony2',
                      'cleanup' =&gt; false
                  )
              ),
              'depends' =&gt; array()
          ),
          'colors' =&gt; true,
          'bootstrap' =&gt; '_bootstrap.php',
          'memory_limit' =&gt; '1024M',
          'log' =&gt; false,
          'strict_xml' =&gt; false,
          'coverage' =&gt; array(),
          'namespace' =&gt; 'Tests',
          'groups' =&gt; array('failed' =&gt; 'tests/_output/failed'),
          'path' =&gt; '/Volumes/Utilisateurs/marc/Sites/acme.com/tests/acceptance/',
          'shuffle' =&gt; false,
          'error_level' =&gt; 'E_ALL &amp; ~E_STRICT &amp; ~E_DEPRECATED'
      ),
      'acceptance',
      'ExtranetBundle/Controller/DefaultControllerCest.php'
  )
  in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/Codecept.php line 172
  
  at Codeception\Codecept-&gt;run('acceptance', 'ExtranetBundle/Controller/DefaultControllerCest.php')
  in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/Command/Run.php line 184
  
  at Codeception\Command\Run-&gt;execute(object(ArgvInput), object(ConsoleOutput))
  in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php line 259
  
  at Symfony\Component\Console\Command\Command-&gt;run(object(ArgvInput), object(ConsoleOutput))
  in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php line 878
  
  at Symfony\Component\Console\Application-&gt;doRunCommand(object(Run), object(ArgvInput), object(ConsoleOutput))
  in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php line 195
  
  at Symfony\Component\Console\Application-&gt;doRun(object(ArgvInput), object(ConsoleOutput))
  in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php line 126
  
  at Symfony\Component\Console\Application-&gt;run()
  in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/codecept line 28
  </code></pre>