会话在 MockArraySessionStorage.php:127 开始后无法设置会话 ID

Cannot set session ID after the session has started at MockArraySessionStorage.php:127

我想通过功能测试来测试表单。 填写表格然后提交后,显示以下错误消息:

[2020-06-11 17:45:32] request.CRITICAL:未捕获 PHP 异常 LogicException:"Cannot set session ID after the session has started." 在 /var/www/renault-del/del/src/vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/Session/Storage/MockArraySessionStorage。php line 127 {"exception":"[object] (LogicException(code: 0): 会话启动后无法设置会话 ID。在 /var/www/renault-del/del/src/vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/Session/Storage/MockArraySessionStorage.php:127) "} []

有关信息,这是我用来提交表格的脚本:

class CmsBlockControllerTest extends WebTestCase
{


    /** @var Client */
    private $client;

    protected function setUp()
    {
        parent::setUp();

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


    }



    public function testNewAction(): void
    {

        $crawler = $this->client->request(
            'GET',
            $this->generateRoute('delbackoffice_cms_block_new') // my own function to generate a route
        );


        $form = $crawler->selectButton('Enregistrer')
            ->form([
                'block[title]' => 'title',
                'block[identifier]' => 'identifier',
                'block[content]' => 'content']);

         $this->client->submit($form);

    }

    protected function tearDown()
    {
        parent::tearDown();

        $this->client = null;
        $this->tokenStorage = null;
        $this->globalVariables = null;
    }
}

提前谢谢你

过了一会儿,我通过在 test.client.class 上调用 disableReboot 找到了解决方案 link : Solution here

因此,我在创建客户端后添加了 $this->client->disableReboot();。所以它起作用了:)