6

I'm actually testing a bundle that I created. All the code is fully unit tested but now, I want to test if my symfony2 services can be request without any trouble.

For that, I need the symfony2 dependency injection container in my test case. How can I do that ?

egeloen
  • 5,844
  • 1
  • 27
  • 38
  • 2
    Why not mocking it. That's the aim of unit testing and dependency injection : isolating the tested code. – Clement Herreman Sep 29 '11 at 16:08
  • I understand your point of view but my interest in this test is to check that my [services configuration](https://github.com/egeloen/IvoryGoogleMapBundle/blob/master/Resources/config/services.xml) are correctly configured. So, I think mocking it doesn't resolve my issue. (Correct me if I'm wrong :)). Right now, The only solution I imagine is to inject the seymfony 2 dependency injection container in my test and check that calling my services doesn't throw an exception & give me appropriate objects but I don't know how can I do that. – egeloen Oct 03 '11 at 16:46
  • Testing your configuration ? That sounds strange. – Clement Herreman Oct 04 '11 at 16:03
  • 1
    I think that's not so strange, I'm actually updating a lot of things in the bundle which force me to add or update some services. My tests don't cover this services, so, each times I update something I must check mannualy my services are correctly configured instead of running my test suite... – egeloen Oct 04 '11 at 16:57

1 Answers1

5

I recently asked a question similar to this in that I needed just the validator, however the person who replied to my question first had a solution which gave access to the whole container.

Basically you can pick apart WebTestCase in order to see how it builds the Symfony2 environment and make your own base class which is Symfony aware as it were.

Here is the answer, I hope it helps: Symfony2: Testing entity validation constraints

Community
  • 1
  • 1
Kasheen
  • 5,401
  • 2
  • 31
  • 41