-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[2.1] TestSessionListener is setting an id to the session #3741
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
Comments
@Drak: can you help-me with this issue? |
Can you show me the tests? |
https://gist.github.com/2279935 As you can see, it's a simple test, and phpunit configuration file it's the sf default. Note that i'm using the most recent version on the master branch. Thanks |
Note to others, we are discussing and investigating together on this. |
What I do't quite understand is why the tests pass in FrameworkBundle/Tests/Functional as these also use sessions. I haven't been able to see what the difference is between the tests, except for the invokation of the client. Does anyone have some idea? |
any news ? |
@yethee in your test you modify the session but your first request is made without a cookie which holds the session id (so the session cannot be restored). I'd say it should work if you save the session and send a proper cookie (but it doesn't). Exception is thrown in MockArraySessionStorage::setId(). I'm not sure if it's a bug. For some (probably good) reason it's forbidden to re-set the session id. If you made a request before altering the session it'd properly set the cookie and your test would pass.
Notice you also need to save the session before making a request. Anyone else has thoughts on this? ping @Drak |
@fabpot - I'm temporarily stumped on this, have you some idea? The tests work in FrameworkBundle/Tests/Functional, yet other people's tests don't work. I don't get it. |
From what I can see, the listener order is correct, ie the test listeners fire before the session is started by the other listener, at least, in code it looks ok. |
@jakzal - in @yethee's case yes, but the tests shown by @diegoholiveira don't appear to be down to user implementation. The problem is, removing the exceptions is OK, but they were added explicitly to trap this kind of thing, so clearly something deeper is going on. |
Without the exception the problem is the same. The session doesn't work with behat (i can't test a simple login page) |
@benji07 are you using FrameworkBundle or not, because FrameworkBundle has a listener which saves sessions (when in test mode). |
I use the standard edition on master branch, i add mink, and try to test the login page |
it's work with symfony session, not with zombie.js EDIT: it's work with sahi too (maybe there are a but with zombie.js) |
@Drak would be helpful if someone linked to/pasted @diegoholiveira's tests. |
@jakzal sorry dude, i don't understand what you mean. Did you like to take a look into my tests? |
@diegoholiveira sorry, i didn't notice your link.... |
@jakzal no problems :) If you need something, just ping me. |
Hi, I'm jumping in since I'm now facing this issue as well. Here a test case failing:
When I started to work today, tests were ok. Then, I added JMSDebuggingBundle and updated Symfony 2.1 dependencies then tests stopped working. Last time I updated, its when Form options were fixed, so it like 8 days ago from now. The failing machine is on Mac OS X, I have another box at home, which is on Windows and with the project not updated yet. I will make some test tonight or tomorrow morning to see what caused the problem to arise now and not before. Maybe it could help with the debugging of the problem. Regards, |
Here a follow-up of my previous post. Today, I tried to revert to a previous working state and tests were passing as expected with a preivous version of my project. Since the last thing I had done before it failed was adding So, I went back to the HEAD of my branch to have my project fully up-to-date and tried to disable the bundle. This also made the tests passed. So, my conclusion is that, in my case, the bundle was interacting badly with the session somehow which is triggering the errors in my tests. The current workaround I did is to disable the
I thought it could be the custom container class provided with the bundle that was breaking something, but it wasn't the case since commenting the code changing the container base class did not make the tests pass. Once again, I'm changing the container base class only in Anyone in this thread having the error is using Hope it helps to resolve this issue. Regards, |
I'm not using JMSDebuggingBundle. In fact, i'm just using the default bundles that come into symfony-standard. :) |
Hello again, Since @diegoholiveira is using only default bundles, it is clearly not only I'm my project, I'm also using
A weird interaction is going on since activating So, I decided to find a way for others to reproduce this error. What you can do is to checkout To make it easy to reproduce, I cloned current If you clone my repo, checkout branch If you then comment I cannot conclude if this a Symfony bug or not. Only thing I can say, this is a bizarre issue and seems to be related to integration of code. Since @diegoholiveira use default bundles from Again, hope this helps to sort out this weird issue :) Regards, |
Hi Matt, Sorry dude, but I give you WRONG information about my project. I'm using FOSFacebookBundle too (I just remember that I'm using when I see you last response, it's easy to forgot about it because it's something that we not deal directly every day...) |
@diegoholiveira No problem at all :), it may now be easier to debug the issue. This seems in some way related to It could potentially be related to this |
After reading more thoroughly issue #79 of Maybe @Drak could confirm my hypothesis. |
also seeing this issue when updating. i am not using FOSFacebookBundle, but a fairly hacked up version of Sensio's CasBundle |
Some more information about my use case. My provider class has a dependency on a service that in turn requires the container. I managed to fix the issue by instead injecting the container and then only fetching the session lazily .. but not instead the constructor. |
@lsmith77 @maoueh @Drak @diegoholiveira I am experiencing the same problem right now. |
Commits ------- 3ad01c0 Update src/Symfony/Bundle/FrameworkBundle/EventListener/TestSessionListener.php Discussion ---------- Fix broken web test cases with session already started This PR fixes the issues highlighted in PR #4445 and #3741 by not overriding the session id if the session is already started. --------------------------------------------------------------------------- by travisbot at 2012-05-29T19:06:33Z This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1468970) (merged 3ad01c0 into adf07f1). --------------------------------------------------------------------------- by stloyd at 2012-05-29T19:07:54Z Look at #2040. It's quite old, but there is at least some "reason" =) --------------------------------------------------------------------------- by guilhermeblanco at 2012-05-29T20:57:27Z @stloyd it seems to me that doing a session_id() (and now as $session->setId()) is still wrong. The right should be a regeneration of the id then, which would still make my code pass. The problem is that setId method checks for a possible regeneration/double attribution, which prevents an already started session (from a WebTestCase) to live peacefully with the TestSessionListener, because it will always try to set an id. So either we allow to regenerate ids or this code is not only useless for 2.1, but actually broken. --------------------------------------------------------------------------- by drak at 2012-05-30T02:42:47Z @guilhermeblanco - When I was doing the session refactoring I wanted to make exactly the patch this PR now but I didnt because I wast sure if there were reasons I was unaware of. @fabpot - I would merge this PR if it fixes the related tickets.
I had the same problem. In my case the problem was I had an event listener which had this code:
As it is described in this isuue FriendsOfSymfony/FOSFacebookBundle#79 the problem is to start the session too early. |
I'm trying to run my tests with sf2.1 and i'm getting an exception weird:
This error occour only when I run my tests, on the browser it's fine.
So I decide to track the error, then i found this lines on the class Symfony\Bundle\FrameworkBundle\EventListener\TestSessionListener
After remove this lines, everything works fine.
I don't know if this is a bug with the code or if something missing on my configuration.
refs FriendsOfSymfony/FOSFacebookBundle#79
The text was updated successfully, but these errors were encountered: