[HttpFoundation] fix FileBag under PHP 8.1

This commit is contained in:
Alex Pott 2021-07-15 00:09:50 +01:00 committed by Alexander M. Turek
parent e5c96c4051
commit dc3504989b
2 changed files with 19 additions and 0 deletions

View File

@ -113,6 +113,8 @@ class FileBag extends ParameterBag
*/
protected function fixPhpFilesArray($data)
{
// Remove extra key added by PHP 8.1.
unset($data['full_path']);
$keys = array_keys($data);
sort($keys);

View File

@ -45,6 +45,23 @@ class FileBagTest extends TestCase
$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' => [