Skip to content

Issue#282: call setContainer on ContainerAwareInterface - #293

Open
SmeTskE wants to merge 4 commits into
schmittjoh:masterfrom
SmeTskE:master
Open

Issue#282: call setContainer on ContainerAwareInterface#293
SmeTskE wants to merge 4 commits into
schmittjoh:masterfrom
SmeTskE:master

Conversation

@SmeTskE

@SmeTskE SmeTskE commented Oct 27, 2017

Copy link
Copy Markdown

Autowired controllers break when not calling setContainer on
ContainerAwareInterface implementations.

Autowired controllers break when not calling setContainer on
ContainerAwareInterface implementations.

@greg0ire greg0ire left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good. Is it covered though?

@SmeTskE

SmeTskE commented Oct 27, 2017

Copy link
Copy Markdown
Author

Honestly not really familiar with unit tests, can you give me some pointers? I'll try to write some soon.

@greg0ire

Copy link
Copy Markdown
Contributor

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.

@SmeTskE

SmeTskE commented Oct 27, 2017

Copy link
Copy Markdown
Author

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?

@greg0ire

Copy link
Copy Markdown
Contributor

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.

@SmeTskE

SmeTskE commented Oct 27, 2017

Copy link
Copy Markdown
Author

First and third if-statements aren't covered. I'll see what I can do with tests tomorrow.

Thanks for the feedback!

@SmeTskE

SmeTskE commented Oct 28, 2017

Copy link
Copy Markdown
Author

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?

@greg0ire

Copy link
Copy Markdown
Contributor

You could try generating traces with xdebug_start_trace() and compare them

@SmeTskE

SmeTskE commented Oct 31, 2017

Copy link
Copy Markdown
Author

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?

@greg0ire

Copy link
Copy Markdown
Contributor

Maybe if a controller fowards to itself? Not sure if what I am saying is clever or utterly stupid...

@SmeTskE

SmeTskE commented Oct 31, 2017

Copy link
Copy Markdown
Author

It seems during a forward another Container is instantiated for the sub-request while forwarding. I'll try to investigate further.

@kmarques

Copy link
Copy Markdown

Any news about this pull request which may fix the issue about Symfony 3.3 Auto-wiring on controllers ?

@GuilhemN

Copy link
Copy Markdown
Collaborator

Is this ready to merge? Or are there still some things to cover with tests?

@SmeTskE

SmeTskE commented Jan 25, 2018

Copy link
Copy Markdown
Author

There's still one check to be written, but I don't know how to reproduce it with a test. #293 (comment)

Any feedback would be appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants