Symfony2 WebTest请求失败

时间:2014-09-15 05:09:00

标签: symfony functional-testing

我有这个功能测试失败,没有找到,虽然在浏览器中尝试时,它的工作原理。我猜这与时间有关。有可能??

public function testCreateGet()
{
    $client = static::createClient();
    $client2 = static::createClient();

    $client->request('GET', '/user/create/Juan Lopez/1234.json');
    $id = $client->getResponse()->getContent();
    // e.g. $id = 1

    $client2->request('GET', '/user/getById/'.$id.'.json');
    $clientData = json_decode($client2->getResponse()->getContent());
    // Getting not found here

    $this->assertEquals("Juan Lopez", $clientData['name']);
}

1 个答案:

答案 0 :(得分:0)

我没有注意到用户创建响应中的json格式。更新的代码,工作:

$client = static::createClient();

$client->request('GET', '/user/create/Juan Lopez/1234.json');
$response = json_decode($client->getResponse()->getContent());
$id = $response->id;

$client->request('GET', '/user/getById/'.$id.'.json');
$clientData = json_decode($client->getResponse()->getContent());

$this->assertEquals("Juan Lopez", $clientData->name);