vendredi 27 novembre 2015

"Undefined index: localhost" PHPUnit exception in Codeception with Symfony2 module

I've got this very simple acceptance test using Codeception and its Symfony2 module:

public function myTest(AcceptanceTester $I)
{
    $I->wantTo('test something');
    $I->amOnRoute("acme_site_home.es");
    $I->dontSee('hello');
}

When I run it I get an Undefined index: localhost PHPUnit_Framework_Exception triggered by a call to $request->server->get("HTTP_HOST") in my route action.

I already tried the following:

  • Adding this to phpunit.xml:
    <phpunit>
        <php>
            <server name='HTTP_HOST' value='http://some.host.com' />
        </php>
    </phpunit>

  • Adding this to my test:
    $_SERVER['HOST_NAME'] = "some.host.com";

  • Adding this to my test:
    $_SERVER['HTTP_HOST'] = "some.host.com";

None of this works, I always get the same error message.

How could I fix this?


Notes

Just in case, my acceptance suite settings are as follows:

class_name: AcceptanceTester
modules:
    enabled:
        - Asserts
        - Db
        - Symfony2
        - Doctrine2
        - \Tests\Helper\Acceptance

And my Codeception settings:

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

Aucun commentaire:

Enregistrer un commentaire