From 3446a71daa3bfaf652f973561daf844b0e8ba5a9 Mon Sep 17 00:00:00 2001 From: Artx Hundiak Date: Wed, 19 Aug 2015 10:01:54 -0500 Subject: [PATCH 1/2] Handles null file in createrequest bridge. --- Factory/DiactorosFactory.php | 6 ++++- Tests/Factory/DiactorosFactoryTest.php | 34 ++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/Factory/DiactorosFactory.php b/Factory/DiactorosFactory.php index 31726f1..f0fc0d3 100644 --- a/Factory/DiactorosFactory.php +++ b/Factory/DiactorosFactory.php @@ -86,6 +86,10 @@ private function getFiles(array $uploadedFiles) $files = array(); foreach ($uploadedFiles as $key => $value) { + if ($value === null) { + $files[$key] = new DiactorosUploadedFile(null, 0, UPLOAD_ERR_NO_FILE, null, null); + continue; + } if ($value instanceof UploadedFile) { $files[$key] = $this->createUploadedFile($value); } else { @@ -107,7 +111,7 @@ private function createUploadedFile(UploadedFile $symfonyUploadedFile) { return new DiactorosUploadedFile( $symfonyUploadedFile->getRealPath(), - $symfonyUploadedFile->getSize(), + $symfonyUploadedFile->getClientSize(), $symfonyUploadedFile->getError(), $symfonyUploadedFile->getClientOriginalName(), $symfonyUploadedFile->getClientMimeType() diff --git a/Tests/Factory/DiactorosFactoryTest.php b/Tests/Factory/DiactorosFactoryTest.php index a4c32bd..3009342 100644 --- a/Tests/Factory/DiactorosFactoryTest.php +++ b/Tests/Factory/DiactorosFactoryTest.php @@ -161,4 +161,38 @@ public function testCreateResponseFromBinaryFile() $this->assertEquals('Binary', $psrResponse->getBody()->__toString()); } + + public function testUploadErrNoFile() + { + $file = new UploadedFile(null, null, null, 0, UPLOAD_ERR_NO_FILE, true); + $this->assertEquals(0,$file->getSize()); + $this->assertEquals(UPLOAD_ERR_NO_FILE,$file->getError()); + + // SplFile returns false on error + $this->assertEquals('boolean',gettype(($file->getSize()))); + $this->assertFalse($file->getSize()); + + // This is an integer, oddly enough internally size is declared as a string + $this->assertTrue(is_int($file->getClientSize())); + + $request = new Request([],[],[],[], + [ + 'f1' => $file, + 'f2' => ['name' => null, 'type' => null, 'tmp_name' => null, 'error' => UPLOAD_ERR_NO_FILE, 'size' => 0], + ], + [ + 'REQUEST_METHOD' => 'POST', + 'HTTP_HOST' => 'dunglas.fr', + 'HTTP_X_SYMFONY' => '2.8', + ], + 'Content' + ); + + $psrRequest = $this->factory->createRequest($request); + + $uploadedFiles = $psrRequest->getUploadedFiles(); + + $this->assertEquals(UPLOAD_ERR_NO_FILE, $uploadedFiles['f1']->getError()); + $this->assertEquals(UPLOAD_ERR_NO_FILE, $uploadedFiles['f2']->getError()); + } } From 1a46f413882806cb6ddaab4db20dcf2b6721ea32 Mon Sep 17 00:00:00 2001 From: Artx Hundiak Date: Wed, 19 Aug 2015 11:35:22 -0500 Subject: [PATCH 2/2] Fixed PHP 5.3.3 array syntax --- Tests/Factory/DiactorosFactoryTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Tests/Factory/DiactorosFactoryTest.php b/Tests/Factory/DiactorosFactoryTest.php index 3009342..c6ab6dc 100644 --- a/Tests/Factory/DiactorosFactoryTest.php +++ b/Tests/Factory/DiactorosFactoryTest.php @@ -175,16 +175,16 @@ public function testUploadErrNoFile() // This is an integer, oddly enough internally size is declared as a string $this->assertTrue(is_int($file->getClientSize())); - $request = new Request([],[],[],[], - [ + $request = new Request(array(),array(),array(),array(), + array( 'f1' => $file, - 'f2' => ['name' => null, 'type' => null, 'tmp_name' => null, 'error' => UPLOAD_ERR_NO_FILE, 'size' => 0], - ], - [ + 'f2' => array('name' => null, 'type' => null, 'tmp_name' => null, 'error' => UPLOAD_ERR_NO_FILE, 'size' => 0), + ), + array( 'REQUEST_METHOD' => 'POST', 'HTTP_HOST' => 'dunglas.fr', 'HTTP_X_SYMFONY' => '2.8', - ], + ), 'Content' );