@@ -622,22 +622,19 @@ This allows you to create all types of requests you can think of:
622
622
Multiple Requests in One Test
623
623
.............................
624
624
625
- After you send one request, subsequent ones will make the client reboot
626
- the kernel, recreating the container from scratch.
627
- This ensures that requests are "isolated" using "new" service objects.
628
- However, this can cause some unexpected behaviors. For example, the
629
- security token will be cleared, Doctrine entities will be "detached"…
630
-
631
- Calling the client's
632
- :method: `Symfony\\ Bundle\\ FrameworkBundle\\ KernelBrowser::disableReboot `
633
- method is the first step to work around this, as this will reset the kernel
634
- instead of rebooting it. Now, resetting the kernel will call the ``reset() ``
635
- method of every ``kernel.reset `` tagged service, which will **also ** clear
636
- the security token, detach entities and so on.
637
-
638
- As such, the next step is to create a
639
- :doc: `compiler pass </service_container/compiler_passes >` to remove the
640
- ``kernel.reset `` tag from these services in your test environment::
625
+ After making a request, subsequent requests will make the client reboot the kernel.
626
+ This recreates the container from scratch to ensures that requests are isolated
627
+ and use new service objects each time. This behavior can have some unexpected
628
+ consequences: for example, the security token will be cleared, Doctrine entities
629
+ will be detached, etc.
630
+
631
+ First, you can call the client's :method: `Symfony\\ Bundle\\ FrameworkBundle\\ KernelBrowser::disableReboot `
632
+ method to reset the kernel instead of rebooting it. In practice, Symfony
633
+ will call the ``reset() `` method of every service tagged with ``kernel.reset ``.
634
+ However, this will **also ** clear the security token, detach Doctrine entities, etc.
635
+
636
+ In order to solve this issue, create a :doc: `compiler pass </service_container/compiler_passes >`
637
+ to remove the ``kernel.reset `` tag from some services in your test environment::
641
638
642
639
// src/Kernel.php
643
640
namespace App;
@@ -651,7 +648,7 @@ As such, the next step is to create a
651
648
{
652
649
use MicroKernelTrait;
653
650
654
- // …
651
+ // ...
655
652
656
653
protected function build(ContainerBuilder $container): void
657
654
{
@@ -662,10 +659,10 @@ As such, the next step is to create a
662
659
// prevents the security token to be cleared
663
660
$container->getDefinition('security.token_storage')->clearTag('kernel.reset');
664
661
665
- // prevents entities to be detached
662
+ // prevents Doctrine entities to be detached
666
663
$container->getDefinition('doctrine')->clearTag('kernel.reset');
667
664
668
- // …
665
+ // ...
669
666
}
670
667
});
671
668
}
0 commit comments