From 3e303fb3667898234fc0aac0d85089ca9a8c8fc9 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 24 May 2021 07:43:42 +0000 Subject: [PATCH] Test file uploads --- src/Util/HTTPInputData.php | 2 +- tests/Util/HTTPInputDataDouble.php | 12 ++++++++++++ tests/src/Util/HTTPInputDataTest.php | 6 ++---- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Util/HTTPInputData.php b/src/Util/HTTPInputData.php index 01678a4068..490dda5f66 100644 --- a/src/Util/HTTPInputData.php +++ b/src/Util/HTTPInputData.php @@ -141,7 +141,7 @@ class HTTPInputData return ['variables' => $variables, 'files' => $files]; } - private static function fetchFileData($stream, string $boundary, array $headers, string $filename) + protected static function fetchFileData($stream, string $boundary, array $headers, string $filename) { $error = UPLOAD_ERR_OK; diff --git a/tests/Util/HTTPInputDataDouble.php b/tests/Util/HTTPInputDataDouble.php index 6db5c44850..02ffa58701 100644 --- a/tests/Util/HTTPInputDataDouble.php +++ b/tests/Util/HTTPInputDataDouble.php @@ -83,4 +83,16 @@ class HTTPInputDataDouble extends HTTPInputData { return static::$injectedContentType; } + + protected static function fetchFileData($stream, string $boundary, array $headers, string $filename) + { + $data = parent::fetchFileData($stream, $boundary, $headers, $filename); + if (!empty($data['tmp_name'])) { + unlink($data['tmp_name']); + $data['tmp_name'] = $data['name']; + } + + return $data; + } + } diff --git a/tests/src/Util/HTTPInputDataTest.php b/tests/src/Util/HTTPInputDataTest.php index dd31669200..5e8fd228fd 100644 --- a/tests/src/Util/HTTPInputDataTest.php +++ b/tests/src/Util/HTTPInputDataTest.php @@ -64,7 +64,6 @@ class HTTPInputDataTest extends MockedTest 'files' => [] ] ], - /* 'multipart-file' => [ 'contenttype' => 'multipart/form-data;boundary=6d4d5a40-651a-4468-a62e-5a6ca2bf350d;charset=utf8', 'input' => file_get_contents(__DIR__ . '/../../datasets/http/multipart-file.httpinput'), @@ -87,21 +86,20 @@ class HTTPInputDataTest extends MockedTest 'avatar' => [ 'name' => '8ZUCS34Y5XNH', 'type' => 'image/png', - 'tmp_name' => '/tmp/phpf85nKJ', + 'tmp_name' => '8ZUCS34Y5XNH', 'error' => 0, 'size' => 349330 ], 'header' => [ 'name' => 'V2B6Z1IICGPM', 'type' => 'image/png', - 'tmp_name' => '/tmp/phpe3sqHT', + 'tmp_name' => 'V2B6Z1IICGPM', 'error' => 0, 'size' => 1323635 ] ] ] ], - */ 'form-urlencoded' => [ 'contenttype' => 'application/x-www-form-urlencoded;charset=utf8', 'input' => file_get_contents(__DIR__ . '/../../datasets/http/form-urlencoded.httpinput'),