commit d09a91dfaafc6ce68d86a53451f73c7fd1c9decf Author: philipp lang Date: Tue Jan 30 11:42:14 2024 +0100 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..57872d0 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/vendor/ diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..a6a3662 --- /dev/null +++ b/composer.json @@ -0,0 +1,16 @@ +{ + "name": "zoomyboy/filesystem-tests", + "description": "Tests filesystems", + "autoload": { + "psr-4": { + "Zoomyboy\\FilesystemTests\\": "src/" + } + }, + "authors": [ + { + "name": "Philipp Lang", + "email": "philipp@zoomyboy.de" + } + ], + "require": {} +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..e55b330 --- /dev/null +++ b/composer.lock @@ -0,0 +1,18 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "5432d073dea9577fe882d9516969dceb", + "packages": [], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [], + "plugin-api-version": "2.2.0" +} diff --git a/src/FilesystemConfig.php b/src/FilesystemConfig.php new file mode 100644 index 0000000..f31c0e5 --- /dev/null +++ b/src/FilesystemConfig.php @@ -0,0 +1,69 @@ +host = $host; + + return $this; + } + + public function password(string $password): self + { + $this->password = $password; + + return $this; + } + + public function username(string $username): self + { + $this->username = $username; + + return $this; + } + + public function path(string $path): self + { + $this->path = $path; + + return $this; + } + + public function type(StorageType $type): self + { + $this->type = $type; + + return $this; + } + + public function swap(): void + { + if (!app()->has('original-filesystem')) { + app()->singleton('original-filesystem', fn () => app(FilesystemManager::class)); + $mock = M::mock(FilesystemManager::class)->makePartial(); + app()->instance(FilesystemManager::class, $mock); + } + + $mock = app(FilesystemManager::class); + + if ($this->type === StorageType::FTP) { + $mock->shouldReceive('createFtpDriver')->withArgs(fn ($config) => $this->host === $config['host'] && $this->username === $config['username'] && $this->password === $config['password'] && $this->path === $config['root']) + ->andReturnUsing(function () { + return app('original-filesystem')->createLocalDriver(['root' => __DIR__ . '/fakes']); + }); + } + } +} diff --git a/src/StorageType.php b/src/StorageType.php new file mode 100644 index 0000000..8b981a6 --- /dev/null +++ b/src/StorageType.php @@ -0,0 +1,11 @@ +beforeApplicationDestroyed(function () { + }); + return $this->mockedSystems[$identifier] = data_get($this->mockedSystems, $identifier, new FilesystemConfig($identifier)); + } + + public function clearFilesystems(): void + { + exec('rm -R ' . __DIR__ . '/fakes/*'); + } +}