testing - symfony WebTestCase client does not send post data -


i'm writing functionnal tests symfony app. use symfony 3 (3.1.6) phpunit 5.6.1. edit : requested alvin bunk, app not website, api returns json. added in 2 updates below, symfony test client sends proper request object form data controller of app receives empty object.

here code use test form :

public function testsavemediafrommediaurl() {     $client = static::createclient();     $crawler = $client->request('get', '/form');      $form = $crawler->selectbutton('ok')->form();     $form['mediaurl'] = 'http://example.com';      $client->submit($form);     var_dump($client->getresponse()->getcontent()); } 

the correct action of controller called there nothing in request object when action called tests suite. using regular web browser, works fine. in controller, use $request = request::createfromglobals(); create request object

i tried code post data , same result : no post data received in controller.

direct post request without using form

public function testsavemediafrommediaurl() {     $client = static::createclient();     $crawler = $client->request('post', '/media', ['mediaurl' => 'http://example.com']);      var_dump($crawler->html()); } 

adding data in submit method

public function testsavemediafrommediaurl() {     $client = static::createclient();     $crawler = $client->request('get', '/form');      $form = $crawler->selectbutton('ok')->form();      $client->submit($form, ['mediaurl' => 'http://example.com']);     var_dump($client->getresponse()->getcontent()); } 

is there i'm doing wrong ?

edit:

here dump of request object in controller action.

.object(symfony\component\httpfoundation\request)#1047 (21) {   ["attributes"]=>   object(symfony\component\httpfoundation\parameterbag)#1050 (1) {     ["parameters":protected]=>     array(0) {     }   }   ["request"]=>   object(symfony\component\httpfoundation\parameterbag)#1048 (1) {     ["parameters":protected]=>     array(0) {     }   }   ["query"]=>   object(symfony\component\httpfoundation\parameterbag)#1049 (1) {     ["parameters":protected]=>     array(0) {     }   }   ["server"]=>   object(symfony\component\httpfoundation\serverbag)#1053 (1) {     ["parameters":protected]=>     array(35) {[...]}   }   ["files"]=>   object(symfony\component\httpfoundation\filebag)#1052 (1) {     ["parameters":protected]=>     array(0) {     }   }   ["cookies"]=>   object(symfony\component\httpfoundation\parameterbag)#1051 (1) {     ["parameters":protected]=>     array(0) {     }   }   ["headers"]=>   object(symfony\component\httpfoundation\headerbag)#1054 (2) {     ["headers":protected]=>     array(0) {     }     ["cachecontrol":protected]=>     array(0) {     }   }   ["content":protected]=>   null   ["languages":protected]=>   null   ["charsets":protected]=>   null   ["encodings":protected]=>   null   ["acceptablecontenttypes":protected]=>   null   ["pathinfo":protected]=>   null   ["requesturi":protected]=>   null   ["baseurl":protected]=>   null   ["basepath":protected]=>   null   ["method":protected]=>   null   ["format":protected]=>   null   ["session":protected]=>   null   ["locale":protected]=>   null   ["defaultlocale":protected]=>   string(2) "en" } 

edit-2:

here dump of request object sent client (in test case : var_dump($client->getrequest()->request);) :

object(symfony\component\httpfoundation\parameterbag)#753 (1) {   ["parameters":protected]=>   array(4) {     ["mediaurl"]=>     string(41) "http://example.com"     ["url"]=>     string(0) ""     ["token"]=>     string(0) ""     ["sizes"]=>     string(0) ""   } } 

the "test browser" seems sends form data app...

usually post request form return redirect, if check redirect correct response , follow redirection, example:

$client->submit($form);  $this->asserttrue($client->getresponse()->isredirect()); $this->crawler = $client->followredirect(); 

hope help

edit:

another way be:

$form = $crawler->selectbutton('ok')->form(array(     'mediaurl' => 'http://example.com') );  $client->submit($form); 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -