Codeception / module-symfony

Codeception module for testing apps using Symfony framework
MIT License
89 stars 24 forks source link

The kernel reboot #130

Open Legion112 opened 3 years ago

Legion112 commented 3 years ago

I think the process of rebooting the kernel should be done right after the request has been finished. Here we have logic that will reboot the kernel only when a second request is made. https://github.com/Codeception/module-symfony/blob/master/src/Codeception/Lib/Connector/Symfony.php#L63 I think we should change it to:

    protected function doRequest($request): Response
    {
        $response = parent::doRequest($request);
        if ($this->rebootable) {
                $this->rebootKernel();
        }
        return $response;
    }

Why is it important? If the kernel is rebooted only when a second request happened - we cannot configure the "DI" container on the fly. Like setting Stubs classes. Something like this:

$I->sendGet('/some/path');
$stub = $I->grabServise(ExternalApiStub::clase);
$stub->setFakeResponse('This is a fake response from external API');
$I->sendGet('/some/path'); // here kernel rebootes and state of DI container is lost
TavoNiievez commented 3 years ago

@Legion112 could you please send a PR for this?

It would also help to have a test in our test project ( Codeception/symfony-module-tests ) with which we verify that your change solves the issue (and that it will not be damaged in future versions).

Please follow the contribution guide ( master/CONTRIBUTING.md ), and if all goes well I will gladly merge the changes.

specdrum-agc commented 2 years ago

Hello!

I also would like to notice that way this module is reboot Symfony Kernel differ from way doing that in Symfony KernelTestCase. Looks like this leads to services which implements Symfony\Contracts\Service\ResetInterface are not reset.

Look at https://github.com/symfony/symfony/issues/40965 for example.

namex42 commented 1 year ago

@Legion112 @TavoNiievez is there any progress on this issue? Thanks!

Legion112 commented 1 year ago

Sorry no longer work with codeception.

We used static variables for setting the state of stub classes. This has one downside as it you need to reset the state between tests yourself.