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

Commit 157f01a

Browse filesBrowse files
author
Amrouche Hamza
committed
[HttpFoundation] Incorrect documentation and method name for UploadedFile::getClientSize()
1 parent 8e7eac6 commit 157f01a
Copy full SHA for 157f01a

File tree

8 files changed

+61
-38
lines changed
Filter options

8 files changed

+61
-38
lines changed

‎src/Symfony/Component/Form/Tests/CompoundFormTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/CompoundFormTest.php
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ public function testSubmitPostOrPutRequest($method)
609609
'author' => array(
610610
'error' => array('image' => UPLOAD_ERR_OK),
611611
'name' => array('image' => 'upload.png'),
612-
'size' => array('image' => 123),
612+
'size' => array('image' => null),
613613
'tmp_name' => array('image' => $path),
614614
'type' => array('image' => 'image/png'),
615615
),
@@ -630,7 +630,7 @@ public function testSubmitPostOrPutRequest($method)
630630

631631
$form->handleRequest($request);
632632

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

635635
$this->assertEquals('Bernhard', $form['name']->getData());
636636
$this->assertEquals($file, $form['image']->getData());
@@ -655,7 +655,7 @@ public function testSubmitPostOrPutRequestWithEmptyRootFormName($method)
655655
'image' => array(
656656
'error' => UPLOAD_ERR_OK,
657657
'name' => 'upload.png',
658-
'size' => 123,
658+
'size' => null,
659659
'tmp_name' => $path,
660660
'type' => 'image/png',
661661
),
@@ -676,7 +676,7 @@ public function testSubmitPostOrPutRequestWithEmptyRootFormName($method)
676676

677677
$form->handleRequest($request);
678678

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

681681
$this->assertEquals('Bernhard', $form['name']->getData());
682682
$this->assertEquals($file, $form['image']->getData());
@@ -697,7 +697,7 @@ public function testSubmitPostOrPutRequestWithSingleChildForm($method)
697697
'image' => array(
698698
'error' => UPLOAD_ERR_OK,
699699
'name' => 'upload.png',
700-
'size' => 123,
700+
'size' => null,
701701
'tmp_name' => $path,
702702
'type' => 'image/png',
703703
),
@@ -714,7 +714,7 @@ public function testSubmitPostOrPutRequestWithSingleChildForm($method)
714714

715715
$form->handleRequest($request);
716716

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

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

‎src/Symfony/Component/Form/Tests/Extension/Core/Type/FileTypeTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Extension/Core/Type/FileTypeTest.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,15 +188,15 @@ public function requestHandlerProvider()
188188
private function createUploadedFileMock(RequestHandlerInterface $requestHandler, $path, $originalName)
189189
{
190190
if ($requestHandler instanceof HttpFoundationRequestHandler) {
191-
return new UploadedFile($path, $originalName, null, 10, null, true);
191+
return new UploadedFile($path, $originalName, null, null, null, true);
192192
}
193193

194194
return array(
195195
'name' => $originalName,
196196
'error' => 0,
197197
'type' => 'text/plain',
198198
'tmp_name' => $path,
199-
'size' => 10,
199+
'size' => null,
200200
);
201201
}
202202
}

‎src/Symfony/Component/HttpFoundation/File/UploadedFile.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/File/UploadedFile.php
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ public function __construct(string $path, string $originalName, string $mimeType
6060
$this->originalName = $this->getName($originalName);
6161
$this->mimeType = $mimeType ?: 'application/octet-stream';
6262
$this->size = $size;
63+
if (null !== $size) {
64+
@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);
65+
}
6366
$this->error = $error ?: UPLOAD_ERR_OK;
6467
$this->test = $test;
6568

@@ -141,10 +144,14 @@ public function guessClientExtension()
141144
* It is extracted from the request from which the file has been uploaded.
142145
* Then it should not be considered as a safe value.
143146
*
144-
* @return int|null The file size
147+
* @deprecated since 4.1 will be removed in 5.0 use getSize instead.
148+
*
149+
* @return int|null The file sizes
145150
*/
146151
public function getClientSize()
147152
{
153+
@trigger_error(sprintf('"%s" is deprecated since 4.1 and will be removed in 5.0. Use getSize instead.', __METHOD__), E_USER_DEPRECATED);
154+
148155
return $this->size;
149156
}
150157

‎src/Symfony/Component/HttpFoundation/Tests/File/UploadedFileTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Tests/File/UploadedFileTest.php
+31-14Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function testFileUploadsWithNoMimeType()
4040
__DIR__.'/Fixtures/test.gif',
4141
'original.gif',
4242
null,
43-
filesize(__DIR__.'/Fixtures/test.gif'),
43+
null,
4444
UPLOAD_ERR_OK
4545
);
4646

@@ -57,7 +57,7 @@ public function testFileUploadsWithUnknownMimeType()
5757
__DIR__.'/Fixtures/.unknownextension',
5858
'original.gif',
5959
null,
60-
filesize(__DIR__.'/Fixtures/.unknownextension'),
60+
null,
6161
UPLOAD_ERR_OK
6262
);
6363

