Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple clients in user test is deprecated, still present in documentation #12961

Open
Voetloos opened this issue Jan 9, 2020 · 15 comments
Open
Labels
Milestone

Comments

@Voetloos
Copy link

Voetloos commented Jan 9, 2020

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,
        ));
@Voetloos
Copy link
Author

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.

From stack

@xabbuh xabbuh transferred this issue from symfony/symfony Jan 20, 2020
@xabbuh
Copy link
Member

xabbuh commented Jan 20, 2020

@Voetloos FYI, I have moved the issue to the documentation repository as it seems that the changes need to be done there.

@xabbuh xabbuh added the Testing label Jan 20, 2020
@xabbuh xabbuh added this to the 4.4 milestone Jan 20, 2020
jpjoao added a commit to jpjoao/symfony-docs that referenced this issue Mar 15, 2020
@errogaht
Copy link

errogaht commented Jun 2, 2020

ok fine, i want to start transacion before each test and then rollback on tearDown, it also described in Symfony docs - "use DAMA\DoctrineTestBundle\PHPUnit\PHPUnitExtension }" but this extension loads kernel of couse.
So currently it is impossible to use transactions and use client to make tests, have to write own Guzzle client, but it is not good because requires real http server which could be hard in CI testing

@bravik
Copy link

bravik commented Jun 8, 2020

Doesn't it make sense to reuse kernel instead of shutdown?

@errogaht
Copy link

errogaht commented Jun 8, 2020 via email

@theredled
Copy link

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.

From stack

So, you cannot use several clients at the same time ? Creating one shuts down the other's kernel, making it unusable.

@carsonbot
Copy link
Collaborator

Thank you for this issue.
There has not been a lot of activity here for a while. Has this been resolved?

@broeser
Copy link

broeser commented Mar 20, 2022

@carsonbot This is still an issue

@carsonbot carsonbot removed the Stalled label Mar 20, 2022
@carsonbot
Copy link
Collaborator

Thank you for this issue.
There has not been a lot of activity here for a while. Has this been resolved?

@JornJorn
Copy link

JornJorn commented May 3, 2023

@carsonbot This is still an issue

@carsonbot carsonbot removed the Stalled label May 3, 2023
@OskarStark
Copy link
Contributor

Symfony 4.4 is EOM, so lets close here

@jdelaune
Copy link
Contributor

Symfony 4.4 may be EOM. But the issue still exists in Symfony 7. https://symfony.com/doc/current/testing/insulating_clients.html just doesn't work.

@burtek
Copy link

burtek commented Feb 19, 2025

@OskarStark why close if the docs are still wrong?

@OskarStark OskarStark reopened this Feb 20, 2025
@OskarStark
Copy link
Contributor

Can you please send a PR?

@burtek
Copy link

burtek commented Feb 20, 2025

#13351 has been open forever

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests