0

I'm wondering if anyone has a solutions to this error. I have just set up PhpUnit 4.3.* and Doctrine Fixtures Bundle in a Symphony 2 project and when I run bin/phpunit -c app/ I get the following errors. These are controller test automatically generated by Symfony 2 code generator, so I figured hey should pass / be valid in any situation. I have a hunch there might be something wrong with my configuration / installation of phpunit, but I'm not sure...

Project\AdminBundle\Tests\Controller\DefaultControllerTest::testIndex
Undefined index: HTTP_HOST

For the record, my composer.json is :

{
    "name": "symfony/framework-standard-edition",
    "license": "MIT",
    "type": "project",
    "description": "The \"Symfony Standard Edition\" distribution",
    "autoload": {
        "psr-0": { "": "src/" }
    },
    "require": {
        "php": ">=5.3.3",
        "symfony/symfony": "2.3.*",
        "doctrine/orm": ">=2.2.3,<2.4-dev",
        "doctrine/doctrine-bundle": "1.2.*",
        "twig/extensions": "1.0.*",
        "symfony/assetic-bundle": "2.3.*",
        "symfony/swiftmailer-bundle": "2.3.*",
        "symfony/monolog-bundle": "2.3.*",
        "sensio/distribution-bundle": "2.3.*",
        "sensio/framework-extra-bundle": "2.3.*",
        "sensio/generator-bundle": "2.3.*",
        "incenteev/composer-parameter-handler": "~2.0",

        "dms/dms-filter-bundle": "*",
        "jms/i18n-routing-bundle": "1.1.*",
        "jms/translation-bundle": "1.1.*",
        "vmelnik/doctrine-encrypt-bundle": "dev-master",
        "doctrine/doctrine-fixtures-bundle": "2.2.*"
    },
    "require-dev": {
        "phpunit/phpunit": "4.3.*"
    },
    "scripts": {
        "post-install-cmd": [
            "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
        ],
        "post-update-cmd": [
            "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
        ]
    },
    "config": {
        "bin-dir": "bin"
    },
    "minimum-stability": "stable",
    "extra": {
        "symfony-app-dir": "app",
        "symfony-web-dir": "web",
        "incenteev-parameters": {
            "file": "app/config/parameters.yml"
        },
        "branch-alias": {
            "dev-master": "2.3-dev"
        }
    }
}
Victor S
  • 5,098
  • 5
  • 44
  • 62

1 Answers1

0

After some more searching around, I found out I had to add a config to phpunit.xml. For posterity, I will answer my own question.

Create a phpunit.xml file and copy the contents of phpunit.xml.dist, if you have one.

To fix the problem add

<php>
    <server name='HTTP_HOST' value='http://localhost' />
</php>

...to the configuration file you just created.

More information on phpunit configuration files: http://www.testically.org/2010/08/24/best-practice-how-to-ship-phpunit-configuration/

This question is a duplicate of: PHPUnit error "undefined index : HTTP_HOST"

Community
  • 1
  • 1
Victor S
  • 5,098
  • 5
  • 44
  • 62