From 0db65b5bbed1a9c348e9f47f17c251568da35e6a Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Tue, 23 Jan 2018 21:25:49 +0100 Subject: [PATCH] fix tests --- .../HttpFoundation/Tests/FileBagTest.php | 49 +++---------------- .../Component/HttpKernel/Tests/ClientTest.php | 10 ++-- .../Component/HttpKernel/composer.json | 2 +- .../Tests/Constraints/FileValidatorTest.php | 3 +- src/Symfony/Component/Validator/composer.json | 2 +- 5 files changed, 14 insertions(+), 52 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/Tests/FileBagTest.php b/src/Symfony/Component/HttpFoundation/Tests/FileBagTest.php index efb4b64f7c..06136e2097 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/FileBagTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/FileBagTest.php @@ -31,14 +31,10 @@ class FileBagTest extends TestCase new FileBag(array('file' => 'foo')); } - /** - * @group legacy - * @expectedDeprecation Passing a size as 4th argument to the constructor of "Symfony\Component\HttpFoundation\File\UploadedFile" is deprecated since Symfony 4.1 and will be unsupported in 5.0. - */ public function testShouldConvertsUploadedFiles() { $tmpFile = $this->createTempFile(); - $file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain', 0); + $file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain'); $bag = new FileBag(array('file' => array( 'name' => basename($tmpFile), @@ -64,26 +60,6 @@ class FileBagTest extends TestCase $this->assertNull($bag->get('file')); } - /** - * @group legacy - * @expectedDeprecation Passing a size as 4th argument to the constructor of "Symfony\Component\HttpFoundation\File\UploadedFile" is deprecated since Symfony 4.1 and will be unsupported in 5.0. - */ - public function testShouldNotTriggerDeprecationWhenPassingSize() - { - $tmpFile = $this->createTempFile(); - $file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain', 0); - - $bag = new FileBag(array('file' => array( - 'name' => basename($tmpFile), - 'type' => 'text/plain', - 'tmp_name' => $tmpFile, - 'error' => 0, - 'size' => 123456, - ))); - - $this->assertEquals($file, $bag->get('file')); - } - public function testShouldRemoveEmptyUploadedFilesForMultiUpload() { $bag = new FileBag(array('files' => array( @@ -110,14 +86,10 @@ class FileBagTest extends TestCase $this->assertSame(array('file1' => null), $bag->get('files')); } - /** - * @group legacy - * @expectedDeprecation Passing a size as 4th argument to the constructor of "Symfony\Component\HttpFoundation\File\UploadedFile" is deprecated since Symfony 4.1 and will be unsupported in 5.0. - */ public function testShouldConvertUploadedFilesWithPhpBug() { $tmpFile = $this->createTempFile(); - $file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain', 0); + $file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain'); $bag = new FileBag(array( 'child' => array( @@ -143,14 +115,10 @@ class FileBagTest extends TestCase $this->assertEquals($file, $files['child']['file']); } - /** - * @group legacy - * @expectedDeprecation Passing a size as 4th argument to the constructor of "Symfony\Component\HttpFoundation\File\UploadedFile" is deprecated since Symfony 4.1 and will be unsupported in 5.0. - */ public function testShouldConvertNestedUploadedFilesWithPhpBug() { $tmpFile = $this->createTempFile(); - $file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain', 0); + $file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain'); $bag = new FileBag(array( 'child' => array( @@ -176,14 +144,10 @@ class FileBagTest extends TestCase $this->assertEquals($file, $files['child']['sub']['file']); } - /** - * @group legacy - * @expectedDeprecation Passing a size as 4th argument to the constructor of "Symfony\Component\HttpFoundation\File\UploadedFile" is deprecated since Symfony 4.1 and will be unsupported in 5.0. - */ public function testShouldNotConvertNestedUploadedFiles() { $tmpFile = $this->createTempFile(); - $file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain', 0); + $file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain'); $bag = new FileBag(array('image' => array('file' => $file))); $files = $bag->all(); @@ -192,7 +156,10 @@ class FileBagTest extends TestCase protected function createTempFile() { - return tempnam(sys_get_temp_dir().'/form_test', 'FormTest'); + $tempFile = tempnam(sys_get_temp_dir().'/form_test', 'FormTest'); + file_put_contents($tempFile, '1'); + + return $tempFile; } protected function setUp() diff --git a/src/Symfony/Component/HttpKernel/Tests/ClientTest.php b/src/Symfony/Component/HttpKernel/Tests/ClientTest.php index 38666ddec3..2febf4b9d6 100644 --- a/src/Symfony/Component/HttpKernel/Tests/ClientTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/ClientTest.php @@ -94,14 +94,10 @@ class ClientTest extends TestCase $this->assertEquals('foo', $domResponse->getContent()); } - /** - * @group legacy - * @expectedDeprecation Passing a size as 4th argument to the constructor of "Symfony\Component\HttpFoundation\File\UploadedFile" is deprecated since Symfony 4.1 and will be unsupported in 5.0. - */ public function testUploadedFile() { $source = tempnam(sys_get_temp_dir(), 'source'); - file_put_contents($source, ''); + file_put_contents($source, '1'); $target = sys_get_temp_dir().'/sf.moved.file'; @unlink($target); @@ -110,7 +106,7 @@ class ClientTest extends TestCase $files = array( array('tmp_name' => $source, 'name' => 'original', 'type' => 'mime/original', 'size' => null, 'error' => UPLOAD_ERR_OK), - new UploadedFile($source, 'original', 'mime/original', 0, UPLOAD_ERR_OK, true), + new UploadedFile($source, 'original', 'mime/original', UPLOAD_ERR_OK, true), ); $file = null; @@ -125,7 +121,7 @@ class ClientTest extends TestCase $this->assertEquals('original', $file->getClientOriginalName()); $this->assertEquals('mime/original', $file->getClientMimeType()); - $this->assertEquals($file->getSize(), 0); + $this->assertEquals(1, $file->getSize()); } $file->move(dirname($target), basename($target)); diff --git a/src/Symfony/Component/HttpKernel/composer.json b/src/Symfony/Component/HttpKernel/composer.json index ebe53279be..b21d1bb643 100644 --- a/src/Symfony/Component/HttpKernel/composer.json +++ b/src/Symfony/Component/HttpKernel/composer.json @@ -18,7 +18,7 @@ "require": { "php": "^7.1.3", "symfony/event-dispatcher": "~3.4|~4.0", - "symfony/http-foundation": "~3.4.4|~4.0.4", + "symfony/http-foundation": "~4.1", "symfony/debug": "~3.4|~4.0", "psr/log": "~1.0" }, diff --git a/src/Symfony/Component/Validator/Tests/Constraints/FileValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/FileValidatorTest.php index 52a207aecd..05c2d499a3 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/FileValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/FileValidatorTest.php @@ -412,8 +412,7 @@ abstract class FileValidatorTest extends ConstraintValidatorTestCase */ public function testUploadedFileError($error, $message, array $params = array(), $maxSize = null) { - touch('/tmp/file'); - $file = new UploadedFile('/tmp/file', 'originalName', 'mime', $error); + $file = new UploadedFile(tempnam(sys_get_temp_dir(), 'file-validator-test-'), 'originalName', 'mime', $error); $constraint = new File(array( $message => 'myMessage', diff --git a/src/Symfony/Component/Validator/composer.json b/src/Symfony/Component/Validator/composer.json index cde7f94569..2e44519c27 100644 --- a/src/Symfony/Component/Validator/composer.json +++ b/src/Symfony/Component/Validator/composer.json @@ -21,7 +21,7 @@ "symfony/translation": "~3.4|~4.0" }, "require-dev": { - "symfony/http-foundation": "~3.4|~4.0", + "symfony/http-foundation": "~4.1", "symfony/http-kernel": "~3.4|~4.0", "symfony/var-dumper": "~3.4|~4.0", "symfony/intl": "~3.4|~4.0",