Skip to content

Commit

Permalink
Fix existence exception structure.
Browse files Browse the repository at this point in the history
  • Loading branch information
frankdejonge committed Jan 13, 2022
1 parent 0943e28 commit cec830e
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/AsyncAwsS3/AsyncAwsS3Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -124,7 +124,7 @@ public function fileExists(string $path): bool
]
)->isSuccess();
} catch (ClientException $e) {
throw UnableToCheckExistence::forLocation($path, $e);
throw UnableToCheckFileExistence::forLocation($path, $e);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/AsyncAwsS3/AsyncAwsS3AdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
}
Expand Down
4 changes: 2 additions & 2 deletions src/AwsS3V3/AwsS3V3Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/AwsS3V3/AwsS3V3AdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
}
Expand Down
9 changes: 9 additions & 0 deletions src/ExceptionInformationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion src/FilesystemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface FilesystemAdapter
{
/**
* @throws FilesystemException
* @throws UnableToCheckExistence
* @throws UnableToCheckFileExistence
*/
public function fileExists(string $path): bool;

Expand Down
1 change: 1 addition & 0 deletions src/FilesystemOperationFailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
3 changes: 1 addition & 2 deletions src/FilesystemReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface FilesystemReader

/**
* @throws FilesystemException
* @throws UnableToCheckExistence
* @throws UnableToCheckFileExistence
*/
public function fileExists(string $location): bool;

Expand All @@ -27,7 +27,6 @@ public function directoryExists(string $location): bool;

/**
* @throws FilesystemException
* @throws UnableToCheckDirectoryExistence
* @throws UnableToCheckExistence
*/
public function has(string $location): bool;
Expand Down
2 changes: 1 addition & 1 deletion src/MountManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/MountManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')];
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/UnableToCheckDirectoryExistence.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/UnableToCheckExistence.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions src/UnableToCheckFileExistence.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace League\Flysystem;

use RuntimeException;
use Throwable;

class UnableToCheckFileExistence extends UnableToCheckExistence
{
public static function forLocation(string $path, Throwable $exception = null): static
{
return new static("Unable to check existence for: ${path}", 0, $exception);
}

public function operation(): string
{
return FilesystemOperationFailed::OPERATION_FILE_EXISTS;
}
}

0 comments on commit cec830e

Please sign in to comment.