8000 [FrameworkBundle] Added unit-tests for GlobalVariables::getUser() by linaori · Pull Request #12013 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[FrameworkBundle] Added unit-tests for GlobalVariables::getUser() #12013

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

Merged
merged 1 commit into from
Sep 25, 2014
Merged

[FrameworkBundle] Added unit-tests for GlobalVariables::getUser() #12013

merged 1 commit into from
Sep 25, 2014

Conversation

linaori
Copy link
Contributor
@linaori linaori commented Sep 24, 2014
Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc PR -

Tests added should explain that getUser() should return null when a string is found as user. If this is not correct, a PR should be made. However, this would result in a huge BC break due to people using {% if app.user %} which would return null if an anonymous token was found. If this suddenly returns a string, this check will fail.

While at it, I have also added getUser() tests to verify the unhappy flow is working. These tests uncovered that if $container->get('security.token_storage') fails, it will throw an exception rather than return null. This issue is now fixed.

List of changes

  • The old testGetUser has been refactored to be tested with multiple variations of return types to verify the return type to work as the code tells.
  • get('security.token_storage') is now only executed if has('security.token_storage') returns true

@fabpot I think this PR should be merged before 2.6, because it fixes an uncaught exception bug in my previous PR which splits the security context

* @param mixed $user
* @param mixed $expected_result
*/
public function testGetUser($user, $expected_user)
Copy link
Member

Choose a reason for hiding this comment

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

please use camelCased names

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I sense a new feature for fabbot.io coming? 👍

@fabpot
Copy link
Member
fabpot commented Sep 25, 2014

Thank you @iltar.

@fabpot fabpot merged commit 3f055f7 into symfony:master Sep 25, 2014
fabpot added a commit that referenced this pull request Sep 25, 2014
…getUser() (iltar)

This PR was merged into the 2.6-dev branch.

Discussion
----------

[FrameworkBundle] Added unit-tests for GlobalVariables::getUser()

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Tests added should explain that `getUser()` should return `null` when a string is found as user. If this is not correct, a PR should be made. However, this would result in a huge BC break due to people using `{% if app.user %}` which would return `null` if an anonymous token was found. If this suddenly returns a string, this check will fail.

While at it, I have also added `getUser()` tests to verify the unhappy flow is working. These tests uncovered that  if `$container->get('security.token_storage')` fails, it will throw an exception rather than return `null`. This issue is now fixed.

List of changes
--------------------
- The old `testGetUser` has been refactored to be tested with multiple variations of return types to verify the return type to work as the code tells.
- `get('security.token_storage')` is now only executed if `has('security.token_storage')` returns true

@fabpot I think this PR should be merged before 2.6, because it fixes an uncaught exception bug in my previous PR which splits the security context

Commits
-------

3f055f7 Fixed a bug and added unit-tests for GlobalVariables
@linaori linaori deleted the feature/twig-app-user-test branch April 15, 2016 13:33
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.

3 participants
0