-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Explained how to run tests in multiple kernel apps #8124
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
Conversation
:class:`Symfony\\Bundle\\FrameworkBundle\\Test\\WebTestCase` class. Inside that | ||
class, a method called ``getKernelClass()`` tries to find the class of the kernel | ||
to use to run the application during tests. The logic of this method does not | ||
support multiple kernel applications, so your tests won't use the right kernel. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to be careful here. The approach described here does not solve the issue when you have more than one kernel. The problem then still is that the KernelTestCase
class keeps a reference to the previously created kernel in its static $kernel
property. Thus, if your functional tests do not run in isolated processes a later run test for a different kernel will reuse the previously created instance which points to a different kernel.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation! You are right and this is critical. What would be the best (and simplest) solution to this problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be sufficient to always reset the static $class
property inside the tearDown()
method:
protected function tearDown()
{
parent::tearDown();
static::$class = null;
}
The parent::tearDown()
call is important to make sure that the kernel is shut down after the test was run.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!! I've fixed the code and reused your original explanation because it's great.
Thank you Javier. |
This fixes #6279.