@@ -70,7 +70,7 @@ public function testGuessClientExtension()
7070
__DIR__.'/Fixtures/test.gif',
7171
'original.gif',
7272
'image/gif',
73-
filesize(__DIR__.'/Fixtures/test.gif'),
73+
null,
7474
null
7575
);
7676

@@ -83,7 +83,7 @@ public function testGuessClientExtensionWithIncorrectMimeType()
8383
__DIR__.'/Fixtures/test.gif',
8484
'original.gif',
8585
'image/jpeg',
86-
filesize(__DIR__.'/Fixtures/test.gif'),
86+
null,
8787
null
8888
);
8989

@@ -96,7 +96,7 @@ public function testErrorIsOkByDefault()
9696
__DIR__.'/Fixtures/test.gif',
9797
'original.gif',
9898
'image/gif',
99-
filesize(__DIR__.'/Fixtures/test.gif'),
99+
null,
100100
null
101101
);
102102

@@ -109,7 +109,7 @@ public function testGetClientOriginalName()
109109
__DIR__.'/Fixtures/test.gif',
110110
'original.gif',
111111
'image/gif',
112-
filesize(__DIR__.'/Fixtures/test.gif'),
112+
null,
113113
null
114114
);
115115

@@ -122,7 +122,7 @@ public function testGetClientOriginalExtension()
122122
__DIR__.'/Fixtures/test.gif',
123123
'original.gif',
124124
'image/gif',
125-
filesize(__DIR__.'/Fixtures/test.gif'),
125+
null,
126126
null
127127
);
128128

@@ -138,7 +138,7 @@ public function testMoveLocalFileIsNotAllowed()
138138
__DIR__.'/Fixtures/test.gif',
139139
'original.gif',
140140
'image/gif',
141-
filesize(__DIR__.'/Fixtures/test.gif'),
141+
null,
142142
UPLOAD_ERR_OK
143143
);
144144

@@ -158,7 +158,7 @@ public function testMoveLocalFileIsAllowedInTestMode()
158158
$path,
159159
'original.gif',
160160
'image/gif',
161-
filesize($path),
161+
null,
162162
UPLOAD_ERR_OK,
163163
true
164164
);
@@ -178,7 +178,7 @@ public function testGetClientOriginalNameSanitizeFilename()
178178
__DIR__.'/Fixtures/test.gif',
179179
'../../original.gif',
180180
'image/gif',
181-
filesize(__DIR__.'/Fixtures/test.gif'),
181+
null,
182182
null
183183
);
184184

@@ -191,7 +191,7 @@ public function testGetSize()
191191
__DIR__.'/Fixtures/test.gif',
192192
'original.gif',
193193
'image/gif',
194-
filesize(__DIR__.'/Fixtures/test.gif'),
194+
null,
195195
null
196196
);
197197

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

209+
/**
210+
* @group legacy
211+
* @expectedDeprecation Passing a size in the constructor is deprecated since 4.1 and will be removed in 5.0. Use getSize instead.
212+
*/
213+
public function testConstructDeprecatedSize()
214+
{
215+
$file = new UploadedFile(
216+
__DIR__.'/Fixtures/test.gif',
217+
'original.gif',
218+
'image/gif',
219+
filesize(__DIR__.'/Fixtures/test.gif'),
220+
null
221+
);
222+
223+
$this->assertEquals(filesize(__DIR__.'/Fixtures/test.gif'), $file->getSize());
224+
}
225+
209226
public function testGetExtension()
210227
{
211228
$file = new UploadedFile(
@@ -223,7 +240,7 @@ public function testIsValid()
223240
__DIR__.'/Fixtures/test.gif',
224241
'original.gif',
225242
null,
226-
filesize(__DIR__.'/Fixtures/test.gif'),
243+
null,
227244
UPLOAD_ERR_OK,
228245
true
229246
);
@@ -240,7 +257,7 @@ public function testIsInvalidOnUploadError($error)
240257
__DIR__.'/Fixtures/test.gif',
241258
'original.gif',
242259
null,
243-
filesize(__DIR__.'/Fixtures/test.gif'),
260+
null,
244261
$error
245262
);
246263

@@ -264,7 +281,7 @@ public function testIsInvalidIfNotHttpUpload()
264281
__DIR__.'/Fixtures/test.gif',
265282
'original.gif',
266283
null,
267-
filesize(__DIR__.'/Fixtures/test.gif'),
284+
null,
268285
UPLOAD_ERR_OK
269286
);
270287

‎src/Symfony/Component/HttpFoundation/Tests/FileBagTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Tests/FileBagTest.php
+7-7Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ public function testFileMustBeAnArrayOrUploadedFile()
3434
public function testShouldConvertsUploadedFiles()
3535
{
3636
$tmpFile = $this->createTempFile();
37-
$file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain', 100, 0);
37+
$file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain', null, 0);
3838

3939
$bag = new FileBag(array('file' => array(
4040
'name' => basename($tmpFile),
4141
'type' => 'text/plain',
4242
'tmp_name' => $tmpFile,
4343
'error' => 0,
44-
'size' => 100,
44+
'size' => null,
4545
)));
4646

4747
$this->assertEquals($file, $bag->get('file'));
@@ -89,7 +89,7 @@ public function testShouldNotRemoveEmptyUploadedFilesForAssociativeArray()
8989
public function testShouldConvertUploadedFilesWithPhpBug()
9090
{
9191
$tmpFile = $this->createTempFile();
92-
$file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain', 100, 0);
92+
$file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain', null, 0);
9393

9494
$bag = new FileBag(array(
9595
'child' => array(
@@ -106,7 +106,7 @@ public function testShouldConvertUploadedFilesWithPhpBug()
106106
'file' => 0,
107107
),
108108
'size' => array(
109-
'file' => 100,
109+
'file' => null,
110110
),
111111
),
112112
));
@@ -118,7 +118,7 @@ public function testShouldConvertUploadedFilesWithPhpBug()
118118
public function testShouldConvertNestedUploadedFilesWithPhpBug()
119119
{
120120
$tmpFile = $this->createTempFile();
121-
$file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain', 100, 0);
121+
$file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain', null, 0);
122122

123123
$bag = new FileBag(array(
124124
'child' => array(
@@ -135,7 +135,7 @@ public function testShouldConvertNestedUploadedFilesWithPhpBug()
135135
'sub' => array('file' => 0),
136136
),
137137
'size' => array(
138-
'sub' => array('file' => 100),
138+
'sub' => array('file' => null),
139139
),
140140
),
141141
));
@@ -147,7 +147,7 @@ public function testShouldConvertNestedUploadedFilesWithPhpBug()
147147
public function testShouldNotConvertNestedUploadedFiles()
148148
{
149149
$tmpFile = $this->createTempFile();
150-
$file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain', 100, 0);
150+
$file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain', null, 0);
151151
$bag = new FileBag(array('image' => array('file' => $file)));
152152

153153
$files = $bag->all();

‎src/Symfony/Component/HttpKernel/Client.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Client.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ protected function filterFiles(array $files)
168168
'',
169169
$value->getClientOriginalName(),
170170
$value->getClientMimeType(),
171-
0,
171+
null,
172172
UPLOAD_ERR_INI_SIZE,
173173
true
174174
);
@@ -177,7 +177,7 @@ protected function filterFiles(array $files)
177177
$value->getPathname(),
178178
$value->getClientOriginalName(),
179179
$value->getClientMimeType(),
180-
$value->getClientSize(),
180+
null,
181181
$value->getError(),
182182
true
183183
);

‎src/Symfony/Component/HttpKernel/Tests/ClientTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Tests/ClientTest.php
+4-5Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ public function testUploadedFile()
104104
$client = new Client($kernel);
105105

106106
$files = array(
107-
array('tmp_name' => $source, 'name' => 'original', 'type' => 'mime/original', 'size' => 123, 'error' => UPLOAD_ERR_OK),
108-
new UploadedFile($source, 'original', 'mime/original', 123, UPLOAD_ERR_OK, true),
107+
array('tmp_name' => $source, 'name' => 'original', 'type' => 'mime/original', 'size' => null, 'error' => UPLOAD_ERR_OK),
108+
new UploadedFile($source, 'original', 'mime/original', null, UPLOAD_ERR_OK, true),
109109
);
110110

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

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

@@ -154,7 +153,7 @@ public function testUploadedFileWhenSizeExceedsUploadMaxFileSize()
154153

155154
$file = $this
156155
->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile')
157-
->setConstructorArgs(array($source, 'original', 'mime/original', 123, UPLOAD_ERR_OK, true))
156+
->setConstructorArgs(array($source, 'original', 'mime/original', null, UPLOAD_ERR_OK, true))
158157
->setMethods(array('getSize'))
159158
->getMock()
160159
;
@@ -176,7 +175,7 @@ public function testUploadedFileWhenSizeExceedsUploadMaxFileSize()
176175
$this->assertEquals(UPLOAD_ERR_INI_SIZE, $file->getError());
177176
$this->assertEquals('mime/original', $file->getClientMimeType());
178177
$this->assertEquals('original', $file->getClientOriginalName());
179-
$this->assertEquals(0, $file->getClientSize());
178+
$this->assertEquals(0, $file->getSize());
180179

181180
unlink($source);
182181
}

‎src/Symfony/Component/Validator/Tests/Constraints/FileValidatorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Tests/Constraints/FileValidatorTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ public function testDisallowEmpty()
411411
*/
412412
public function testUploadedFileError($error, $message, array $params = array(), $maxSize = null)
413413
{
414-
$file = new UploadedFile('/path/to/file', 'originalName', 'mime', 0, $error);
414+
$file = new UploadedFile('/path/to/file', 'originalName', 'mime', null, $error);
415415

416416
$constraint = new File(array(
417417
$message => 'myMessage',

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.