Php 测试失败,请使用“测试失败”;在调用";之前引导内核\WebTestCase::createClient();不支持

Php 测试失败,请使用“测试失败”;在调用";之前引导内核\WebTestCase::createClient();不支持,php,symfony,testing,Php,Symfony,Testing,在Symfony 5.0.5和5.0.8之间的某个位置,异常 LogicException:在调用之前引导内核 “Symfony\Bundle\FrameworkBundle\Test\WebTestCase::createClient()”是 不支持,内核只应启动一次 是生成的。在5.05中,以下所示的试验通过。更新至5.08后,测试失败。虽然例外情况出现在SO中,但答案确实解决了当前问题。为了让5.08通过此测试和类似测试,缺少了什么 namespace App\Tests\Controll

在Symfony 5.0.5和5.0.8之间的某个位置,异常

LogicException:在调用之前引导内核 “Symfony\Bundle\FrameworkBundle\Test\WebTestCase::createClient()”是 不支持,内核只应启动一次

是生成的。在5.05中,以下所示的试验通过。更新至5.08后,测试失败。虽然例外情况出现在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());
    }
...
}
namespace-App\Tests\Controller;
使用Liip\TestFixturesBundle\Test\FixturesBundle;
使用Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
类AdminControllerTest扩展WebTestCase
{
使用固定器;
公用函数设置():无效
{
$this->fixtures=$this->loadFixtures([
'应用程序\数据装置\测试\选项装置',
'应用程序\数据装置\测试\非营利装置',
'App\DataFixtures\Test\UserFixture',
])
->getReferencePository();
$this->client=static::createClient();//client->followRedirects();
$this->client->request('GET','/login');
$this->client->submitForm('登录'[
'电子邮件'=>'admin@bogus.info',
“密码”=>“123Abc”,
]);
}
公共函数testLogin()
{
$this->client->request('GET','/admin/dashboard');
$this->assertEquals(200,$this->client->getResponse()->getStatusCode());
}
...
}

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

在以下块之前:

$this->fixtures = $this->loadFixtures([
        'App\DataFixtures\Test\OptionsFixture',
        'App\DataFixtures\Test\NonprofitFixture',
        'App\DataFixtures\Test\UserFixture',
    ])
    ->getReferenceRepository(); 
如果内核尚未启动,则加载装置正在启动内核。如果你先启动它,它就不会启动了


它可能不应该在Symfony 5.05中工作,也不知道它为什么会通过。

谢谢。移动块允许进行不需要任何夹具就能通过的测试。不幸的是,测试类中的其他测试失败,因为夹具似乎没有加载。再次阅读Liip文档,我得到的印象是,客户端和夹具代码应该在每个测试中,而不是在
setup()
中。答案被接受,因为它解决了所提出的问题。虽然答案还带来了其他问题,但这是另一个问题。每次测试之前都应该调用setup(),因此我怀疑这是否是问题所在。可能会覆盖分解方法,以便不移除固定装置,运行其中一个测试,然后查看是否填充了数据库。