-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A Configuration Option for being able to retain container between requests #124
base: master
Are you sure you want to change the base?
Conversation
@everzet what do you think of this? |
Haven't reviewed the code but like it in theory - good for apps that can handle multiple requests and have truly stateless services |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea!
{ | ||
parent::__construct($kernel->getContainer()->get('test.client'), $baseUrl); | ||
$client = (true === $shared) ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be a one-liner
@@ -80,6 +80,12 @@ public function configure(ArrayNodeDefinition $builder) | |||
->end() | |||
->defaultTrue() | |||
->end() | |||
->booleanNode('shared') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shared_container
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically, it's the kernel
that's being shared, which has a reference to the container.
* @Given I have not configured behat to use shared kernel | ||
*/ | ||
public function iHaveNotConfiguredBehatToUseSharedKernel() | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you simply assert that the symfony2_extension.kernel.shared
parameter has the correct value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually no :( because of course the application is only started on the @when step, so I would either remove this step def, or have it write the config file with that value (I actually wanted to avoid that, which is why I used different profiles)
Is there a solution here already? |
Any news? |
Would be nice to have it merged. For now this one worked for me: #90 (comment). |
{ | ||
parent::__construct($kernel->getContainer()->get('test.client'), $baseUrl); | ||
$client = (true === $shared) ? | ||
new Client($kernel) : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Client
is now deprecated. Should be replaced with Symfony\Component\HttpKernel\HttpKernelBrowser
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.