Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 101b608

Browse filesBrowse files
ahundiakDanielss89
authored andcommitted
Handles null file in createrequest bridge.
Fixed PHP 5.3.3 array syntax
1 parent 3664dc0 commit 101b608
Copy full SHA for 101b608

File tree

2 files changed

+39
-1
lines changed
Filter options

2 files changed

+39
-1
lines changed

‎Factory/DiactorosFactory.php

Copy file name to clipboardExpand all lines: Factory/DiactorosFactory.php
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ private function getFiles(array $uploadedFiles)
8686
$files = array();
8787

8888
foreach ($uploadedFiles as $key => $value) {
89+
if ($value === null) {
90+
$files[$key] = new DiactorosUploadedFile(null, 0, UPLOAD_ERR_NO_FILE, null, null);
91+
continue;
92+
}
8993
if ($value instanceof UploadedFile) {
9094
$files[$key] = $this->createUploadedFile($value);
9195
} else {
@@ -107,7 +111,7 @@ private function createUploadedFile(UploadedFile $symfonyUploadedFile)
107111
{
108112
return new DiactorosUploadedFile(
109113
$symfonyUploadedFile->getRealPath(),
110-
$symfonyUploadedFile->getSize(),
114+
$symfonyUploadedFile->getClientSize(),
111115
$symfonyUploadedFile->getError(),
112116
$symfonyUploadedFile->getClientOriginalName(),
113117
$symfonyUploadedFile->getClientMimeType()

‎Tests/Factory/DiactorosFactoryTest.php

Copy file name to clipboardExpand all lines: Tests/Factory/DiactorosFactoryTest.php
+34Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,38 @@ public function testCreateResponseFromBinaryFile()
161161

162162
$this->assertEquals('Binary', $psrResponse->getBody()->__toString());
163163
}
164+
165+
public function testUploadErrNoFile()
166+
{
167+
$file = new UploadedFile(null, null, null, 0, UPLOAD_ERR_NO_FILE, true);
168+
$this->assertEquals(0,$file->getSize());
169+
$this->assertEquals(UPLOAD_ERR_NO_FILE,$file->getError());
170+
171+
// SplFile returns false on error
172+
$this->assertEquals('boolean',gettype(($file->getSize())));
173+
$this->assertFalse($file->getSize());
174+
175+
// This is an integer, oddly enough internally size is declared as a string
176+
$this->assertTrue(is_int($file->getClientSize()));
177+
178+
$request = new Request(array(),array(),array(),array(),
179+
array(
180+
'f1' => $file,
181+
'f2' => array('name' => null, 'type' => null, 'tmp_name' => null, 'error' => UPLOAD_ERR_NO_FILE, 'size' => 0),
182+
),
183+
array(
184+
'REQUEST_METHOD' => 'POST',
185+
'HTTP_HOST' => 'dunglas.fr',
186+
'HTTP_X_SYMFONY' => '2.8',
187+
),
188+
'Content'
189+
);
190+
191+
$psrRequest = $this->factory->createRequest($request);
192+
193+
$uploadedFiles = $psrRequest->getUploadedFiles();
194+
195+
$this->assertEquals(UPLOAD_ERR_NO_FILE, $uploadedFiles['f1']->getError());
196+
$this->assertEquals(UPLOAD_ERR_NO_FILE, $uploadedFiles['f2']->getError());
197+
}
164198
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.