Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[HttpFoundation] Incorrect documentation and method name for UploadedFile::getClientSize() #25324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions 12 src/Symfony/Component/Form/Tests/CompoundFormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ public function testSubmitPostOrPutRequest($method)
'author' => array(
'error' => array('image' => UPLOAD_ERR_OK),
'name' => array('image' => 'upload.png'),
'size' => array('image' => 123),
'size' => array('image' => null),
'tmp_name' => array('image' => $path),
'type' => array('image' => 'image/png'),
),
Expand All @@ -630,7 +630,7 @@ public function testSubmitPostOrPutRequest($method)

$form->handleRequest($request);

$file = new UploadedFile($path, 'upload.png', 'image/png', 123, UPLOAD_ERR_OK);
$file = new UploadedFile($path, 'upload.png', 'image/png', null, UPLOAD_ERR_OK);

$this->assertEquals('Bernhard', $form['name']->getData());
$this->assertEquals($file, $form['image']->getData());
Expand All @@ -655,7 +655,7 @@ public function testSubmitPostOrPutRequestWithEmptyRootFormName($method)
'image' => array(
'error' => UPLOAD_ERR_OK,
'name' => 'upload.png',
'size' => 123,
'size' => null,
'tmp_name' => $path,
'type' => 'image/png',
),
Expand All @@ -676,7 +676,7 @@ public function testSubmitPostOrPutRequestWithEmptyRootFormName($method)

$form->handleRequest($request);

$file = new UploadedFile($path, 'upload.png', 'image/png', 123, UPLOAD_ERR_OK);
$file = new UploadedFile($path, 'upload.png', 'image/png', null, UPLOAD_ERR_OK);

$this->assertEquals('Bernhard', $form['name']->getData());
$this->assertEquals($file, $form['image']->getData());
Expand All @@ -697,7 +697,7 @@ public function testSubmitPostOrPutRequestWithSingleChildForm($method)
'image' => array(
'error' => UPLOAD_ERR_OK,
'name' => 'upload.png',
'size' => 123,
'size' => null,
'tmp_name' => $path,
'type' => 'image/png',
),
Expand All @@ -714,7 +714,7 @@ public function testSubmitPostOrPutRequestWithSingleChildForm($method)

$form->handleRequest($request);

$file = new UploadedFile($path, 'upload.png', 'image/png', 123, UPLOAD_ERR_OK);
$file = new UploadedFile($path, 'upload.png', 'image/png', null, UPLOAD_ERR_OK);

$this->assertEquals($file, $form->getData());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,15 @@ public function requestHandlerProvider()
private function createUploadedFileMock(RequestHandlerInterface $requestHandler, $path, $originalName)
{
if ($requestHandler instanceof HttpFoundationRequestHandler) {
return new UploadedFile($path, $originalName, null, 10, null, true);
return new UploadedFile($path, $originalName, null, null, null, true);
}

return array(
'name' => $originalName,
'error' => 0,
'type' => 'text/plain',
'tmp_name' => $path,
'size' => 10,
'size' => null,
);
}
}
9 changes: 8 additions & 1 deletion 9 src/Symfony/Component/HttpFoundation/File/UploadedFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public function __construct(string $path, string $originalName, string $mimeType
$this->originalName = $this->getName($originalName);
$this->mimeType = $mimeType ?: 'application/octet-stream';
$this->size = $size;
if (null !== $size) {
@trigger_error('Passing a size in the constructor is deprecated since 4.1 and will be removed in 5.0. Use getSize() instead.', E_USER_DEPRECATED);
}
$this->error = $error ?: UPLOAD_ERR_OK;
$this->test = $test;

Expand Down Expand Up @@ -141,10 +144,14 @@ public function guessClientExtension()
* It is extracted from the request from which the file has been uploaded.
* Then it should not be considered as a safe value.
*
* @return int|null The file size
* @deprecated since 4.1 will be removed in 5.0 use getSize() instead.
*
* @return int|null The file sizes
*/
public function getClientSize()
{
@trigger_error(sprintf('"%s" is deprecated since 4.1 and will be removed in 5.0. Use getSize() instead.', __METHOD__), E_USER_DEPRECATED);

return $this->size;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function testFileUploadsWithNoMimeType()
__DIR__.'/Fixtures/test.gif',
'original.gif',
null,
filesize(__DIR__.'/Fixtures/test.gif'),
null,
UPLOAD_ERR_OK
);

Expand All @@ -57,7 +57,7 @@ public function testFileUploadsWithUnknownMimeType()
__DIR__.'/Fixtures/.unknownextension',
'original.gif',
null,
filesize(__DIR__.'/Fixtures/.unknownextension'),
null,
UPLOAD_ERR_OK
);

