Skip to content

Commit cf4da97

Browse files
committed
Merge branch 'master' into 2.0
* master: fixed information about how to simulate a file upload
2 parents 8abb949 + e6027eb commit cf4da97

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

book/testing.rst

+11-1
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,21 @@ additional arguments of the ``request()`` method::
286286
$client->request('POST', '/submit', array('name' => 'Fabien'));
287287

288288
// Form submission with a file upload
289-
$client->request('POST', '/submit', array('name' => 'Fabien'), array('photo' => '/path/to/photo'));
289+
use Symfony\Component\HttpFoundation\File\UploadedFile;
290+
291+
$photo = new UploadedFile('/path/to/photo.jpg', 'photo.jpg', 'image/jpeg', 123);
292+
// or
293+
$photo = array('tmp_name' => '/path/to/photo.jpg', 'name' => 'photo.jpg', 'type' => 'image/jpeg', 'size' => 123, 'error' => UPLOAD_ERR_OK);
294+
295+
$client->request('POST', '/submit', array('name' => 'Fabien'), array('photo' => $photo));
290296

291297
// Specify HTTP headers
292298
$client->request('DELETE', '/post/12', array(), array(), array('PHP_AUTH_USER' => 'username', 'PHP_AUTH_PW' => 'pa$$word'));
293299

300+
.. tip::
301+
302+
Form submissions are greatly simplified by using a crawler object (see below).
303+
294304
When a request returns a redirect response, the client automatically follows
295305
it. This behavior can be changed with the ``followRedirects()`` method::
296306

0 commit comments

Comments
 (0)