Behat / Symfony2Extension

Symfony2 extension for Behat
MIT License
392 stars 106 forks source link

A Configuration Option for being able to retain container between requests #124

Open jon-acker opened 7 years ago

jon-acker commented 7 years ago

In the simplest case where you make only one request to your app - access to the services in the container from Behat context file works, but once you make another request then Symfony will reboot the kernel and you will lose access to the container from the Behat context files.

If I am running a scenario where I set the value of a symfony service in the Given step (for example an in-memory repository), make a request to load a form and then make another request to press the form button (which will have an effect of setting a value in this service), I will no longer have access to the original instance of the service from Behat.

Using this option, I construct the a new "test.client" (instead of the existing one) using an instance of Behat's kernel. Effectively, the kernel is only rebooted once every scenario rather than every request.

I find the possibility of this very useful when running scenarios against in-memory repositories, though I suppose it should be made clear that this option should it potentially dangerous as it changes the way symfony would normally work, and means that if you had stateful services then there is no guarantee what state they will be in after the first request.

jon-acker commented 7 years ago

@everzet what do you think of this?

ciaranmcnulty commented 7 years ago

Haven't reviewed the code but like it in theory - good for apps that can handle multiple requests and have truly stateless services

ghostika commented 6 years ago

Is there a solution here already?

prodigeris commented 5 years ago

Any news?

holyspecter commented 4 years ago

Would be nice to have it merged. For now this one worked for me: https://github.com/Behat/Symfony2Extension/issues/90#issuecomment-324927702. Thank you @jon-acker!