Expand All @@ -70,7 +70,7 @@ public function testGuessClientExtension()
__DIR__.'/Fixtures/test.gif',
'original.gif',
'image/gif',
filesize(__DIR__.'/Fixtures/test.gif'),
null,
null
);

Expand All @@ -83,7 +83,7 @@ public function testGuessClientExtensionWithIncorrectMimeType()
__DIR__.'/Fixtures/test.gif',
'original.gif',
'image/jpeg',
filesize(__DIR__.'/Fixtures/test.gif'),
null,
null
);

Expand All @@ -96,7 +96,7 @@ public function testErrorIsOkByDefault()
__DIR__.'/Fixtures/test.gif',
'original.gif',
'image/gif',
filesize(__DIR__.'/Fixtures/test.gif'),
null,
null
);

Expand All @@ -109,7 +109,7 @@ public function testGetClientOriginalName()
__DIR__.'/Fixtures/test.gif',
'original.gif',
'image/gif',
filesize(__DIR__.'/Fixtures/test.gif'),
null,
null
);

Expand All @@ -122,7 +122,7 @@ public function testGetClientOriginalExtension()
__DIR__.'/Fixtures/test.gif',
'original.gif',
'image/gif',
filesize(__DIR__.'/Fixtures/test.gif'),
null,
null
);

Expand All @@ -138,7 +138,7 @@ public function testMoveLocalFileIsNotAllowed()
__DIR__.'/Fixtures/test.gif',
'original.gif',
'image/gif',
filesize(__DIR__.'/Fixtures/test.gif'),
null,
UPLOAD_ERR_OK
);

Expand All @@ -158,7 +158,7 @@ public function testMoveLocalFileIsAllowedInTestMode()
$path,
'original.gif',
'image/gif',
filesize($path),
null,
UPLOAD_ERR_OK,
true
);
Expand All @@ -178,7 +178,7 @@ public function testGetClientOriginalNameSanitizeFilename()
__DIR__.'/Fixtures/test.gif',
'../../original.gif',
'image/gif',
filesize(__DIR__.'/Fixtures/test.gif'),
null,
null
);

Expand All @@ -191,7 +191,7 @@ public function testGetSize()
__DIR__.'/Fixtures/test.gif',
'original.gif',
'image/gif',
filesize(__DIR__.'/Fixtures/test.gif'),
null,
null
);

Expand All @@ -206,6 +206,23 @@ public function testGetSize()
$this->assertEquals(filesize(__DIR__.'/Fixtures/test'), $file->getSize());
}

/**
* @group legacy
* @expectedDeprecation Passing a size in the constructor is deprecated since 4.1 and will be removed in 5.0. Use getSize instead.
*/
public function testConstructDeprecatedSize()
{
$file = new UploadedFile(
__DIR__.'/Fixtures/test.gif',
'original.gif',
'image/gif',
filesize(__DIR__.'/Fixtures/test.gif'),
null
);

$this->assertEquals(filesize(__DIR__.'/Fixtures/test.gif'), $file->getSize());
}

public function testGetExtension()
{
$file = new UploadedFile(
Expand All @@ -223,7 +240,7 @@ public function testIsValid()
__DIR__.'/Fixtures/test.gif',
'original.gif',
null,
filesize(__DIR__.'/Fixtures/test.gif'),
null,
UPLOAD_ERR_OK,
true
);
Expand All @@ -240,7 +257,7 @@ public function testIsInvalidOnUploadError($error)
__DIR__.'/Fixtures/test.gif',
'original.gif',
null,
filesize(__DIR__.'/Fixtures/test.gif'),
null,
$error
);

Expand All @@ -264,7 +281,7 @@ public function testIsInvalidIfNotHttpUpload()
__DIR__.'/Fixtures/test.gif',
'original.gif',
null,
filesize(__DIR__.'/Fixtures/test.gif'),
null,
UPLOAD_ERR_OK
);

Expand Down
14 changes: 7 additions & 7 deletions 14 src/Symfony/Component/HttpFoundation/Tests/FileBagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ public function testFileMustBeAnArrayOrUploadedFile()
public function testShouldConvertsUploadedFiles()
{
$tmpFile = $this->createTempFile();
$file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain', 100, 0);
$file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain', null, 0);

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

$this->assertEquals($file, $bag->get('file'));
Expand Down Expand Up @@ -89,7 +89,7 @@ public function testShouldNotRemoveEmptyUploadedFilesForAssociativeArray()
public function testShouldConvertUploadedFilesWithPhpBug()
{
$tmpFile = $this->createTempFile();
$file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain', 100, 0);
$file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain', null, 0);

$bag = new FileBag(array(
'child' => array(
Expand All @@ -106,7 +106,7 @@ public function testShouldConvertUploadedFilesWithPhpBug()
'file' => 0,
),
'size' => array(
'file' => 100,
'file' => null,
),
),
));
Expand All @@ -118,7 +118,7 @@ public function testShouldConvertUploadedFilesWithPhpBug()
public function testShouldConvertNestedUploadedFilesWithPhpBug()
{
$tmpFile = $this->createTempFile();
$file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain', 100, 0);
$file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain', null, 0);

$bag = new FileBag(array(
'child' => array(
Expand All @@ -135,7 +135,7 @@ public function testShouldConvertNestedUploadedFilesWithPhpBug()
'sub' => array('file' => 0),
),
'size' => array(
'sub' => array('file' => 100),
'sub' => array('file' => null),
),
),
));
Expand All @@ -147,7 +147,7 @@ public function testShouldConvertNestedUploadedFilesWithPhpBug()
public function testShouldNotConvertNestedUploadedFiles()
{
$tmpFile = $this->createTempFile();
$file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain', 100, 0);
$file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain', null, 0);
$bag = new FileBag(array('image' => array('file' => $file)));

$files = $bag->all();
Expand Down
4 changes: 2 additions & 2 deletions 4 src/Symfony/Component/HttpKernel/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ protected function filterFiles(array $files)
'',
$value->getClientOriginalName(),
$value->getClientMimeType(),
0,
null,
UPLOAD_ERR_INI_SIZE,
true
);
Expand All @@ -177,7 +177,7 @@ protected function filterFiles(array $files)
$value->getPathname(),
$value->getClientOriginalName(),
$value->getClientMimeType(),
$value->getClientSize(),
null,
$value->getError(),
true
);
Expand Down
9 changes: 4 additions & 5 deletions 9 src/Symfony/Component/HttpKernel/Tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ public function testUploadedFile()
$client = new Client($kernel);

$files = array(
array('tmp_name' => $source, 'name' => 'original', 'type' => 'mime/original', 'size' => 123, 'error' => UPLOAD_ERR_OK),
new UploadedFile($source, 'original', 'mime/original', 123, UPLOAD_ERR_OK, true),
array('tmp_name' => $source, 'name' => 'original', 'type' => 'mime/original', 'size' => null, 'error' => UPLOAD_ERR_OK),
new UploadedFile($source, 'original', 'mime/original', null, UPLOAD_ERR_OK, true),
);

$file = null;
Expand All @@ -120,7 +120,6 @@ public function testUploadedFile()

$this->assertEquals('original', $file->getClientOriginalName());
$this->assertEquals('mime/original', $file->getClientMimeType());
$this->assertEquals('123', $file->getClientSize());
$this->assertTrue($file->isValid());
}

Expand Down Expand Up @@ -154,7 +153,7 @@ public function testUploadedFileWhenSizeExceedsUploadMaxFileSize()

$file = $this
->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile')
->setConstructorArgs(array($source, 'original', 'mime/original', 123, UPLOAD_ERR_OK, true))
->setConstructorArgs(array($source, 'original', 'mime/original', null, UPLOAD_ERR_OK, true))
->setMethods(array('getSize'))
->getMock()
;
Expand All @@ -176,7 +175,7 @@ public function testUploadedFileWhenSizeExceedsUploadMaxFileSize()
$this->assertEquals(UPLOAD_ERR_INI_SIZE, $file->getError());
$this->assertEquals('mime/original', $file->getClientMimeType());
$this->assertEquals('original', $file->getClientOriginalName());
$this->assertEquals(0, $file->getClientSize());
$this->assertEquals(0, $file->getSize());

unlink($source);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ public function testDisallowEmpty()
*/
public function testUploadedFileError($error, $message, array $params = array(), $maxSize = null)
{
$file = new UploadedFile('/path/to/file', 'originalName', 'mime', 0, $error);
$file = new UploadedFile('/path/to/file', 'originalName', 'mime', null, $error);

$constraint = new File(array(
$message => 'myMessage',
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.