Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix broken web test cases with session already started #4451

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
May 30, 2012
Merged

Fix broken web test cases with session already started #4451

merged 1 commit into from
May 30, 2012

Conversation

guilhermeblanco
Copy link
Contributor

This PR fixes the issues highlighted in PR #4445 and #3741 by not overriding the session id if the session is already started.

@travisbot
Copy link

This pull request passes (merged 3ad01c0 into adf07f1).

@stloyd
Copy link
Contributor

stloyd commented May 29, 2012

Look at #2040. It's quite old, but there is at least some "reason" =)

@guilhermeblanco
Copy link
Contributor Author

@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.

@ghost
Copy link

ghost commented May 30, 2012

@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.

fabpot added a commit that referenced this pull request May 30, 2012
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.
@fabpot fabpot merged commit 3ad01c0 into symfony:master May 30, 2012
@khepin
Copy link
Contributor

khepin commented Jun 30, 2012

What would be the reason that I am still seeing this error? I ran a simple test for logging a user in:

<?php

namespace Mashup\UserBundle\Tests\Controller;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class SecurityControllerTest extends WebTestCase
{
    public function testLogin()
    {
        $client = static::createClient();

        $crawler = $client->request('GET', '/login');
        $form = $crawler->selectButton('Login')->form(array(
            '_username' => 'bob',
            '_password' => 'bob'
                ));
        $client->submit($form);
        $response_code = $client->getResponse()->getStatusCode();
        $this->assertEquals($response_code, 500);
    }
}

I'm currently using FOS UserBundle && FacebookBundle. The logs still show me:

LogicException: Cannot set session ID after the session has started.

I ran an update through composer to get all latest components but still seeing this so I'm wondering where else it could come from.

@ghost
Copy link

ghost commented Jun 30, 2012

@khepin There is a problem with the facebook bundle if I recall: FriendsOfSymfony/FOSFacebookBundle#79 (comment)

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.

5 participants