From ca5d5e157ba1bd1d43473df8bb18906bda645cef Mon Sep 17 00:00:00 2001 From: philipp lang Date: Tue, 30 Jan 2024 13:30:50 +0100 Subject: [PATCH] Return fake filesystem --- src/FilesystemConfig.php | 10 ++++++++-- src/TestsFilesystems.php | 8 ++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/FilesystemConfig.php b/src/FilesystemConfig.php index f31c0e5..d8a2dd7 100644 --- a/src/FilesystemConfig.php +++ b/src/FilesystemConfig.php @@ -14,6 +14,10 @@ class FilesystemConfig public string $path; public StorageType $type; + public function __construct(public string $identifier) + { + } + public function host(string $host): self { $this->host = $host; @@ -49,7 +53,7 @@ class FilesystemConfig return $this; } - public function swap(): void + public function swap() { if (!app()->has('original-filesystem')) { app()->singleton('original-filesystem', fn () => app(FilesystemManager::class)); @@ -62,8 +66,10 @@ class FilesystemConfig 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']); + return app('original-filesystem')->createLocalDriver(['root' => __DIR__ . '/fakes/' . $this->identifier]); }); + + return app('original-filesystem')->createLocalDriver(['root' => __DIR__ . '/fakes/' . $this->identifier]); } } } diff --git a/src/TestsFilesystems.php b/src/TestsFilesystems.php index 32f8b47..eb0bb6c 100644 --- a/src/TestsFilesystems.php +++ b/src/TestsFilesystems.php @@ -5,18 +5,14 @@ namespace Zoomyboy\FilesystemTests; trait TestsFilesystems { - public $mockedSystems = []; public bool $mocked = false; public function mockFilesystem(string $identifier): FilesystemConfig { $this->beforeApplicationDestroyed(function () { + @exec('rm -R ' . __DIR__ . '/fakes/* > /dev/null 2>&1'); }); - return $this->mockedSystems[$identifier] = data_get($this->mockedSystems, $identifier, new FilesystemConfig($identifier)); - } - public function clearFilesystems(): void - { - exec('rm -R ' . __DIR__ . '/fakes/*'); + return new FilesystemConfig($identifier); } }