Skip to content

Commit bd810d1

Browse files
Fix Psr17Factory::createServerRequestFromGlobals() when uploaded files have been moved (#233)
1 parent 786d27f commit bd810d1

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- [#230](https://github.com/php-http/discovery/pull/230) - Add Psr18Client to make it straightforward to use PSR-18
66
- [#232](https://github.com/php-http/discovery/pull/232) - Allow pinning the preferred implementations in composer.json
7+
- [#233](https://github.com/php-http/discovery/pull/233) - Fix Psr17Factory::createServerRequestFromGlobals() when uploaded files have been moved
78

89
## 1.16.0 - 2023-04-26
910

Diff for: src/Psr17Factory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ private function normalizeFiles(array $files): array
283283
private function createUploadedFileFromSpec(array $value)
284284
{
285285
if (!is_array($tmpName = $value['tmp_name'])) {
286-
$file = $this->createStreamFromFile($tmpName, 'r');
286+
$file = is_file($tmpName) ? $this->createStreamFromFile($tmpName, 'r') : $this->createStream();
287287

288288
return $this->createUploadedFile($file, $value['size'], $value['error'], $value['name'], $value['type']);
289289
}

Diff for: tests/Psr17FactoryTest.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -282,14 +282,14 @@ public function testFromGlobals()
282282
'file' => [
283283
'name' => 'MyFile.txt',
284284
'type' => 'text/plain',
285-
'tmp_name' => 'php://memory',
285+
'tmp_name' => __FILE__,
286286
'error' => UPLOAD_ERR_OK,
287287
'size' => 123,
288288
],
289289
'files' => [
290290
'name' => ['file_0' => ['NestedFile.txt']],
291291
'type' => ['file_0' => ['text/plain']],
292-
'tmp_name' => ['file_0' => ['php://memory']],
292+
'tmp_name' => ['file_0' => ['/not-exists']],
293293
'error' => ['file_0' => [UPLOAD_ERR_OK]],
294294
'size' => ['file_0' => [123]],
295295
],
@@ -339,5 +339,8 @@ public function testFromGlobals()
339339
];
340340

341341
self::assertEquals($expectedFiles, $server->getUploadedFiles());
342+
343+
self::assertSame('plainfile', $server->getUploadedFiles()['file']->getStream()->getMetadata()['wrapper_type']);
344+
self::assertSame('PHP', $server->getUploadedFiles()['files']['file_0'][0]->getStream()->getMetadata()['wrapper_type']);
342345
}
343346
}

0 commit comments

Comments
 (0)