簡體   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