配置模拟会话时,使用本机会话的phpunit webtestcase,Symfony 5
在运行Symfony的样本烟雾测试URL示例时,我会得到“无法启动会话”, https://symfony.com/doc/5.3/best_practices.html#smoke-test-test-your-urls
<?php
namespace App\Tests;
use Generator;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class ApplicationAvailabilityFunctionalTest extends WebTestCase
{
/**
* @dataProvider urlProvider
*/
public function testPageIsSuccessful($url)
{
$client = self::createClient();
$client->request('GET', $url);
$this->assertResponseIsSuccessful();
}
public function urlProvider(): Generator
{
yield ['/'];
}
}
我在我的配置中配置了模拟序列/packages/framework.yaml文件。在配置/软件包/测试文件夹中没有其他替代。
when@test:
framework:
test: true
session:
storage_factory_id: session.storage.factory.mock_file
phpunit.xml.dist文件具有为“测试”环境指定的适当环境。
&lt; server name =“ app_env” value =“ test” test force =“ true”/&gt;
无论我是在phpstorm中执行测试表还是通过php bin/of Console执行测试表格没有区别phpunit
。我必须缺少配置。有什么想法吗?
I am getting the "Failed to start the session because headers have already been sent" error when running the sample smoke test url example from Symfony, https://symfony.com/doc/5.3/best_practices.html#smoke-test-your-urls
<?php
namespace App\Tests;
use Generator;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class ApplicationAvailabilityFunctionalTest extends WebTestCase
{
/**
* @dataProvider urlProvider
*/
public function testPageIsSuccessful($url)
{
$client = self::createClient();
$client->request('GET', $url);
$this->assertResponseIsSuccessful();
}
public function urlProvider(): Generator
{
yield ['/'];
}
}
I have configured mock sessions in my config/packages/framework.yaml file. There are no other overrides in the config/packages/test folder.
when@test:
framework:
test: true
session:
storage_factory_id: session.storage.factory.mock_file
The phpunit.xml.dist file has the appropriate environment specified for the "test" environment.
<server name="APP_ENV" value="test" force="true" />
It makes no difference whether I execute the test form within PHPStorm or from console via php bin/phpunit
. I must be missing something with the configuration. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
回答了我自己的问题,但是@dbrumann让我朝着活动的侦听器提示朝着正确的方向前进。谢谢,
我添加了Services.yaml,事件听众仅适用于非测试环境。
Answered my own question, but @dbrumann had me heading in the right direction with the event listener hint. Thanks
I added to services.yaml, the event listeners only for non-test environments.