首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Symfony 2股票控制器测试失败,出现错误`未定义索引: HTTP_HOST`

Symfony 2股票控制器测试失败,出现错误`未定义索引: HTTP_HOST`
EN

Stack Overflow用户
提问于 2014-10-15 22:00:24
回答 1查看 732关注 0票数 0

我想知道是否有人对这个错误有解决方案。我刚刚在一个PhpUnit 2项目中设置了Doctrine 4.3.*和Doctrine Fixtures Bundle,当我运行bin/phpunit -c app/时,我得到了以下错误。这些是Symfony 2代码生成器自动生成的控制器测试,所以我认为嘿在任何情况下都应该通过/有效。我有预感,我的phpunit配置/安装可能有问题,但我不确定……

代码语言:javascript
复制
Project\AdminBundle\Tests\Controller\DefaultControllerTest::testIndex
Undefined index: HTTP_HOST

根据记录,我的composer.json是:

代码语言:javascript
复制
{
    "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"
        }
    }
}
EN

回答 1

Stack Overflow用户

发布于 2014-10-15 22:17:56

经过进一步的搜索,我发现我必须为phpunit.xml添加一个配置。为了子孙后代,我将回答我自己的问题。

创建一个phpunit.xml文件并复制phpunit.xml.dist的内容(如果有)。

要解决此问题,请添加

代码语言:javascript
复制
<php>
    <server name='HTTP_HOST' value='http://localhost' />
</php>

对刚创建的配置文件执行...to命令。

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

此问题与:PHPUnit error "undefined index : HTTP_HOST"重复

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26384484

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档