Created
February 11, 2011 08:15
-
-
Save Herzult/822068 to your computer and use it in GitHub Desktop.
Quick fix to make session work for a single client in tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace MyVendor\MyBundleBundle\Test; | |
use Symfony\Bundle\FrameworkBundle\Client as BaseClient; | |
use Symfony\Component\BrowserKit\Cookie; | |
class Client extends BaseClient | |
{ | |
/** | |
* Makes a request. | |
* | |
* @param Request $request A Request instance | |
* | |
* @return Response A Response instance | |
*/ | |
protected function doRequest($request) | |
{ | |
// create the session cookie for the client if it does not exist | |
if (null === $this->cookieJar->get(session_name())) { | |
$this->cookieJar->set(new Cookie(session_name(), uniqid())); | |
} | |
$response = parent::doRequest($request); | |
// save the session after performing the request | |
$request->getSession()->save(); | |
return $response; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment