-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Session] Fixed bug with TestListener #6362
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
Conversation
When the session is not started, the test listener would still save the session causing the session data to be emptied.
A RuntimeException is thrown if there is an attempt to save the session without it being started, or if it has already been closed.
@@ -68,7 +68,9 @@ public function onKernelResponse(FilterResponseEvent $event) | |||
} | |||
|
|||
if ($session = $event->getRequest()->getSession()) { | |||
$session->save(); | |||
if ($session->isStarted()) { |
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 think this should be part of the condition above because if the session has not started, surely there is nothing more to do here at all.
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.
Sorry, already merged this PR. It probably makes sense to move the check, but the tests must be fixed as well then as they won't pass anymore.
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'll fix it now.
This PR was merged into the 2.1 branch. Commits ------- 098b593 [Session] Added exception to save method 6b9ee87 [Session] Fixed a bug with the TestListener Discussion ---------- [Session] Fixed bug with TestListener Fixed a bug where an unstarted mock session would be emptied with a save. Here are the steps to reproduce: Use the test client from Symfony\Bundle\FrameworkBundle\Test\WebTestCase::createClient(), and add something to its session. (I actually had it authenticate against a firewall). Take the cookies of this first test client and add them to a second test client Have the second test client request a URL that results in a 404 Since the 404 does not need to start the session, hence when save is called (automatically), the mock session is overwritten with an empty array. This does not happen with the other session handlers. The added unit test in this PR shows this problem. If this PR gets accepted, will it also get merged into the 2.1.x-dev branch? Bug fix: yes Feature addition: no Backwards compatibility break: no Symfony2 tests pass: yes (The broken test seems to be unrelated to this change) Fixes the following tickets: - Todo: - License of the code: MIT Documentation PR: - This is a follow up PR since my original one (#6342) was against the wrong upstream branch.
Fixed a bug where an unstarted mock session would be emptied with a save. Here are the steps to reproduce:
Use the test client from Symfony\Bundle\FrameworkBundle\Test\WebTestCase::createClient(), and add something to its session. (I actually had it authenticate against a firewall).
Take the cookies of this first test client and add them to a second test client
Have the second test client request a URL that results in a 404
Since the 404 does not need to start the session, hence when save is called (automatically), the mock session is overwritten with an empty array. This does not happen with the other session handlers.
The added unit test in this PR shows this problem. If this PR gets accepted, will it also get merged into the 2.1.x-dev branch?
Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes (The broken test seems to be unrelated to this change)
Fixes the following tickets: -
Todo: -
License of the code: MIT
Documentation PR: -
This is a follow up PR since my original one (#6342) was against the wrong upstream branch.