liip / LiipFunctionalTestBundle

Some helper classes for writing functional tests in Symfony

Home Page:http://liip.ch

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error with definition of method getContainer and Symfony 5.3

k20human opened this issue · comments

Preconditions

  1. Bundle version : 4.3.1
  2. Symfony version : 5.3

Steps to reproduce

  1. Create a test class that extends Liip\FunctionalTestBundle\Test\WebTestCase
  2. Create a test
  3. Run the test

Expected result

  1. 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