From 6f56d878c91c1570003f9d43a6aa27fec4cb408e Mon Sep 17 00:00:00 2001 From: realmfoo Date: Wed, 21 May 2014 00:16:09 +0400 Subject: [PATCH] [HttpKernel] fixed file uploads in functional tests when no file was selected Allow user to submit a form with no file selected. --- src/Symfony/Component/HttpKernel/Client.php | 6 +++--- .../Component/HttpKernel/Tests/ClientTest.php | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Client.php b/src/Symfony/Component/HttpKernel/Client.php index a663350bf1..5ef739ba8d 100644 --- a/src/Symfony/Component/HttpKernel/Client.php +++ b/src/Symfony/Component/HttpKernel/Client.php @@ -143,7 +143,9 @@ EOF; { $httpRequest = Request::create($request->getUri(), $request->getMethod(), $request->getParameters(), $request->getCookies(), $request->getFiles(), $request->getServer(), $request->getContent()); - $httpRequest->files->replace($this->filterFiles($httpRequest->files->all())); + foreach ($this->filterFiles($httpRequest->files->all()) as $key => $value) { + $httpRequest->files->set($key, $value); + } return $httpRequest; } @@ -189,8 +191,6 @@ EOF; true ); } - } else { - $filtered[$key] = $value; } } diff --git a/src/Symfony/Component/HttpKernel/Tests/ClientTest.php b/src/Symfony/Component/HttpKernel/Tests/ClientTest.php index 8e1b6c1e6f..4d9918b504 100644 --- a/src/Symfony/Component/HttpKernel/Tests/ClientTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/ClientTest.php @@ -143,6 +143,21 @@ class ClientTest extends \PHPUnit_Framework_TestCase unlink($target); } + public function testUploadedFileWhenNoFileSelected() + { + $kernel = new TestHttpKernel(); + $client = new Client($kernel); + + $file = array('tmp_name' => '', 'name' => '', 'type' => '', 'size' => 0, 'error' => UPLOAD_ERR_NO_FILE); + + $client->request('POST', '/', array(), array('foo' => $file)); + + $files = $client->getRequest()->files->all(); + + $this->assertCount(1, $files); + $this->assertNull($files['foo']); + } + public function testUploadedFileWhenSizeExceedsUploadMaxFileSize() { $source = tempnam(sys_get_temp_dir(), 'source');