Testing AJAX/XMLHttpRequest pages functionally in Symfony2

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

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

4条回答
  •  我在风中等你
    2021-02-04 05:07

    If you are working with Symfony 3.x or 4.x this is the correct way to do it using POST method.

    $data = ['some' => 'value'];
    $client = static::createClient();
    $client->request('POST', '/some_uri', ['data' => $data], [],; [
      'HTTP_X-Requested-With' => 'XMLHttpRequest',
    ]);
    

提交回复
热议问题