From cec830e6de78ded362a179d3fd44d5b2b703f8ba Mon Sep 17 00:00:00 2001 From: Frank de Jonge Date: Thu, 13 Jan 2022 22:11:49 +0100 Subject: [PATCH] Fix existence exception structure. --- src/AsyncAwsS3/AsyncAwsS3Adapter.php | 4 ++-- src/AsyncAwsS3/AsyncAwsS3AdapterTest.php | 4 ++-- src/AwsS3V3/AwsS3V3Adapter.php | 4 ++-- src/AwsS3V3/AwsS3V3AdapterTest.php | 4 ++-- src/ExceptionInformationTest.php | 9 +++++++++ src/FilesystemAdapter.php | 2 +- src/FilesystemOperationFailed.php | 1 + src/FilesystemReader.php | 3 +-- src/MountManager.php | 2 +- src/MountManagerTest.php | 2 +- src/UnableToCheckDirectoryExistence.php | 4 ++-- src/UnableToCheckExistence.php | 4 ++-- src/UnableToCheckFileExistence.php | 21 +++++++++++++++++++++ 13 files changed, 47 insertions(+), 17 deletions(-) create mode 100644 src/UnableToCheckFileExistence.php diff --git a/src/AsyncAwsS3/AsyncAwsS3Adapter.php b/src/AsyncAwsS3/AsyncAwsS3Adapter.php index 50ece92dd..a29ef4ad2 100644 --- a/src/AsyncAwsS3/AsyncAwsS3Adapter.php +++ b/src/AsyncAwsS3/AsyncAwsS3Adapter.php @@ -19,7 +19,7 @@ use League\Flysystem\FilesystemAdapter; use League\Flysystem\PathPrefixer; use League\Flysystem\StorageAttributes; -use League\Flysystem\UnableToCheckExistence; +use League\Flysystem\UnableToCheckFileExistence; use League\Flysystem\UnableToCopyFile; use League\Flysystem\UnableToDeleteFile; use League\Flysystem\UnableToMoveFile; @@ -124,7 +124,7 @@ public function fileExists(string $path): bool ] )->isSuccess(); } catch (ClientException $e) { - throw UnableToCheckExistence::forLocation($path, $e); + throw UnableToCheckFileExistence::forLocation($path, $e); } } diff --git a/src/AsyncAwsS3/AsyncAwsS3AdapterTest.php b/src/AsyncAwsS3/AsyncAwsS3AdapterTest.php index c42ace1f8..72171c730 100644 --- a/src/AsyncAwsS3/AsyncAwsS3AdapterTest.php +++ b/src/AsyncAwsS3/AsyncAwsS3AdapterTest.php @@ -19,7 +19,7 @@ use League\Flysystem\FileAttributes; use League\Flysystem\FilesystemAdapter; use League\Flysystem\StorageAttributes; -use League\Flysystem\UnableToCheckExistence; +use League\Flysystem\UnableToCheckFileExistence; use League\Flysystem\UnableToDeleteFile; use League\Flysystem\UnableToMoveFile; use League\Flysystem\UnableToRetrieveMetadata; @@ -198,7 +198,7 @@ public function failing_to_check_for_file_existence(): void $exception = new ClientException(new SimpleMockedResponse()); static::$stubS3Client->throwExceptionWhenExecutingCommand('ObjectExists', $exception); - $this->expectException(UnableToCheckExistence::class); + $this->expectException(UnableToCheckFileExistence::class); $adapter->fileExists('something-that-does-exist.txt'); } diff --git a/src/AwsS3V3/AwsS3V3Adapter.php b/src/AwsS3V3/AwsS3V3Adapter.php index 1247b3cef..157eb09a5 100644 --- a/src/AwsS3V3/AwsS3V3Adapter.php +++ b/src/AwsS3V3/AwsS3V3Adapter.php @@ -15,7 +15,7 @@ use League\Flysystem\PathPrefixer; use League\Flysystem\StorageAttributes; use League\Flysystem\UnableToCheckDirectoryExistence; -use League\Flysystem\UnableToCheckExistence; +use League\Flysystem\UnableToCheckFileExistence; use League\Flysystem\UnableToCopyFile; use League\Flysystem\UnableToDeleteFile; use League\Flysystem\UnableToMoveFile; @@ -128,7 +128,7 @@ public function fileExists(string $path): bool try { return $this->client->doesObjectExist($this->bucket, $this->prefixer->prefixPath($path), $this->options); } catch (Throwable $exception) { - throw UnableToCheckExistence::forLocation($path, $exception); + throw UnableToCheckFileExistence::forLocation($path, $exception); } } diff --git a/src/AwsS3V3/AwsS3V3AdapterTest.php b/src/AwsS3V3/AwsS3V3AdapterTest.php index 5d14e6d96..4ef2d56e1 100644 --- a/src/AwsS3V3/AwsS3V3AdapterTest.php +++ b/src/AwsS3V3/AwsS3V3AdapterTest.php @@ -15,7 +15,7 @@ use League\Flysystem\FilesystemAdapter; use League\Flysystem\PathPrefixer; use League\Flysystem\StorageAttributes; -use League\Flysystem\UnableToCheckExistence; +use League\Flysystem\UnableToCheckFileExistence; use League\Flysystem\UnableToDeleteFile; use League\Flysystem\UnableToMoveFile; use League\Flysystem\UnableToRetrieveMetadata; @@ -215,7 +215,7 @@ public function failing_to_check_for_file_existence(): void static::$stubS3Client->throw500ExceptionWhenExecutingCommand('HeadObject'); - $this->expectException(UnableToCheckExistence::class); + $this->expectException(UnableToCheckFileExistence::class); $adapter->fileExists('something-that-does-exist.txt'); } diff --git a/src/ExceptionInformationTest.php b/src/ExceptionInformationTest.php index 36208f022..a91cbb565 100644 --- a/src/ExceptionInformationTest.php +++ b/src/ExceptionInformationTest.php @@ -57,6 +57,15 @@ public function delete_file_exception_information(): void $this->assertEquals(FilesystemOperationFailed::OPERATION_DELETE, $exception->operation()); } + /** + * @test + */ + public function unable_to_check_for_file_existence(): void + { + $exception = UnableToCheckFileExistence::forLocation('location'); + $this->assertEquals(FilesystemOperationFailed::OPERATION_FILE_EXISTS, $exception->operation()); + } + /** * @test */ diff --git a/src/FilesystemAdapter.php b/src/FilesystemAdapter.php index 005710261..31ffe9fc2 100644 --- a/src/FilesystemAdapter.php +++ b/src/FilesystemAdapter.php @@ -8,7 +8,7 @@ interface FilesystemAdapter { /** * @throws FilesystemException - * @throws UnableToCheckExistence + * @throws UnableToCheckFileExistence */ public function fileExists(string $path): bool; diff --git a/src/FilesystemOperationFailed.php b/src/FilesystemOperationFailed.php index 9a3ed5697..1f61a6c4d 100644 --- a/src/FilesystemOperationFailed.php +++ b/src/FilesystemOperationFailed.php @@ -10,6 +10,7 @@ interface FilesystemOperationFailed extends FilesystemException public const OPERATION_UPDATE = 'UPDATE'; public const OPERATION_EXISTENCE_CHECK = 'EXISTENCE_CHECK'; public const OPERATION_DIRECTORY_EXISTS = 'DIRECTORY_EXISTS'; + public const OPERATION_FILE_EXISTS = 'FILE_EXISTS'; public const OPERATION_CREATE_DIRECTORY = 'CREATE_DIRECTORY'; public const OPERATION_DELETE = 'DELETE'; public const OPERATION_DELETE_DIRECTORY = 'DELETE_DIRECTORY'; diff --git a/src/FilesystemReader.php b/src/FilesystemReader.php index 8fe53c7db..62194d9a9 100644 --- a/src/FilesystemReader.php +++ b/src/FilesystemReader.php @@ -15,7 +15,7 @@ interface FilesystemReader /** * @throws FilesystemException - * @throws UnableToCheckExistence + * @throws UnableToCheckFileExistence */ public function fileExists(string $location): bool; @@ -27,7 +27,6 @@ public function directoryExists(string $location): bool; /** * @throws FilesystemException - * @throws UnableToCheckDirectoryExistence * @throws UnableToCheckExistence */ public function has(string $location): bool; diff --git a/src/MountManager.php b/src/MountManager.php index bb6069fa5..3dfd93e25 100644 --- a/src/MountManager.php +++ b/src/MountManager.php @@ -33,7 +33,7 @@ public function fileExists(string $location): bool try { return $filesystem->fileExists($path); } catch (Throwable $exception) { - throw UnableToCheckExistence::forLocation($location, $exception); + throw UnableToCheckFileExistence::forLocation($location, $exception); } } diff --git a/src/MountManagerTest.php b/src/MountManagerTest.php index db14fea46..0469f6ed5 100644 --- a/src/MountManagerTest.php +++ b/src/MountManagerTest.php @@ -135,7 +135,7 @@ public function dpMetadataRetrieverMethods(): iterable yield 'createDirectory' => ['createDirectory', UnableToCreateDirectory::atLocation('location.txt')]; yield 'read' => ['read', UnableToReadFile::fromLocation('location.txt')]; yield 'readStream' => ['readStream', UnableToReadFile::fromLocation('location.txt')]; - yield 'fileExists' => ['fileExists', UnableToCheckExistence::forLocation('location.txt')]; + yield 'fileExists' => ['fileExists', UnableToCheckFileExistence::forLocation('location.txt')]; } /** diff --git a/src/UnableToCheckDirectoryExistence.php b/src/UnableToCheckDirectoryExistence.php index 63abbd2b4..a935f012b 100644 --- a/src/UnableToCheckDirectoryExistence.php +++ b/src/UnableToCheckDirectoryExistence.php @@ -8,9 +8,9 @@ class UnableToCheckDirectoryExistence extends UnableToCheckExistence { - public static function forLocation(string $path, Throwable $exception = null): UnableToCheckExistence + public static function forLocation(string $path, Throwable $exception = null): static { - return new UnableToCheckDirectoryExistence("Unable to check directory existence for: ${path}", 0, $exception); + return new static("Unable to check directory existence for: ${path}", 0, $exception); } public function operation(): string diff --git a/src/UnableToCheckExistence.php b/src/UnableToCheckExistence.php index be74855c9..c70561bce 100644 --- a/src/UnableToCheckExistence.php +++ b/src/UnableToCheckExistence.php @@ -9,9 +9,9 @@ class UnableToCheckExistence extends RuntimeException implements FilesystemOperationFailed { - public static function forLocation(string $path, Throwable $exception = null): UnableToCheckExistence + public static function forLocation(string $path, Throwable $exception = null): static { - return new UnableToCheckExistence("Unable to check existence for: ${path}", 0, $exception); + return new static("Unable to check existence for: ${path}", 0, $exception); } public function operation(): string diff --git a/src/UnableToCheckFileExistence.php b/src/UnableToCheckFileExistence.php new file mode 100644 index 000000000..ba494b83e --- /dev/null +++ b/src/UnableToCheckFileExistence.php @@ -0,0 +1,21 @@ +