-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Cannot set session ID after the session has started. #5161
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
This was something some users were experiencing before. It's specifically related to testing. Do you have a bundle I can work with to investigate further? |
I'm a afraid not, my public bundles are just libraries without WebTestCases. By the way I get the same error in a simpler case: <?php
$client = static::createClient();
$crawler = $client->request('GET', '/');
$this->assertTrue(200 === $client->getResponse()->getStatusCode());
$crawler = $client->request('GET', '/other-page/');
$this->assertTrue(200 === $client->getResponse()->getStatusCode()); Just requesting another page, it gives the error. Does it work with you? |
I'm not getting this on a 2.1 project. Might be it's related to migration. Have you changed storage_id in the app/config/config_test.yml to session.storage.mock_file? |
Yes I tried both session.storage.filesystem and session.storage.mock_file. Same effect. I'm also using LiipFunctionalTestBundle, I'll try to disable some bundles to locate the problem. |
It appears that the problem is related to FOSFacebookBundle, disabling it, the tests work again. I'll try to report the issue there. |
I'm facing this issue even though I don't use FOSFacebookBundle, it occurs when I try to authenticate a user in a functional test, it looks related to the cookie I'm setting to fake a previous session, is there anything I'm doing wrong within this test? |
@Drak : any clue? |
FriendsOfSymfony/FOSFacebookBundle#183 might address this issue. @iJanki @Drak @bamarni |
@gquemener : apparently this can also occurs when not using FOSFacebookBundle. I've added added my failing test in a symfony standard edition fork : https://github.com/bamarni/symfony-standard/blob/failing-test/src/Acme/DemoBundle/Tests/Controller/DemoControllerTest.php Is there anything I'm doing wrong? cc @Drak I've also commited my composer.lock so you can get the exact versions it fails with. |
Any progress on this? I'm facing the same issue, but when following redirects, at https://github.com/symfony/symfony/tree/ee7597576c4244d51d777001e570111ba59d9d72 framework:
test: true
profiler:
only_exceptions: false
session:
storage_id: 'session.storage.mock_file'
handler_id: false <?php
namespace Ormigo\Bundle\OrmigoBundle\Tests\Controller;
use Ormigo\Tests\AbstractFunctionalTest;
use Ormigo\Model\Banking\BankQuery;
class BankControllerTest extends AbstractFunctionalTest
{
// ..
public function testByBicIsRedirectingToShow()
{
$bank = BankQuery::create()->findOneByBic('HYVEDEMM488');
$client = static::createClient();
$client->request('GET', sprintf('/bank/by-bic/%s.de_DE.json', $bank->getBic()));
$this->assertRedirect($client->getResponse(), sprintf('/bank/%s.de_DE.json', $bank->getId()));
$client->followRedirect();
$this->assertSuccessfulJsonResponse($client->getResponse()); // 500 "Cannot set session ID .."
}
// ..
} |
Nothing changed for me, I still get the original problems using the latest trees. |
I have same problem. I am trying to use Behat with Mink but I think that is not the issue because I see this error when accessing app_test.php from browser too. Tests are passing when I comment line #54 in TestSessionListener.php. My composer.json: { "require" : {
"symfony/symfony": "2.1.*",
"doctrine/orm": ">=2.2.3,<2.4-dev",
"doctrine/doctrine-bundle": "1.0.*",
"twig/extensions": "1.0.*",
"symfony/assetic-bundle": "2.1.*",
"symfony/swiftmailer-bundle": "2.1.*",
"symfony/monolog-bundle": "2.1.*",
"sensio/distribution-bundle": "2.1.*",
"sensio/framework-extra-bundle": "2.1.*",
"sensio/generator-bundle": "2.1.*",
"jms/security-extra-bundle": "1.2.*",
"jms/di-extra-bundle": "1.1.*",
"Beryllium/CacheBundle": "dev-master",
"friendsofsymfony/jsrouting-bundle": "1.0.x-dev",
"friendsofsymfony/facebook-bundle": "dev-master",
"friendsofsymfony/user-bundle": "*",
"stof/doctrine-extensions-bundle": "dev-master",
"doctrine/doctrine-migrations-bundle": "dev-master",
"jms/i18n-routing-bundle": "dev-master",
"behat/behat": "*",
"behat/mink": "*",
"behat/symfony2-extension": "*",
"behat/mink-extension": "*",
"behat/mink-goutte-driver": "*",
"behat/mink-browserkit-driver": "*",
"behat/mink-selenium2-driver": "*",
"sanpi/behatch-contexts": "*"
}}``` |
@Pajk I believe you have the wrong session storage set. framework:
session:
storage_id: 'session.storage.native'
handler_id: 'session.handler.native_file' This will work with Behat/Mink on an actual browser. |
Thanks for suggestion @havvg but it didn't help. There is a bug in Facebook bundle, [1] fixed it. |
Getting the same issue here - no FOSFacebookBundle. Tried both the session configurations mentioned above - didn't help. Problem occurs when following redirect through the crawler after a login. |
I'm getting the same issue with LiipFunctionalTestBundle and the problem lies with this line:
When I remove it in my tests, it works fine. I don't know why yet. Maybe someone else has more insight on this. |
An update: it seems that when I configure the session storage name to |
I'm getting the same issue with the test case of iJanki without using FOSFacebookBundle. Changing the session name didn't help. |
I have this issue even without FOSFacebookBundle. |
@phidah would it be possible to set up a simple standard edition project reproducing this issue? |
I'd be happy to try and investigate for you if you can setup a project I can just download and get the error with. |
@bamarni - Composer throws a wobbly when I try to get the deps. Maybe you can mail me at drak at zikula dot org so we dont pollute the ticket. I'm quite busy but if I can at least get the test env working, then I can get to it. I'm working on some session PRs atm so it's a good time. |
@bamarni your test fails because there's no session ID sent with the cookie. Also, session needs to be saved before sending a request (in fact before creating a cookie too). see: bamarni/symfony-standard@317ce94#commitcomment-2953995 |
@jakzal - do you think you could open a cookbook entry or something in the Symfony2 docs about this? If it's documented once, it might save quite a bit of bother. |
@jakzal : thx for the explanations and the code snippet, I understand what was wrong now. |
@Drak I will. |
closing as symfony/symfony-docs#2468 has been merged now. |
I'm starting to receive this error after upgrading to 2.1 during tests. I've seen there are other tickets with this issue but they are old and closed.
I'm receiving the error for example with this code:
The last client response is 500 error Cannot set session ID after the session has started. This test worked before. Has something changed?
The text was updated successfully, but these errors were encountered: