Error with definition of method getContainer and Symfony 5.3
k20human opened this issue · comments
Preconditions
- Bundle version : 4.3.1
- Symfony version : 5.3
Steps to reproduce
- Create a test class that extends
Liip\FunctionalTestBundle\Test\WebTestCase
- Create a test
- Run the test
Expected result
- Test run without error
Actual result
An error occured:
In WebTestCase.php line 205:
Compile Error: Cannot make static method Symfony\Bundle\FrameworkBundle\Test\KernelTestCase::getContainer() non static in class Liip\FunctionalTestBundle\Test\WebTestCase
It's due to this PR on SF 5.3 : symfony/symfony#40366
I can propose a PR to fix that. Can we remove getContainer
method from WebTestCase and use SF's one ? Or rename it ? Or other thing ?
For now i copy / paste WebTestCase class in my code and remove the getContainer method. All tests run like before
Thanks for the detailed issue.
Removing getContainer()
would break the bundle for Symfony < 5.3. Allowing only Symfony 5.3+ would be too restrictive IMHO.
Can we define the method only if it doesn't exist yet?
Or we can remove getContainer()
and the trait like in liip/LiipTestFixturesBundle#26 and switch to services for the next major release.
Can we define the method only if it doesn't exist yet?
I think to something like this: https://www.php.net/manual/fr/function.function-exists.php#117916
if (!function_exists(__NAMESPACE__ . '\getContainer'))
{
function getContainer() {
// …
}
}
Ok, finally we can't use function_exists
or method_exists
inside class definition. So i use __call
method to avoid BC break.
I keep usage of old method getContainer
because the new one of KernelTestCase
call bootKernel
which set static::$booted = true;
and it as some side effects
PR here : #584