testing - Symfony functional tests: receive uploaded file -


i have html form contains following input: <input type="file" name="sentfile" /> form has not been generated $this->createformbuilder(). have written class extends webtestcase. testing method following:

$crawler = $client->request('get', '/users/import'); $buttoncrawlernode = $crawler->selectbutton('import'); $form = $buttoncrawlernode->form(); $testfile = 'import_users.csv'; $destination = 'f:/www/symfony/web/uploads/' . $testfile; $form['sentfile']->upload($destination); $form['myparam'] = 'hello'; $crawler = $client->submit($form); 

but when run test phpunit command, controller method receives posted form shows empty $_files. other input (myparam) correctly received. how can use uploaded file?

ps:

  • i have not succeeded use phpt in symfony (stackoverflow.com/questions/4922207/integrate-phpt-test-cases-with-phpunit/4925061).
  • i have not tried selenium yet

references:

the content of $_files not seems changeable simulate file upload, solution use http://api.symfony.com/2.0/symfony/component/httpfoundation/file/uploadedfile.html class. jakub said, when form submitted way wrote in question, request object of controller filled content, can use $request->files->get('sentfile') uploadedfile corresponds file sent via sentfile input of form.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -