Issue#282: call setContainer on ContainerAwareInterface
Autowired controllers break when not calling setContainer on ContainerAwareInterface implementations.
Honestly not really familiar with unit tests, can you give me some pointers? I'll try to write some soon.
I'm on my phone all this week end so it won't be easy . Read .travis.yml to see how to read them, and make a deliberate mistake in the existing part of the code you modified. If it is covered, the tests should break.
When I add throw new \Exception('deliberate mistake'); to the first line of the instantiateController(), the local tests fail on the following test functions:
- Tests/Functional/AutomaticControllerInjectionsTest.php
testInjections() - Tests/Functional/ControllerResolverTest.php
testLookupMethodIsCorrectlyImplemented() - Tests/Functional/ControllerResolverTest.php
testLookupMethodAndAopProxy() - Tests/Functional/ControllerResolverTest.php
testAopProxyWhenNoDiMetadata()
Same effect when I add the throw right before the return.
My guess is that the code is covered, then? :) Any way I can provide proof, or should I extend the tests?
It means the existing code is covered indeed :) you might want to try throwing inside the if statements now, and check that they are covered too, and add more tests if they are not.
First and third if-statements aren't covered. I'll see what I can do with tests tomorrow.
Thanks for the feedback!
I can't really wrap my head around the fact the tests fail for php 5.x and not for 7.x
When I try to debug the test for the autowired controller on 7.x, the code is executed properly, but whenever I debug the controller on 5.x, it seems the code isn't executed and the test fails telling me the Route could not be found.
The HttpKernel/ControllerResolver::createController() does not get executed on 5.x with the current config (and thus the instantiateController() isn't called either).
Any ideas?
You could try generating traces with xdebug_start_trace() and compare them
The third if is now covered.
The first if not yet. When would a Controller already be set on the Container, but not yet be instantiated? In a sub request a new Container would be created, no? I can't think of another scenario in which the first if ($this->container->has($class)) would validate.
Any idea?
Maybe if a controller fowards to itself? Not sure if what I am saying is clever or utterly stupid...
It seems during a forward another Container is instantiated for the sub-request while forwarding. I'll try to investigate further.
Any news about this pull request which may fix the issue about Symfony 3.3 Auto-wiring on controllers ?
Is this ready to merge? Or are there still some things to cover with tests?
There's still one check to be written, but I don't know how to reproduce it with a test. https://github.com/schmittjoh/JMSDiExtraBundle/pull/293#issuecomment-340782931
Any feedback would be appreciated.