Skip to content

Instantly share code, notes, and snippets.

@Herzult
Created February 11, 2011 08:15
Show Gist options
  • Save Herzult/822068 to your computer and use it in GitHub Desktop.
Save Herzult/822068 to your computer and use it in GitHub Desktop.
Quick fix to make session work for a single client in tests
<?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