升级到Symfony 2.1破坏了WebTestCase功能测试会话

时间:2012-11-30 02:10:50

标签: symfony symfony-2.1

在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);
}

0 个答案:

没有答案