- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
-6ren">
我使用 Codeception 及其 Symfony2 模块进行了这个非常简单的验收测试:
public function myTest(AcceptanceTester $I)
{
$I->wantTo('test something');
$I->amOnRoute("acme_site_home.es");
$I->dontSee('hello');
}
当我运行它时,我得到一个 Undefined index: localhost
PHPUnit_Framework_Exception,这是由在我的路由中调用 $request->server->get("HTTP_HOST")
触发的行动。
我已经尝试过以下方法:
<phpunit>
<php>
<server name='HTTP_HOST' value='http://some.host.com' />
</php>
</phpunit>
$_SERVER['HOST_NAME'] = "some.host.com";
$_SERVER['HTTP_HOST'] = "some.host.com";
这些都不起作用,我总是收到相同的错误消息。
我该如何解决这个问题?
[此处给出的所有内容都经过清理(密码、主机名等)并添加了一些换行符和缩进以提高可读性]
为了以防万一,我的验收套件设置如下:
class_name: AcceptanceTester
modules:
enabled:
- Asserts
- Db
- Symfony2
- Doctrine2
- \Tests\Helper\Acceptance
还有我的 Codeception 设置:
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
这是使用 -vvv
标志运行测试的结果:
$ bin/codecept run tests/acceptance/ExtranetBundle/Controller/DefaultControllerCest.php -vvv
Codeception PHP Testing Framework v2.1.3
Powered by PHPUnit 4.8.13 by Sebastian Bergmann and contributors.
Tests.acceptance Tests (1) ---------------------------------------------------------------------------------------------------------------------------
Modules: Asserts, Db, Symfony2, Doctrine2, \Tests\Helper\Acceptance
------------------------------------------------------------------------------------------------------------------------------------------------------
Test something (Acceptance\ExtranetBundle\Controller\DefaultControllerCest::myTest)
Scenario:
* I am on route "acme_site_home.es"
[Page] http://localhost/es
[User] anon. []
* I don't see "hello"
FAIL
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
------------------------------------------------------------------------------------------------------------------------------------------------------
Time: 4.13 seconds, Memory: 65.75Mb
There was 1 failure:
---------
1) Failed to test something in Tests\Acceptance\ExtranetBundle\Controller\DefaultControllerCest::myTest (tests/acceptance/ExtranetBundle/Controller/DefaultControllerCest.php)
Step I don't see "hello"
Fail Failed asserting that /es
-->
Undefined index: localhost (500 Internal Server Error)
[Content too long to display. See complete response in '_output' directory]
--> does not contain "hello".
Scenario Steps:
2. $I->dontSee("hello") at tests/acceptance/ExtranetBundle/Controller/DefaultControllerCest.php:15
1. $I->amOnRoute("acme_site_home.es") at tests/acceptance/ExtranetBundle/Controller/DefaultControllerCest.php:14
/Volumes/Utilisateurs/marc/Sites/acme.com/vendor/phpunit/phpunit/src/Framework/Constraint/Not.php:100
/Volumes/Utilisateurs/marc/Sites/acme.com/vendor/phpunit/phpunit/src/Framework/Assert.php:2255
/Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/Util/Shared/Asserts.php:280
/Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/Lib/InnerBrowser.php:1263
/Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/Lib/InnerBrowser.php:284
/Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/Step.php:193
/Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/TestCase/Shared/Actor.php:99
/Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/Scenario.php:101
/Volumes/Utilisateurs/marc/Sites/acme.com/tests/_support/_generated/AcceptanceTesterActions.php:831
/Volumes/Utilisateurs/marc/Sites/acme.com/tests/acceptance/ExtranetBundle/Controller/DefaultControllerCest.php:15
/Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/Lib/Di.php:112
/Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/TestCase/Cest.php:127
/Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/TestCase/Cest.php:136
/Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/TestCase/Cest.php:66
/Volumes/Utilisateurs/marc/Sites/acme.com/vendor/phpunit/phpunit/src/Framework/TestCase.php:909
/Volumes/Utilisateurs/marc/Sites/acme.com/vendor/phpunit/phpunit/src/Framework/TestCase.php:768
/Volumes/Utilisateurs/marc/Sites/acme.com/vendor/phpunit/phpunit/src/Framework/TestResult.php:612
/Volumes/Utilisateurs/marc/Sites/acme.com/vendor/phpunit/phpunit/src/Framework/TestCase.php:724
/Volumes/Utilisateurs/marc/Sites/acme.com/vendor/phpunit/phpunit/src/Framework/TestSuite.php:747
/Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/PHPUnit/Runner.php:89
/Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/SuiteManager.php:153
/Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/Codecept.php:203
/Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/Codecept.php:172
/Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/Command/Run.php:184
/Volumes/Utilisateurs/marc/Sites/acme.com/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:259
/Volumes/Utilisateurs/marc/Sites/acme.com/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:878
/Volumes/Utilisateurs/marc/Sites/acme.com/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:195
/Volumes/Utilisateurs/marc/Sites/acme.com/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:126
/Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/codecept:28
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
这是 Symfony 在 _output 目录中给出的错误堆栈跟踪:
PHPUnit_Framework_Exception: Undefined index: localhost
at n/a
in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/Subscriber/ErrorHandler.php line 48
at Codeception\Subscriber\ErrorHandler->errorHandler('8', 'Undefined index: localhost', '/Volumes/Utilisateurs/marc/Sites/acme.com/src/Acme/SiteBundle/Controller/DefaultController.php', '160', array(
'request' => object(Request),
'locale' => 'es',
'registrationForm' => object(Form),
'typeAppFb' => array(
'acme.com' => array(
'appId' => '123456789123456',
'secret' => '123456789abcdef123456789abcdef12'
),
'dev.acme.com' => array(
'appId' => '123456789123456',
'secret' => '123456789abcdef123456789abcdef12'
),
'www.prod-acme.com' => array(
'appId' => '123456789123456',
'secret' => '123456789abcdef123456789abcdef12'
)
)
))
in /Volumes/Utilisateurs/marc/Sites/acme.com/src/Acme/SiteBundle/Controller/DefaultController.php line 160
at Acme\SiteBundle\Controller\DefaultController->homeAction(object(Request))
in line
at call_user_func_array(array(object(DefaultController), 'homeAction'), array(object(Request)))
in /Volumes/Utilisateurs/marc/Sites/acme.com/app/bootstrap.php.cache line 3109
at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), '1')
in /Volumes/Utilisateurs/marc/Sites/acme.com/app/bootstrap.php.cache line 3071
at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), '1', true)
in /Volumes/Utilisateurs/marc/Sites/acme.com/app/bootstrap.php.cache line 3222
at Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle(object(Request), '1', true)
in /Volumes/Utilisateurs/marc/Sites/acme.com/app/bootstrap.php.cache line 2444
at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Client.php line 81
at Symfony\Component\HttpKernel\Client->doRequest(object(Request))
in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/Lib/Connector/Symfony2.php line 38
at Codeception\Lib\Connector\Symfony2->doRequest(object(Request))
in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/symfony/symfony/src/Symfony/Component/BrowserKit/Client.php line 327
at Symfony\Component\BrowserKit\Client->request('GET', '/es', array(), array(), array(), null, true)
in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/Lib/InnerBrowser.php line 130
at Codeception\Lib\InnerBrowser->clientRequest('GET', '/es', array(), array(), array(), null)
in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/Lib/InnerBrowser.php line 159
at Codeception\Lib\InnerBrowser->_loadPage('GET', '/es')
in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/Lib/InnerBrowser.php line 203
at Codeception\Lib\InnerBrowser->amOnPage('/es')
in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/Module/Symfony2.php line 197
at Codeception\Module\Symfony2->amOnRoute('acme_site_home.es')
in line
at call_user_func_array(array(object(Symfony2), 'amOnRoute'), array('acme_site_home.es'))
in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/Step.php line 193
at Codeception\Step->run(object(ModuleContainer))
in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/TestCase/Shared/Actor.php line 99
at Codeception\TestCase\Cest->runStep(object(Condition))
in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/Scenario.php line 101
at Codeception\Scenario->runStep(object(Condition))
in /Volumes/Utilisateurs/marc/Sites/acme.com/tests/_support/_generated/AcceptanceTesterActions.php line 579
at Tests\AcceptanceTester->amOnRoute('acme_site_home.es')
in /Volumes/Utilisateurs/marc/Sites/acme.com/tests/acceptance/ExtranetBundle/Controller/DefaultControllerCest.php line 14
at Tests\Acceptance\ExtranetBundle\Controller\DefaultControllerCest->myTest(object(AcceptanceTester))
in line
at ReflectionMethod->invokeArgs(object(DefaultControllerCest), array(object(AcceptanceTester)))
in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/Lib/Di.php line 112
at Codeception\Lib\Di->injectDependencies(object(DefaultControllerCest), 'myTest', array(object(AcceptanceTester), object(Scenario)))
in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/TestCase/Cest.php line 127
at Codeception\TestCase\Cest->invoke('myTest', array(object(AcceptanceTester), object(Scenario)))
in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/TestCase/Cest.php line 136
at Codeception\TestCase\Cest->executeTestMethod(object(AcceptanceTester))
in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/TestCase/Cest.php line 66
at Codeception\TestCase\Cest->testCodecept()
in line
at ReflectionMethod->invokeArgs(object(Cest), array())
in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/phpunit/phpunit/src/Framework/TestCase.php line 909
at PHPUnit_Framework_TestCase->runTest()
in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/phpunit/phpunit/src/Framework/TestCase.php line 768
at PHPUnit_Framework_TestCase->runBare()
in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/phpunit/phpunit/src/Framework/TestResult.php line 612
at PHPUnit_Framework_TestResult->run(object(Cest))
in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/phpunit/phpunit/src/Framework/TestCase.php line 724
at PHPUnit_Framework_TestCase->run(object(PHPUnit_Framework_TestResult))
in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/phpunit/phpunit/src/Framework/TestSuite.php line 747
at PHPUnit_Framework_TestSuite->run(object(PHPUnit_Framework_TestResult))
in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/PHPUnit/Runner.php line 89
at Codeception\PHPUnit\Runner->doEnhancedRun(object(Suite), object(PHPUnit_Framework_TestResult), array(
'silent' => false,
'debug' => false,
'steps' => false,
'html' => false,
'xml' => false,
'json' => false,
'tap' => false,
'report' => false,
'colors' => true,
'coverage' => false,
'coverage-xml' => false,
'coverage-html' => false,
'coverage-text' => false,
'groups' => null,
'excludeGroups' => null,
'filter' => null,
'env' => null,
'fail-fast' => false,
'verbosity' => '4',
'interactive' => true,
'no-rebuild' => false,
'bootstrap' => '_bootstrap.php',
'memory_limit' => '1024M',
'log' => false,
'strict_xml' => false,
'verbose' => true
))
in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/SuiteManager.php line 153
at Codeception\SuiteManager->run(object(Runner), object(PHPUnit_Framework_TestResult), array(
'silent' => false,
'debug' => false,
'steps' => false,
'html' => false,
'xml' => false,
'json' => false,
'tap' => false,
'report' => false,
'colors' => true,
'coverage' => false,
'coverage-xml' => false,
'coverage-html' => false,
'coverage-text' => false,
'groups' => null,
'excludeGroups' => null,
'filter' => null,
'env' => null,
'fail-fast' => false,
'verbosity' => '4',
'interactive' => true,
'no-rebuild' => false,
'bootstrap' => '_bootstrap.php',
'memory_limit' => '1024M',
'log' => false,
'strict_xml' => false,
'verbose' => true
))
in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/Codecept.php line 203
at Codeception\Codecept->runSuite(array(
'class_name' => 'AcceptanceTester',
'modules' => array(
'enabled' => array(
'Asserts',
'Db',
'Symfony2',
'Doctrine2',
'\Tests\Helper\Acceptance'
),
'config' => array(
'Db' => array(
'dsn' => 'mysql:host=localhost;dbname=acme_test',
'user' => 'root',
'password' => 'blahblah',
'dump' => 'tests/_data/dump.sql',
'populate' => false,
'cleanup' => false
),
'PhpBrowser' => array(
'url' => 'http://acme.com'
),
'WebDriver' => array(
'url' => 'http://acme.com',
'browser' => 'firefox'
),
'REST' => array(
'url' => 'http://acme.com',
'depends' => 'Symfony2'
),
'Doctrine2' => array(
'depends' => 'Symfony2',
'cleanup' => false
)
),
'depends' => array()
),
'colors' => true,
'bootstrap' => '_bootstrap.php',
'memory_limit' => '1024M',
'log' => false,
'strict_xml' => false,
'coverage' => array(),
'namespace' => 'Tests',
'groups' => array('failed' => 'tests/_output/failed'),
'path' => '/Volumes/Utilisateurs/marc/Sites/acme.com/tests/acceptance/',
'shuffle' => false,
'error_level' => 'E_ALL & ~E_STRICT & ~E_DEPRECATED'
),
'acceptance',
'ExtranetBundle/Controller/DefaultControllerCest.php'
)
in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/Codecept.php line 172
at Codeception\Codecept->run('acceptance', 'ExtranetBundle/Controller/DefaultControllerCest.php')
in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/src/Codeception/Command/Run.php line 184
at Codeception\Command\Run->execute(object(ArgvInput), object(ConsoleOutput))
in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php line 259
at Symfony\Component\Console\Command\Command->run(object(ArgvInput), object(ConsoleOutput))
in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php line 878
at Symfony\Component\Console\Application->doRunCommand(object(Run), object(ArgvInput), object(ConsoleOutput))
in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php line 195
at Symfony\Component\Console\Application->doRun(object(ArgvInput), object(ConsoleOutput))
in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php line 126
at Symfony\Component\Console\Application->run()
in /Volumes/Utilisateurs/marc/Sites/acme.com/vendor/codeception/codeception/codecept line 28
最佳答案
这是一个双方面的问题:
代码没有很好地处理未知域并发出警告,PhpUnit 将警告转换为异常。
要测试对特定域的请求,您必须向该域发出请求,例如$I->amOnPage('http://acme.com/es');
。由于您使用的是 Symfony2 模块,它不会向该站点发出实际的 HTTP 请求,而是在内部处理它。如果您使用的是 amOnRoute()
方法,请确保路由生成的 url 包含主机名部分。
附言我不知道网站包是如何工作的,但我建议至少为该域设置一个基于主机名的路由,否则您的测试可能会停止使用 future 版本的 Codeception。
关于symfony - "Undefined index: localhost"使用 Symfony2 模块的 Codeception 中的 PHPUnit 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33963012/
我开始从事一个用 Symfony 2.8 编写的大型项目。将整个项目升级到 SF 3 需要数百小时,现在还不可能。我想到了一个想法,将 symfony/symfony 包解压到它替换的单个包中(com
我在提交表单后使用 FOSUserEvents,但订阅者调用了两次。 这样我的验证码第一次有效第二次无效 这是我的代码 router = $router; $this->request
我有以下路线: blog_show: path: /test/123 defaults: { _controller: TotalcanBravofillBundle:Te
我是测试新手。我想测试我的功能。我已经成功安装了 phpUnit。我在互联网上查看了许多教程。但我无法获得有关测试的正确信息。这是我的功能代码: public function loginAction
我正在尝试重现 facebook batch requests 的行为在他们的图形 api 上运行。 所以我认为最简单的解决方案是在 Controller 上向我的应用程序发出几个请求,例如: pub
在 Symfony Progress Bar documentation有一个超酷酒吧的示例图像。不幸的是,看起来文档的其余部分没有解释如何获得这样的结果。 这是图片,以防您错过: 我怎么才能得到它?
我使用Finder发送假脱机电子邮件,但是自动名称生成器将点放在文件名中,有时它们出现在文件的开头。 查找程序似乎无法获取具有该名称的文件-那些文件被隐藏了……有人经历过这种行为吗?有什么建议如何使用
我正在尝试进行 LDAP 身份验证,我目前遇到此类错误: ServiceNotFoundException: The service "security.firewall.map.context.ma
有没有办法验证和检查集合数组是否为空。我已经尝试过: /** * @Assert\NotBlank() * @Assert\Length( min = 1) */ protected $work
使用Smyfony2和Doctrin2,可以使用以下示例创建数据固定装置:http://symfony.com/doc/current/bundles/DoctrineFixturesBundle/i
我看到在大多数Symfony 2示例中,例如,不存在记录时,Symfony 2会引发异常。我认为这种方法对最终用户不友好。为什么有人更喜欢引发异常而不在Flashbag上添加一些错误消息? 最佳答案
我对项目中的以下服务有疑问: app.security.guardAuthenticatorLoginPassword: class: AppBundle\Security\LoginPa
symfony缓存和登录Docker容器存在问题。 Web服务器从www-data用户和组执行,当我使用docker上安装的php从docker容器中清除symfony缓存时,它从root执行。 因此
我想了解 symfony 中的服务 我已阅读http://symfony.com/doc/2.3/book/service_container.html#creating-configuring-se
因为我对 Symfony 和 Doctrine 还很陌生,所以我有一个可能很愚蠢的问题;-) 有人可以用简单的词语向我解释集合(尤其是实体中的ArrayCollections)吗?它是什么以及何时以及
我收到了这个表格: {{ form_start(form) }} {{ form_end(form) }} 我想检查用户是否登录,我这样做了: {% if is_g
我的网站已准备好部署,我正在尝试将其设置为在线。 一些信息: 主持人是 OVH。 它不允许 SSH,我必须使用 FTP 发送文件。也没有命令行。 我现在希望能够在子目录中设置网站:/www/test(
过去几个月以来,我一直在尝试与symfony合作。昨晚我自动删除了不需要的存储库。之后,我无法使用symfony命令创建新的symfony项目。当我在终端中运行Symfony new Security
In the environnement variable, then in system variable, I edited the path and added在环境变量中,然后在系统变量
我们有一个 Symfony 1.4 应用程序,想升级到 Symfony 4。是否有可能或者我们必须重新编程该应用程序? 我们询问了我们附近的一家软件公司,他们告诉我们必须重新编写应用程序。 最佳答案
我是一名优秀的程序员,十分优秀!