Symfony 4.4 deprecation warning for multiple clients in user test is deprecated, still present in documentation
Asked Answered
S

1

4

Symfony version(s) affected: 4.4.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.

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?

How to reproduce

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,
        ));
Sexy answered 9/1, 2020 at 22:15 Comment(1)
deprecation doesn't mean you can't use it. Unless you move to symfony 5, it won't matter.Heartstrings
D
12

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.

Devious answered 10/1, 2020 at 11:53 Comment(1)
This is very confusing as $kernel, once booted, has a shutdown-method, so you could be tempted using it like "$kernel->shutdown();" which obviously doesn't do the same as self::ensureKernelShutdown().Suburbanize

© 2022 - 2024 — McMap. All rights reserved.