Skip to content
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

How can I mock behavior of the services in the 'fob_symfony.driver_kernel'? #94

Closed
arkadiy-lysenko opened this issue Sep 26, 2019 · 5 comments
Labels

Comments

@arkadiy-lysenko
Copy link

User case:
I need to mock some services while api testing
I get from kernel instance some services and put on this service some dummy(using Prophecy)
But when behat steps are passed and request to kernel is started, kernel object have no mocked objects at all (I think this is because of two kernel's loaded)

\FriendsOfBehat\SymfonyExtension\ServiceContainer\SymfonyExtension::load $this->loadKernel($container, $this->autodiscoverKernelConfiguration($config['kernel'])); $this->loadDriverKernel($container);
I try to pass 'fob_symfony.driver_kernel' service to BehatContext to change it behavior but service doesnot exist.

How can I mock behavior of the services in the 'fob_symfony.driver_kernel'?

I use:

  • Behatch/contexts(for example RestContext send request using mink driver that loaded with second kernel instance)
  • Behat/MinkExtension
@lchrusciel
Copy link
Member

For now, you are probably forced to write some dummy implementation and load it only in test env, so DI will handle mocking. However some support for prophecy could be useful, but probably it won't be easy to implement.

@pamil is it something that we would like to support?

@arkadiy-lysenko
Copy link
Author

arkadiy-lysenko commented Sep 30, 2019

But if i implement static dummy implementation this will work only for one case.
I can't configure it in behat scenario because kernel will reboot and reset all configuration.
For my case I want to mock response from service and want to test several of responses.

@lchrusciel Can I get access to kernel object that set to mink driver? If I can get access to him I can configure it as i want using that mock library that i want(prophecy, phpunit, etc).

@pamil
Copy link
Member

pamil commented Nov 26, 2019

This issue is probably a bit related to #86, defining a stable way to get to and modify those services in Mink kernel would be certainly beneficial, although I don't have any good ideas for it now.

@pamil pamil added the Feature label Jan 13, 2020
@pamil
Copy link
Member

pamil commented Apr 4, 2020

After #116 is merged, you can inject @behat.driver.service_container service to your context and access services/kernel of the tested application via Mink driver. Let me know if that solves your issue.

@pamil
Copy link
Member

pamil commented Apr 4, 2020

I've released v2.1.0-BETA.2 with #116 that should help with it. I'll close this issue, please open a new one if it isn't enough.

@pamil pamil closed this as completed Apr 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants