在 2.0 中,下面的代码可以正常工作,因为升级到 2.1 会话变量正在 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);
}