Symfony功能测试 – 自定义标题不通过

前端之家收集整理的这篇文章主要介绍了Symfony功能测试 – 自定义标题不通过前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
由于某些原因,当我发送一个新的$client->请求我指定的标题丢失:
public function testGetClientsAction()
{
    $client = static::createClient();

    $cookie = new Cookie('locale2','en',time() + 3600 * 24 * 7,'/',null,false,false);
    $client->getCookieJar()->set($cookie);

    // Visit user login page and login
    $crawler = $client->request('GET','/login');
    $form = $crawler->selectButton('login')->form();
    $crawler = $client->submit($form,array('_username' => 'greg','_password' => 'greg'));

    $client->request(
       'GET','/clients',array(),array('X-Requested-With' => 'XMLHttpRequest','accept' => 'application/json')
    );

    print_r($client->getResponse());
    die();

}

在正在测试的方法中,我在第一行:

print_r($request->headers->all());

答复如下:

Array
(
    [host] => Array
        (
            [0] => localhost
        )

    [user-agent] => Array
        (
            [0] => Symfony2 BrowserKit
        )

    [accept] => Array
        (
            [0] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
        )

    [accept-language] => Array
        (
            [0] => en-us,en;q=0.5
        )

    [accept-charset] => Array
        (
            [0] => ISO-8859-1,utf-8;q=0.7,*;q=0.7
        )

    [referer] => Array
        (
            [0] => http://localhost/login_check
        )

    [x-PHP-ob-level] => Array
        (
            [0] => 1
        )

)
我有同样的问题,经过一点点挖掘,我认为这是BrowserKit目前不支持功能.

我已经记录了一个问题:
https://github.com/symfony/symfony/issues/5074

更新:这不是一个问题 – 请看下面的评论

示例代码

样品申请:

$client->request(
    'GET',$url,array(
        'HTTP_X_CUSTOM_VAR' => $var
    )
);

获取数据:

$request->headers->get('x-custom-var');
原文链接:https://www.f2er.com/php/140088.html

猜你在找的PHP相关文章