-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle] Use security.token_storage service in Controller::getUser() #13214
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Instead of creating a class, where we will add all methods progressively, what about using reflection to access the method?
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.
When I see reflection, I usually notice that the code might not be correct. If you can't test it easily, you might have to rewrite so it is.
I think that the best solution would be if all the basic functionality of the Controller would move away to a loose class (or 2). The current Controller could then delegate the methods and you can test the public methods properly on that specific class. This also makes it easier to re-use certain functionality from the controller if you use 'Controller as a Service'.
I think this falls out of the scope of the PR though.
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.
Even if I agree with you that "non-easily-testable" code is a smell, in this specific case, this is perfectly valid IMO.
Please, don't overcomplicate things, this class is how we tie everything together, easy and simple.
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't this be handled with a magic
__call()
method in theTestController
class?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 haven't used reflection so far, so I am not very familiar with it. @fabpot Your suggestion sounds like it would avoid the need of the
TestController
class completely. If I am not wrong, it would only avoid the overriding of the methods. Maybe that was your point. In this case it would not simplify the testcode IMO, since I have to changeto
where I still need
By avoiding adding all the tested methods of
Controller
progressively, the test methods itself would become unlike more verbose. Although it could be reduced with a helper method, for me, the current version is simpler (for readers, writers and runtime).@xabbuh Using
__call
is indeed an option, but has the drawback that the IDE complains about calling the protected method then.Let me know if I should change the PR though to either use reflection or the __call method.
To address @iltar's comment... What about capitalizing the abilities of traits in PHP 5.4 for SF 3.0 by providing traits with the shortcut methods, so developers can use the methods without extending a base Controller?
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 find it a bad practice to do that because it still requires me to have a container in my controller. As long as I don't see the container and it's abstracted away, I'm ok with it.