Skip to content

Commit

Permalink
use phpunit 9.3+ and
Browse files Browse the repository at this point in the history
1)use phpunit 9.3+
2)replace php-vfs/php-vfs with mikey179/vfsstream
3)enable deprecation warnings
  • Loading branch information
saeideng committed Feb 14, 2022
1 parent a2cf020 commit de16ace
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 18 deletions.
9 changes: 7 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -32,5 +32,10 @@
"psr-4": {
"Josegonzalez\\Upload\\Test\\": "tests"
}
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
4 changes: 4 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
processIsolation="false"
stopOnFailure="false"
bootstrap="./tests/bootstrap.php"
convertDeprecationsToExceptions="true"
>
<php>
<ini name="memory_limit" value="-1"/>
<!-- E_ALL & ~E_USER_DEPRECATED (16383)-->
<!-- E_ALL (32767) -->
<ini name="error_reporting" value="32767"/>
<ini name="apc.enable_cli" value="1"/>
</php>

Expand Down
21 changes: 10 additions & 11 deletions tests/TestCase/File/Writer/DefaultWriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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()
Expand All @@ -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', []));
}

Expand All @@ -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',
]));
}

Expand All @@ -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()
Expand Down
9 changes: 4 additions & 5 deletions tests/TestCase/Validation/ImageValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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,
];
Expand Down

0 comments on commit de16ace

Please sign in to comment.