为了账号安全,请及时绑定邮箱和手机立即绑定

测试失败并显示“不支持在调用“...\WebTestCase::createClient()

测试失败并显示“不支持在调用“...\WebTestCase::createClient()

PHP
慕容3067478 2023-04-15 16:40:21
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());    }...}
查看完整描述

1 回答

?
墨色风雨

TA贡献1853条经验 获得超6个赞

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


在以下块之前:


$this->fixtures = $this->loadFixtures([

        'App\DataFixtures\Test\OptionsFixture',

        'App\DataFixtures\Test\NonprofitFixture',

        'App\DataFixtures\Test\UserFixture',

    ])

    ->getReferenceRepository(); 

load fixtures 正在引导内核,如果它还没有被引导的话。如果您先启动它,则它不会执行此操作。


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


查看完整回答
反对 回复 2023-04-15
  • 1 回答
  • 0 关注
  • 90 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信