phpUnit 中的客户端请求给出的响应与 cURL 不同

Request with client in phpUnit gives a different response than with cURL

我在 phpUnit 中对客户端的请求给出了与 cURL 不同的响应。

这怎么可能?

    //Curl
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, "http://localhost:8888/web/app_dev.php/api/v1/users/16");  
    $output = curl_exec($ch);
    dump($output);

    dump("--------");

    //phpUnit Client
    $client = static::createClient();
    $client->request('GET', '/api/v1/users/16');
    $content = json_decode($client->getResponse()->getContent(), true);
    dump($content);

回复:

{
    "id":16,
    "email":"gmail@gmail.com",
    "first_name":"Olivier",
    "last_name":"Peano",
    "sex":"Femme",
    "promotion":"Bac +1",
    "telephone":"0606060606",
}


"--------"

array:7 [
        "id"            => 16
        "first_name"    => "Lea"
        "last_name"     => "Peano"
        "sex"           => "Femme"
        "promotion"     => "Bac +1"
        "telephone"     => "0606060606"
]

电子邮件与 cUrl 一起出现,而不是与客户端一起出现。

这两种方法有什么不同吗?

我使用 Symfony3、FOSUserBundle 和 FOSRestBundle。但没关系,因为我发送了相同的请求。

正如@BVengerov 所说:

Seems like you are creating the client with a base url which is different from http://localhost:8888/web/app_dev.php/

我已经修复了它:

$client = static::createClient(array(), array('HTTP_HOST' => 'symfony.dev'));
$client->followRedirects(true);

谢谢。