Тестирование модулей symfony: добавление / изменение формы

У меня есть форма, без действия (отправляется с javascript), и я пытаюсь написать для нее единичный тест, но он терпит неудачу, потому что отсутствует атрибут «действие»:

InvalidArgumentException: Текущий URI должен быть абсолютным URL ("").

Есть ли способ добавить его в модульные тесты или изменить содержимое html с помощью искателя?

<form id="form_search_page"> <input type="text" name="keyword" value="" /> <button type="submit" name="searchBtn" id="searchBtn">Search</button> </form> $client = $this->makeClient(true); $url = $this->createRoute("page_index")); $crawler = $client->request('GET', $url); $response = $client->getResponse(); $form = $crawler->filter('#form_search_page')->form(); $params = array( "form[text]" => "dummy title" ); $form->setValues($params); $crawler = $client->submit($form); $response = $client->getResponse(); $this->assertGreaterThan(0, $crawler->filter('.pages li')->count()); 

Я нашел решение:

 $crawler ->filter('form#form_search_page') ->reduce(function (Crawler $form) use ($router) { $url = $router->generate('search_page', array(), true); $node = $form->getNode(0); if (!$node->hasAttribute('action')){ $node->setAttribute('action', $url); $node->setAttribute('method', 'POST'); return true; } return false; }) ->first(); 

Вы можете проверить форму POST ajax submit как пример выше (предполагая форму с токеном CSRF):

 $crawler = $this->client->request('GET', $url); // retrieves the form token $token = $crawler->filter('[name="myform[_token]"]')->attr("value"); $posturl = $this->client->getContainer()->get('router')->generate("the-url-of-the-submit"); // makes the POST request $crawler = $this->client->request('POST', $posturl, array( 'myform' => array( '_token' => $token )), array(), array( 'HTTP_X-Requested-With' => 'XMLHttpRequest', ) ); $this->assertTrue( $this->client->getResponse()->headers->contains( 'Content-Type', 'application/json' ) ); 

Надеюсь, что эта помощь