Uncaught PHP Exception LogicException: "Unable to add global "ea" as the runtime or the extensions

84 Views Asked by At

In browser, easyadmin is working fine. But when I run test case which asserts redirection logic to EasyAdmin's dashboard controller after login, it failed with the following error:

Uncaught PHP Exception LogicException: "Unable to add global "ea" as the runtime or the extensions

As it's pointed out in the following comment,
https://github.com/EasyCorp/EasyAdminBundle/issues/5591#issuecomment-1405962016 It seems to me that EasyAdmin twig extension is called after Twig extensions and runtime are initialized

easyadmin twig extension shouldn't be called before extensions and runtime are initialized and phpunit should pass

1

There are 1 best solutions below

0
Erkhembayar Gantulga On

I found out the solution to my problem.

When multiple requests are executed in one test, since Symfony 5.4 the Client reboots the Kernel for each request. So to be able to run several request in the test, I should have added $this->client->enableReboot(); in the test cases which execute several requests.

Multiple Requests in One Test After making a request, subsequent requests will make the client reboot the kernel. This recreates the container from scratch to ensures that requests are isolated and use new service objects each time. This behavior can have some unexpected consequences: for example, the security token will be cleared, Doctrine entities will be detached, etc.

Here is the link https://symfony.com/doc/current/testing.html#multiple-requests-in-one-test