Skip to content

Commit

Permalink
Fix bug in RequestTransformer::convertFile().
Browse files Browse the repository at this point in the history
It threw an exception when no file was uploaded.
  • Loading branch information
ADmad committed Jul 12, 2016
1 parent 2d1505f commit 2d7e239
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Http/RequestTransformer.php
Expand Up @@ -134,11 +134,17 @@ protected static function convertFiles($data, $files, $path = '')
*/
protected static function convertFile($file)
{
$error = $file->getError();
$tmpName = '';
if ($error === UPLOAD_ERR_OK) {
$tmpName = $file->getStream()->getMetadata('uri');
}

return [
'name' => $file->getClientFilename(),
'type' => $file->getClientMediaType(),
'tmp_name' => $file->getStream()->getMetadata('uri'),
'error' => $file->getError(),
'tmp_name' => $tmpName,
'error' => $error,
'size' => $file->getSize(),
];
}
Expand Down
16 changes: 16 additions & 0 deletions tests/TestCase/Http/RequestTransformerTest.php
Expand Up @@ -147,6 +147,13 @@ public function testToCakeParamsPopulated()
public function testToCakeUploadedFiles()
{
$files = [
'no_file' => [
'name' => ['file' => ''],
'type' => ['file' => ''],
'tmp_name' => ['file' => ''],
'error' => ['file' => UPLOAD_ERR_NO_FILE],
'size' => ['file' => 0]
],
'image_main' => [
'name' => ['file' => 'born on.txt'],
'type' => ['file' => 'text/plain'],
Expand Down Expand Up @@ -205,6 +212,15 @@ public function testToCakeUploadedFiles()
'size' => 17178,
]
],
'no_file' => [
'file' => [
'name' => '',
'type' => '',
'tmp_name' => '',
'error' => UPLOAD_ERR_NO_FILE,
'size' => 0,
]
],
'pictures' => [
0 => [
'name' => 'A cat',
Expand Down

0 comments on commit 2d7e239

Please sign in to comment.