【问题标题】:Symfony 2 stock controller tests fail with error `Undefined index: HTTP_HOST`Symfony 2 库存控制器测试失败并出现错误“未定义索引:HTTP_HOST”
【发布时间】:2014-12-10 15:27:56
【问题描述】:

我想知道是否有人对此错误有解决方案。我刚刚在 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"
        }
    }
}

【问题讨论】:

    标签: php symfony phpunit symfony-2.3


    【解决方案1】:

    经过一番搜索,我发现我必须向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 error "undefined index : HTTP_HOST"

    【讨论】:

      猜你喜欢
      • 2013-09-18
      • 1970-01-01
      • 2013-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-23
      • 2022-01-25
      • 2015-09-19
      相关资源
      最近更新 更多