簡體   English   中英

Symfony 2股票控制器測試失敗,錯誤為“未定義索引:HTTP_HOST”

[英]Symfony 2 stock controller tests fail with error `Undefined index: HTTP_HOST`

我想知道是否有人對此錯誤有解決方案。 我剛剛在Symphony 2項目中設置了PhpUnit 4.3。*和Doctrine Fixtures Bundle,當我運行bin/phpunit -c app/ ,出現以下錯誤。 這些是由Symfony 2代碼生成器自動生成的控制器測試,因此我認為在任何情況下都應該通過/有效。 我有一種預感,我的phpunit配置/安裝可能有問題,但是我不確定...

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

作為記錄,我的composer.json是:

{
    "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"
        }
    }
}

經過更多搜索后,我發現我必須向phpunit.xml添加配置。 對於后代,我將回答我自己的問題。

創建phpunit.xml文件,復制的內容phpunit.xml.dist ,如果你有一個。

要解決此問題,請添加

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

...到您剛創建的配置文件。

有關phpunit配置文件的更多信息: http : //www.testically.org/2010/08/24/best-practice-how-to-ship-phpunit-configuration/

這個問題是重復的: PHPUnit錯誤“未定義的索引:HTTP_HOST”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM