不建议在用户测试中使用多个客户端的Symfony 4.4弃用警告,仍在文档中提供 [英] Symfony 4.4 deprecation warning for multiple clients in user test is deprecated, still present in documentation

查看:141
本文介绍了不建议在用户测试中使用多个客户端的Symfony 4.4弃用警告,仍在文档中提供的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

受影响的Symfony版本:4.4.0

说明

升级到Symfony 4.4.0之后,我收到了以下弃用警告:
自Symfony 4.4起,在引导内核时不赞成调用 Symfony\Bundle\FrameworkBundle\Test\WebTestCase :: createClient()。并将抛出5.0,请确保在调用该方法之前关闭内核。

Description
After upgrading to Symfony 4.4.0 I got the following deprecation warning: Calling "Symfony\Bundle\FrameworkBundle\Test\WebTestCase::createClient()" while a kernel has been booted is deprecated since Symfony 4.4 and will throw in 5.0, ensure the kernel is shut down before calling the method.

但是,我的操作与文档中的操作相同( https://symfony.com/doc/current/testing/insulating_clients.html ),这还可以相同的弃用警告。没有明确的选择,是文档已过时还是错误?

However, I do the same as in the documentation (https://symfony.com/doc/current/testing/insulating_clients.html), this also gives the same deprecation warning. There is no clear alternative, is the documentation outdated or is this a bug?

如何复制

class PagesTestCase extends WebTestCase {
     ...
     public function setUp(): void {
        parent::setUp();
        ...
        // Create clients
        self::$anonymousClient = self::createClient(array(), array(
            'HTTPS' => true,
        ));
        self::$userClient = self::createClient(array(), array(
            'PHP_AUTH_USER' => self::get('anonymous')->getUsername(),
            'PHP_AUTH_PW' => '***',
            'HTTPS' => true,
        ));
        self::$adminClient = self::createClient(array(), array(
            'PHP_AUTH_USER' => self::get('testuser')->getUsername(),
            'PHP_AUTH_PW' => '***',
            'HTTPS' => true,
        ));


推荐答案

您需要关闭内核。
WebTestCase扩展了KernelTestCase ,它提供了静态方法 self :: ensureKernelShutdown()

You need to shutdown the kernel. WebTestCase extends KernelTestCase, which provides a static method self::ensureKernelShutdown().

在创建客户端之前调用此命令。

Call this before creating the clients.

文档中的确仍然缺少此内容。

This is indeed still missing from the documentation.

这篇关于不建议在用户测试中使用多个客户端的Symfony 4.4弃用警告,仍在文档中提供的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