繁体   English   中英

测试失败,并显示“在调用“...\WebTestCase::createClient()”之前启动 kernel 不受支持

[英]Testing fails with “Booting the kernel before calling ”…\WebTestCase::createClient()" is not supported

Symfony 5.0.5 和 5.0.8 之间的某处异常

LogicException:不支持在调用“Symfony\Bundle\FrameworkBundle\Test\WebTestCase::createClient()”之前启动 kernel,kernel 应该只启动一次。

生成。 在 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());
    }
...
}

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

在以下块之前:

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

如果 kernel 尚未启动,则负载夹具正在启动它。 如果你先启动它,它就不会这样做。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM