From de16ace5271bf1191d4a43b26ed3e6a12b1374e7 Mon Sep 17 00:00:00 2001 From: saeid Date: Mon, 14 Feb 2022 17:22:20 +0330 Subject: [PATCH] use phpunit 9.3+ and 1)use phpunit 9.3+ 2)replace php-vfs/php-vfs with mikey179/vfsstream 3)enable deprecation warnings --- composer.json | 9 ++++++-- phpunit.xml.dist | 4 ++++ .../File/Writer/DefaultWriterTest.php | 21 +++++++++---------- .../Validation/ImageValidationTest.php | 9 ++++---- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/composer.json b/composer.json index d309d1f3..926dcab8 100644 --- a/composer.json +++ b/composer.json @@ -17,10 +17,10 @@ }, "require-dev": { "cakephp/cakephp": "^4.0.2", - "phpunit/phpunit": "~8.5.0", + "phpunit/phpunit": "^8.5 || ^9.3", "cakephp/cakephp-codesniffer": "^4.0", "league/flysystem-memory": "^2.0|^3.0", - "php-vfs/php-vfs": "^1.4.2" + "mikey179/vfsstream": "^1.6.10" }, "autoload": { "psr-4": { @@ -32,5 +32,10 @@ "psr-4": { "Josegonzalez\\Upload\\Test\\": "tests" } + }, + "config": { + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true + } } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index a07d13d9..024a3378 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -3,9 +3,13 @@ processIsolation="false" stopOnFailure="false" bootstrap="./tests/bootstrap.php" + convertDeprecationsToExceptions="true" > + + + diff --git a/tests/TestCase/File/Writer/DefaultWriterTest.php b/tests/TestCase/File/Writer/DefaultWriterTest.php index 5cedefeb..602d481d 100644 --- a/tests/TestCase/File/Writer/DefaultWriterTest.php +++ b/tests/TestCase/File/Writer/DefaultWriterTest.php @@ -10,7 +10,7 @@ use League\Flysystem\UnableToDeleteFile; use League\Flysystem\UnableToMoveFile; use League\Flysystem\UnableToWriteFile; -use VirtualFileSystem\FileSystem as Vfs; +use org\bovigo\vfs\vfsStream as Vfs; class DefaultWriterTest extends TestCase { @@ -43,9 +43,8 @@ public function setUp(): void $this->settings ); - $this->vfs = new Vfs(); - mkdir($this->vfs->path('/tmp')); - file_put_contents($this->vfs->path('/tmp/tempfile'), 'content'); + $this->vfs = Vfs::setup('tmp'); + file_put_contents($this->vfs->url() . '/tempfile', 'content'); } public function testIsWriterInterface() @@ -57,11 +56,11 @@ public function testInvoke() { $this->assertEquals([], $this->writer->write([])); $this->assertEquals([true], $this->writer->write([ - $this->vfs->path('/tmp/tempfile') => 'file.txt', + $this->vfs->url() . '/tempfile' => 'file.txt', ], 'field', [])); $this->assertEquals([false], $this->writer->write([ - $this->vfs->path('/tmp/invalid.txt') => 'file.txt', + $this->vfs->url() . '/invalid.txt' => 'file.txt', ], 'field', [])); } @@ -78,11 +77,11 @@ public function testDelete() $this->assertEquals([], $writer->delete([])); $this->assertEquals([true], $writer->delete([ - $this->vfs->path('/tmp/tempfile'), + $this->vfs->url() . '/tempfile', ])); $this->assertEquals([false], $writer->delete([ - $this->vfs->path('/tmp/invalid.txt'), + $this->vfs->url() . '/invalid.txt', ])); } @@ -92,19 +91,19 @@ public function testWriteFile() $filesystem->expects($this->once())->method('writeStream'); $filesystem->expects($this->exactly(3))->method('delete'); $filesystem->expects($this->once())->method('move'); - $this->assertTrue($this->writer->writeFile($filesystem, $this->vfs->path('/tmp/tempfile'), 'path')); + $this->assertTrue($this->writer->writeFile($filesystem, $this->vfs->url() . '/tempfile', 'path')); $filesystem = $this->getMockBuilder('League\Flysystem\FilesystemOperator')->getMock(); $filesystem->expects($this->once())->method('writeStream')->will($this->throwException(new UnableToWriteFile())); $filesystem->expects($this->exactly(2))->method('delete'); $filesystem->expects($this->never())->method('move'); - $this->assertFalse($this->writer->writeFile($filesystem, $this->vfs->path('/tmp/tempfile'), 'path')); + $this->assertFalse($this->writer->writeFile($filesystem, $this->vfs->url() . '/tempfile', 'path')); $filesystem = $this->getMockBuilder('League\Flysystem\FilesystemOperator')->getMock(); $filesystem->expects($this->once())->method('writeStream'); $filesystem->expects($this->exactly(3))->method('delete'); $filesystem->expects($this->once())->method('move')->will($this->throwException(new UnableToMoveFile())); - $this->assertFalse($this->writer->writeFile($filesystem, $this->vfs->path('/tmp/tempfile'), 'path')); + $this->assertFalse($this->writer->writeFile($filesystem, $this->vfs->url() . '/tempfile', 'path')); } public function testDeletePath() diff --git a/tests/TestCase/Validation/ImageValidationTest.php b/tests/TestCase/Validation/ImageValidationTest.php index d7762897..d9d08ddc 100644 --- a/tests/TestCase/Validation/ImageValidationTest.php +++ b/tests/TestCase/Validation/ImageValidationTest.php @@ -6,7 +6,7 @@ use Cake\TestSuite\TestCase; use Josegonzalez\Upload\Validation\ImageValidation; use Laminas\Diactoros\UploadedFile; -use VirtualFileSystem\FileSystem as Vfs; +use org\bovigo\vfs\vfsStream as Vfs; class ImageValidationTest extends TestCase { @@ -17,18 +17,17 @@ public function setUp(): void { parent::setUp(); - $this->vfs = new Vfs(); - mkdir($this->vfs->path('/tmp')); + $this->vfs = Vfs::setup('tmp'); // Write sample image with dimensions: 20x20 - $img = fopen($this->vfs->path('/tmp/tmpimage'), 'wb'); + $img = fopen($this->vfs->url() . '/tmpimage', 'wb'); fwrite($img, base64_decode('iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAB3RJTUUH4AMUECwX5I9GIwAAACFJREFUOMtj/P//PwM1ARMDlcGogaMGjho4auCogUPFQABpCwMlgqgSYAAAAABJRU5ErkJggg==')); fclose($img); $this->data = [ 'name' => 'sample.txt', 'type' => 'text/plain', - 'tmp_name' => $this->vfs->path('/tmp/tmpimage'), + 'tmp_name' => $this->vfs->url() . '/tmpimage', 'size' => 200, 'error' => UPLOAD_ERR_OK, ];