Skip to content

Commit

Permalink
[HttpFoundation] fix FileBag under PHP 8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpott authored and derrabus committed Jul 15, 2021
1 parent 48f7bed commit 17a1c3d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions FileBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ protected function convertFileInformation($file)
*/
protected function fixPhpFilesArray($data)
{
// Remove extra key added by PHP 8.1.
unset($data['full_path']);
$keys = array_keys($data);
sort($keys);

Expand Down
17 changes: 17 additions & 0 deletions Tests/FileBagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,23 @@ public function testShouldConvertsUploadedFiles()
$this->assertEquals($file, $bag->get('file'));
}

public function testShouldConvertsUploadedFilesPhp81()
{
$tmpFile = $this->createTempFile();
$file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain');

$bag = new FileBag(['file' => [
'name' => basename($tmpFile),
'full_path' => basename($tmpFile),
'type' => 'text/plain',
'tmp_name' => $tmpFile,
'error' => 0,
'size' => null,
]]);

$this->assertEquals($file, $bag->get('file'));
}

public function testShouldSetEmptyUploadedFilesToNull()
{
$bag = new FileBag(['file' => [
Expand Down

0 comments on commit 17a1c3d

Please sign in to comment.