在2.0中,下面的代码工作正常,因为升级到2.1会话var正在进行MIA。
public function __construct()
{
$this->client = static::createClient(array(), array(
'PHP_AUTH_USER' => 'unittest@test.com',
'PHP_AUTH_PW' => 'test',
));
//set the session
$this->container = $this->client->getContainer();
$this->client->getCookieJar()->set(new \Symfony\Component\BrowserKit\Cookie(session_name(), true));
$this->session = $this->container->get('session');
$this->session->set('company_id', '9999');
$this->session->save();
}
public function testGetClientsAction()
{
$this->client->request(
'GET',
'/clients',
array(),
array(),
array('HTTP_X-Requested-With' => 'XMLHttpRequest', 'HTTP_accept' => 'application/json')
);
$content = $this->client->getResponse()->getContent();
$status = $this->client->getResponse()->getStatusCode();
$this->assertNotEmpty($content);
$this->assertEquals(200, $status);
}