gpt4 book ai didi

php - 测试失败,显示 "Booting the kernel before calling "...\WebTestCase::createClient()"不受支持

转载 作者:行者123 更新时间:2023-12-05 05:02:46 33 4
gpt4 key购买 nike

Symfony 5.0.5 和 5.0.8 之间的某个地方是异常(exception)

LogicException: Booting the kernel before calling "Symfony\Bundle\FrameworkBundle\Test\WebTestCase::createClient()" is not supported, the kernel should only be booted once.

生成。在 5.05 中,下面显示的测试通过了。更新到 5.08 后测试失败。而异常出现elsewhere在 SO 中,答案确实解决了当前的问题。为了让 5.08 通过这个和类似的测试,还缺少什么?

namespace App\Tests\Controller;

use Liip\TestFixturesBundle\Test\FixturesTrait;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class AdminControllerTest extends WebTestCase
{
use FixturesTrait;

public function setup(): void
{
$this->fixtures = $this->loadFixtures([
'App\DataFixtures\Test\OptionsFixture',
'App\DataFixtures\Test\NonprofitFixture',
'App\DataFixtures\Test\UserFixture',
])
->getReferenceRepository();
$this->client = static::createClient(); // <-- this line causes failure
$this->client->followRedirects();
$this->client->request('GET', '/login');
$this->client->submitForm('Sign in', [
'email' => 'admin@bogus.info',
'password' => '123Abc',
]);
}

public function testLogin()
{
$this->client->request('GET', '/admin/dashboard');

$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
}
...
}

最佳答案

移动行 $this->client = static::createClient();

在以下 block 之前:

$this->fixtures = $this->loadFixtures([
'App\DataFixtures\Test\OptionsFixture',
'App\DataFixtures\Test\NonprofitFixture',
'App\DataFixtures\Test\UserFixture',
])
->getReferenceRepository();

load fixtures 正在引导内核,如果它还没有被引导的话。如果您先启动它,那么它不会这样做。

它可能不应该在 Symfony 5.05 中工作并且不确定它为什么会通过。

关于php - 测试失败,显示 "Booting the kernel before calling "...\WebTestCase::createClient()"不受支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61965329/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com