diff --git a/.coveralls.yml b/.coveralls.yml deleted file mode 100644 index e69de29..0000000 diff --git a/.gitignore b/.gitignore index 255b924..9cf02d8 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ vendor .idea build composer.lock +.phpunit.result.cache diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 09483af..0000000 --- a/.travis.yml +++ /dev/null @@ -1,22 +0,0 @@ -language: php - -php: - - 7.2 - - 7.3 - -sudo: false - -cache: - directories: - - $HOME/.composer/cache - -before_install: - - travis_retry composer self-update - -install: - - travis_retry composer install --no-interaction --prefer-dist --no-suggest - -script: vendor/bin/phpunit - -after_success: - - travis_retry php vendor/bin/coveralls -v diff --git a/composer.json b/composer.json index f20f6da..14d8ab6 100644 --- a/composer.json +++ b/composer.json @@ -32,16 +32,16 @@ }, "minimum-stability": "stable", "require": { - "php": ">=7.0.0", - "league/flysystem": "^1.0", - "illuminate/support": "^5.1 || ^6.0 || ^7.0", + "php": "^8.0", + "league/flysystem": "^3.0.0", + "illuminate/support": "^5.1 || ^6.0 || ^7.0 || ^9.0 || ^10.0", "mikey179/vfsstream": "^1.6" }, "require-dev": { - "phpunit/phpunit": "~6.0", + "phpunit/phpunit": "~9.0", "symfony/var-dumper": "^3", "ext-fileinfo": "*", "mockery/mockery": "~1.0", - "phpspec/phpspec": "^2.2" + "phpspec/phpspec": "^7.2" } } diff --git a/phpunit.xml b/phpunit.xml index e69739a..342e3f9 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,35 +1,22 @@ - - - - ./tests/Adapter - - - - - - - src/ - - - - - - - - - - - - - - \ No newline at end of file + + + + + + + + + + + ./tests/Adapter + + + + + + + + + + diff --git a/src/VfsFilesystemServiceProvider.php b/src/VfsFilesystemServiceProvider.php index 9d60174..6bb12fd 100644 --- a/src/VfsFilesystemServiceProvider.php +++ b/src/VfsFilesystemServiceProvider.php @@ -7,7 +7,7 @@ /** * @codeCoverageIgnore */ -class VfsFilesystemServiceProvider extends ServiceProvider { +class VfsFilesystemServiceProvider extends ServiceProvider { //boot public function boot() @@ -33,4 +33,4 @@ public function register() } -} \ No newline at end of file +} diff --git a/src/VirtualFilesystemAdapter.php b/src/VirtualFilesystemAdapter.php index 143c7cd..87878f5 100644 --- a/src/VirtualFilesystemAdapter.php +++ b/src/VirtualFilesystemAdapter.php @@ -2,7 +2,8 @@ use Illuminate\Support\Collection; use Illuminate\Support\Str; -use League\Flysystem\Adapter\Local; +use League\Flysystem\Local\LocalFilesystemAdapter; +use League\Flysystem\UnixVisibility\PortableVisibilityConverter; use org\bovigo\vfs\vfsStream; use org\bovigo\vfs\vfsStreamDirectory; use SplFileInfo; @@ -20,7 +21,8 @@ * @property int $link_handling * @property array $dirStructure */ -class VirtualFilesystemAdapter extends Local { +class VirtualFilesystemAdapter extends LocalFilesystemAdapter +{ /** * This adapters configuration @@ -33,21 +35,21 @@ class VirtualFilesystemAdapter extends Local { * @var array */ protected $defaultConfig = [ - 'dir_name' => 'root', + 'dir_name' => 'root', 'dir_permissions' => 0755, - 'dir_structure' => [], - 'write_flags' => LOCK_EX, - 'link_handling' => self::DISALLOW_LINKS, - 'permissions' => [ + 'dir_structure' => [], + 'write_flags' => 0, //LOCAK_EX doesn't work in this scenario + 'link_handling' => self::DISALLOW_LINKS, + 'permissions' => [ 'file' => [ - 'public' => 0644, + 'public' => 0644, 'private' => 0600, ], - 'dir' => [ - 'public' => 0755, + 'dir' => [ + 'public' => 0755, 'private' => 0700, - ] - ] + ], + ], ]; /** @@ -63,7 +65,8 @@ public function __construct(array $config = []) { $this->config = collect(array_replace_recursive($this->defaultConfig, $config)); $this->vfsStreamDir = vfsStream::setup($this->dirName, $this->dirPermissions, $this->dirStructure); - parent::__construct($this->vfsStreamDir->url(), $this->writeFlags, $this->linkHandling, $this->permissions); + + parent::__construct($this->vfsStreamDir->url(), PortableVisibilityConverter::fromArray($this->permissions), $this->writeFlags, $this->linkHandling); } /** @@ -93,7 +96,7 @@ public function __get($name) { $response = $this->config->get(Str::snake($name)); - if (is_null($response)){ + if (is_null($response)) { throw new \InvalidArgumentException(sprintf('%s is not a valid field.', $name)); } @@ -116,14 +119,14 @@ public function getVfsStreamDir() * @return void * @throws \Exception in case the root directory can not be created */ - protected function ensureDirectory($path) + protected function ensureDirectoryExists(string $dirname, int $visibility): void { - if ($path === $this->dirName){ + if ($dirname === $this->dirName) { // @codeCoverageIgnoreStart return; // @codeCoverageIgnoreEnd } - parent::ensureDirectory($path); + parent::ensureDirectoryExists($dirname, $visibility); } /** @@ -131,14 +134,12 @@ protected function ensureDirectory($path) * SplFileInfo::getPathname() * @param SplFileInfo $file */ - protected function deleteFileInfoObject(SplFileInfo $file) + protected function deleteFileInfoObject(SplFileInfo $file): bool { if ($file->getType() === 'dir') { - rmdir($file->getPathname()); - - return; + return @rmdir($file->getPathname()); } - unlink($file->getPathname()); + return @unlink($file->getPathname()); } } diff --git a/tests/Adapter/BasicTest.php b/tests/Adapter/BasicTest.php index edd77b2..c7a59ee 100644 --- a/tests/Adapter/BasicTest.php +++ b/tests/Adapter/BasicTest.php @@ -1,8 +1,10 @@ 0700, 'dir_structure' => [], 'write_flags' => 0, - 'link_handling' => Local::DISALLOW_LINKS, + 'link_handling' => LocalFilesystemAdapter::DISALLOW_LINKS, 'permissions' => [ 'file' => [ 'public' => 0660, @@ -71,26 +73,27 @@ public function throws_exception_on_bad_parameter(){ /** @test */ public function setup_new_vfs_directory_structure(){ - $filesystem = new Filesystem(new VirtualFilesystemAdapter()); - $filesystem->put('foo/bar/tile1.txt', 'FooBar'); + $filesystem = new Filesystem($adapter = new VirtualFilesystemAdapter()); + $filesystem->write('foo/bar/tile1.txt', 'FooBar'); $expected_1 = [ "type" => "file", "path" => "foo/bar/tile1.txt", "timestamp" => 1488331955, - "size" => 6, - "dirname" => "foo/bar", - "basename" => "tile1.txt", - "extension" => "txt", - "filename" => "tile1", + "file_size" => 6, + //"dirname" => "foo/bar", + //"basename" => "tile1.txt", + //"extension" => "txt", + //"filename" => "tile1", ]; - $actual_1 = $filesystem->listContents('foo/bar')[0]; + $actual_1 = $filesystem->listContents('foo/bar')->toArray()[0]; collect($expected_1)->each( function ($value, $key) use ($actual_1) { if ($key === 'timestamp'){ return; } + /** @var FileAttributes $actual_1 */ $this->assertEquals($value, $actual_1[$key]); } ); @@ -107,13 +110,13 @@ function ($value, $key) use ($actual_1) { ] ]; - $config = $filesystem->getAdapter()->getConfig(); + $config = $adapter->getConfig(); $config['dir_structure'] = $newStructure; vfsStream::setup($config['dir_name'], $config['dir_permissions'], $config['dir_structure']); // Ensure the old file system is gone. - $this->assertFalse($filesystem->has('foo/bar')); + $this->assertFalse($filesystem->fileExists('foo/bar')); - $this->assertTrue($filesystem->has('Core/AbstractFactory/test.php')); + $this->assertTrue($filesystem->fileExists('Core/AbstractFactory/test.php')); $this->assertEquals('some other text content', $filesystem->read('Core/AbstractFactory/other.php')); $this->assertEquals('some bad voodoo', $filesystem->read('Core/somethingwicked.php')); } @@ -121,12 +124,12 @@ function ($value, $key) use ($actual_1) { /** @test */ public function setup_new_vfs_from_local_filesystem() { - $filesystem = new Filesystem(new VirtualFilesystemAdapter()); - vfsStream::copyFromFileSystem(__DIR__ . '/../resources/filesystemcopy', $filesystem->getAdapter()->getVfsStreamDir(), 3145728); + $filesystem = new Filesystem($adapter = new VirtualFilesystemAdapter()); + vfsStream::copyFromFileSystem(__DIR__ . '/../resources/filesystemcopy', $adapter->getVfsStreamDir(), 3145728); - $this->assertTrue($filesystem->has('withSubfolders/subfolder2/multipage2.pdf')); - $this->assertEquals('application/pdf', $filesystem->getMimetype('withSubfolders/subfolder2/multipage2.pdf')); - $this->assertEquals('image/tiff', $filesystem->getMimetype('withSubfolders/subfolder2/one.TIF')); - $this->assertEquals('571382', $filesystem->getSize('withSubfolders/subfolder2/singlepage1.pdf')); + $this->assertTrue($filesystem->fileExists('withSubfolders/subfolder2/multipage2.pdf')); + $this->assertEquals('application/pdf', $filesystem->mimetype('withSubfolders/subfolder2/multipage2.pdf')); + $this->assertEquals('image/tiff', $filesystem->mimetype('withSubfolders/subfolder2/one.TIF')); + $this->assertEquals('571382', $filesystem->fileSize('withSubfolders/subfolder2/singlepage1.pdf')); } } diff --git a/tests/Adapter/FailTests.php b/tests/STS/Filesystem/FailTests.php similarity index 68% rename from tests/Adapter/FailTests.php rename to tests/STS/Filesystem/FailTests.php index 8576fb7..240110e 100644 --- a/tests/Adapter/FailTests.php +++ b/tests/STS/Filesystem/FailTests.php @@ -4,17 +4,17 @@ { function file_put_contents($name) { - if (strpos($name, 'pleasefail') !== false) { + if (str_contains($name, 'pleasefail')) { return false; } - return call_user_func_array('file_put_contents', func_get_args()); + return file_put_contents(...func_get_args()); } function file_get_contents($name) { - if (strpos($name, 'pleasefail') !== false) { + if (str_contains($name, 'pleasefail')) { return false; } - return call_user_func_array('file_get_contents', func_get_args()); + return file_get_contents(...func_get_args()); } } @@ -30,7 +30,7 @@ public function ensure_we_fail_on_all_of_these() { $adapter = new VirtualFilesystemAdapter(); $this->assertFalse($adapter->write('pleasefail.txt', 'content', new Config())); - $this->assertFalse($adapter->update('pleasefail.txt', 'content', new Config())); + $this->assertFalse($adapter->write('pleasefail.txt', 'content', new Config())); $this->assertFalse($adapter->read('pleasefail.txt')); $this->assertFalse($adapter->deleteDir('non-existing')); } diff --git a/tests/Adapter/FileTests.php b/tests/STS/Filesystem/FileTests.php similarity index 84% rename from tests/Adapter/FileTests.php rename to tests/STS/Filesystem/FileTests.php index 5b635e7..6070583 100644 --- a/tests/Adapter/FileTests.php +++ b/tests/STS/Filesystem/FileTests.php @@ -1,4 +1,5 @@ -deleteDir('files'); - $fs->createDir('files', new Config()); + $fs->createDirectory('files', new Config()); $fs->write('file.txt', 'contents', new Config()); $this->filesystem = new Filesystem($fs); } - public function tearDown() + public function tearDown(): void { try { $this->filesystem->delete('file.txt'); } catch (FileNotFoundException $e) { } - $this->filesystem->deleteDir('files'); + $this->filesystem->deleteDirectory('files'); } /** @@ -131,10 +132,10 @@ public function can_put_contents_in_file_stream() public function can_rename_file() { $file = $this->getFile(); - $result = $file->rename('files/renamed.txt'); + $result = $file->move('files/renamed.txt'); $this->assertTrue($result); - $this->assertFalse($this->filesystem->has('file.txt')); - $this->assertTrue($this->filesystem->has('files/renamed.txt')); + $this->assertFalse($this->filesystem->fileExists('file.txt')); + $this->assertTrue($this->filesystem->fileExists('files/renamed.txt')); $this->assertEquals('files/renamed.txt', $file->getPath()); } @@ -158,7 +159,7 @@ public function ensure_rename_fails() $filesystem = new Filesystem($adapter); /** @var File $file */ $file = $filesystem->get('file.txt', new File()); - $result = $file->rename('files/renamed.txt'); + $result = $file->move('files/renamed.txt'); $this->assertFalse($result); $this->assertEquals('file.txt', $file->getPath()); } @@ -168,8 +169,8 @@ public function ensure_we_can_copy_a_file() { $file = $this->getFile(); $copied = $file->copy('files/copied.txt'); - $this->assertTrue($this->filesystem->has('file.txt')); - $this->assertTrue($this->filesystem->has('files/copied.txt')); + $this->assertTrue($this->filesystem->fileExists('file.txt')); + $this->assertTrue($this->filesystem->fileExists('files/copied.txt')); $this->assertEquals('file.txt', $file->getPath()); $this->assertEquals('files/copied.txt', $copied->getPath()); } @@ -202,7 +203,7 @@ public function ensure_copy_fails() public function check_file_timestamp() { $file = $this->getFile(); - $timestamp = $this->filesystem->getTimestamp($file->getPath()); + $timestamp = $this->filesystem->lastModified($file->getPath()); $this->assertEquals($timestamp, $file->getTimestamp()); } @@ -210,7 +211,7 @@ public function check_file_timestamp() public function check_file_mimetype() { $file = $this->getFile(); - $mimetype = $this->filesystem->getMimetype($file->getPath()); + $mimetype = $this->filesystem->mimetype($file->getPath()); $this->assertEquals($mimetype, $file->getMimetype()); } @@ -218,7 +219,7 @@ public function check_file_mimetype() public function check_file_visibility() { $file = $this->getFile(); - $visibility = $this->filesystem->getVisibility($file->getPath()); + $visibility = $this->filesystem->visibility($file->getPath()); $this->assertEquals($visibility, $file->getVisibility()); } @@ -234,7 +235,7 @@ public function check_file_metadata() public function check_file_size() { $file = $this->getFile(); - $size = $this->filesystem->getSize($file->getPath()); + $size = $this->filesystem->fileSize($file->getPath()); $this->assertEquals($size, $file->getSize()); } @@ -243,15 +244,15 @@ public function ensure_we_can_delete_file() { $file = $this->getFile(); $file->delete(); - $this->assertFalse($this->filesystem->has('file.txt')); + $this->assertFalse($this->filesystem->fileExists('file.txt')); } /** @test */ public function ensure_we_can_delete_a_nested_directory() { - $this->filesystem->createDir('files/dir/nested'); + $this->filesystem->createDirectory('files/dir/nested'); - $this->assertTrue($this->filesystem->deleteDir('files/dir')); - $this->assertFalse($this->filesystem->has('files/dir')); + $this->assertTrue((bool) $this->filesystem->deleteDirectory('files/dir')); + $this->assertFalse($this->filesystem->directoryExists('files/dir')); } }