Testing AJAX/XMLHttpRequest pages functionally in Symfony2

前端 未结 4 1226
迷失自我
迷失自我 2021-02-04 04:54

Is it possible to simulate/make an XMLHttpRequest request (ajax) in symfony2 tests?

4条回答
  •  清酒与你
    2021-02-04 05:11

    For POST, PUT:

    $crawler = $client->request('POST', '/foo/', array('param' => 'value'), array(),
    array(
        'HTTP_X-Requested-With' => 'XMLHttpRequest',
    ));
    

    For POST, PUT with raw JSON body:

    $crawler = $client->request('POST', '/foo/', array(), array(), array(
        'HTTP_X-Requested-With' => 'XMLHttpRequest',
        'CONTENT_TYPE' => 'application/json',
    ), '{"param": "value"}');
    

提交回复
热议问题