liip / LiipFunctionalTestBundle

Some helper classes for writing functional tests in Symfony
http://liip.ch
MIT License
639 stars 182 forks source link

Error with definition of method getContainer and Symfony 5.3 #583

Closed k20human closed 3 years ago

k20human commented 3 years ago

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 : https://github.com/symfony/symfony/pull/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

alexislefebvre commented 3 years ago

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 https://github.com/liip/LiipTestFixturesBundle/pull/26 and switch to services for the next major release.

alexislefebvre commented 3 years ago

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() {
        // …
    }
}
k20human commented 3 years ago

Ok perfect, will test this tomorrow and do the PR ;)

Le lun. 31 mai 2021 à 19:46, Alexis Lefebvre @.***> a écrit :

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() {

    // …

}

}

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/liip/LiipFunctionalTestBundle/issues/583#issuecomment-851614880, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEEEJPRR5PLKGJWBM4VUMOLTQPDQ7ANCNFSM453DH2SA .

k20human commented 3 years ago

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