Skip to content

Commit

Permalink
Fix Psr17Factory::createServerRequestFromGlobals() when uploaded file…
Browse files Browse the repository at this point in the history
…s have been moved (#233)
  • Loading branch information
nicolas-grekas authored Apr 26, 2023
1 parent 786d27f commit bd810d1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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

## 1.16.0 - 2023-04-26

Expand Down
2 changes: 1 addition & 1 deletion src/Psr17Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ private function normalizeFiles(array $files): array
private function createUploadedFileFromSpec(array $value)
{
if (!is_array($tmpName = $value['tmp_name'])) {
$file = $this->createStreamFromFile($tmpName, 'r');
$file = is_file($tmpName) ? $this->createStreamFromFile($tmpName, 'r') : $this->createStream();

return $this->createUploadedFile($file, $value['size'], $value['error'], $value['name'], $value['type']);
}
Expand Down
7 changes: 5 additions & 2 deletions tests/Psr17FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,14 @@ public function testFromGlobals()
'file' => [
'name' => 'MyFile.txt',
'type' => 'text/plain',
'tmp_name' => 'php://memory',
'tmp_name' => __FILE__,
'error' => UPLOAD_ERR_OK,
'size' => 123,
],
'files' => [
'name' => ['file_0' => ['NestedFile.txt']],
'type' => ['file_0' => ['text/plain']],
'tmp_name' => ['file_0' => ['php://memory']],
'tmp_name' => ['file_0' => ['/not-exists']],
'error' => ['file_0' => [UPLOAD_ERR_OK]],
'size' => ['file_0' => [123]],
],
Expand Down Expand Up @@ -339,5 +339,8 @@ public function testFromGlobals()
];

self::assertEquals($expectedFiles, $server->getUploadedFiles());

self::assertSame('plainfile', $server->getUploadedFiles()['file']->getStream()->getMetadata()['wrapper_type']);
self::assertSame('PHP', $server->getUploadedFiles()['files']['file_0'][0]->getStream()->getMetadata()['wrapper_type']);
}
}

0 comments on commit bd810d1

Please sign in to comment.