Skip to content

Commit 6f56d87

Browse files
realmfoofabpot
authored andcommitted
[HttpKernel] fixed file uploads in functional tests when no file was selected
Allow user to submit a form with no file selected.
1 parent 48980b0 commit 6f56d87

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/Symfony/Component/HttpKernel/Client.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ protected function filterRequest(DomRequest $request)
143143
{
144144
$httpRequest = Request::create($request->getUri(), $request->getMethod(), $request->getParameters(), $request->getCookies(), $request->getFiles(), $request->getServer(), $request->getContent());
145145

146-
$httpRequest->files->replace($this->filterFiles($httpRequest->files->all()));
146+
foreach ($this->filterFiles($httpRequest->files->all()) as $key => $value) {
147+
$httpRequest->files->set($key, $value);
148+
}
147149

148150
return $httpRequest;
149151
}
@@ -189,8 +191,6 @@ protected function filterFiles(array $files)
189191
true
190192
);
191193
}
192-
} else {
193-
$filtered[$key] = $value;
194194
}
195195
}
196196

src/Symfony/Component/HttpKernel/Tests/ClientTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,21 @@ public function testUploadedFile()
143143
unlink($target);
144144
}
145145

146+
public function testUploadedFileWhenNoFileSelected()
147+
{
148+
$kernel = new TestHttpKernel();
149+
$client = new Client($kernel);
150+
151+
$file = array('tmp_name' => '', 'name' => '', 'type' => '', 'size' => 0, 'error' => UPLOAD_ERR_NO_FILE);
152+
153+
$client->request('POST', '/', array(), array('foo' => $file));
154+
155+
$files = $client->getRequest()->files->all();
156+
157+
$this->assertCount(1, $files);
158+
$this->assertNull($files['foo']);
159+
}
160+
146161
public function testUploadedFileWhenSizeExceedsUploadMaxFileSize()
147162
{
148163
$source = tempnam(sys_get_temp_dir(), 'source');

0 commit comments

Comments
 (0)