From 198a83ff100d66514ba258147b81c42159009044 Mon Sep 17 00:00:00 2001 From: Nicolas Joubert Date: Tue, 20 Oct 2026 17:25:25 +0200 Subject: [PATCH] #65 - Throw exceptions implementing ProcessExceptionInterface instead of raw SPL exceptions As cleverage/process-bundle#317: new exceptions of the bundle extending the SPL exceptions thrown before and implementing ProcessExceptionInterface (4 throw replaced, same messages). Tests and CHANGELOG updated. Co-Authored-By: Claude Opus 5.5 (1M context) --- CHANGELOG.md | 1 + src/Exception/UnexpectedValueException.php | 23 ++++++++++ src/Task/FileFetchTask.php | 7 +-- src/Task/RemoveFileTask.php | 3 +- tests/Exception/SplExceptionsTest.php | 50 ++++++++++++++++++++++ 5 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 src/Exception/UnexpectedValueException.php create mode 100644 tests/Exception/SplExceptionsTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 16f25c8..3917f99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ Latest ------ ### Changes +* [#65](https://github.com/cleverage/flysystem-process-bundle/issues/65) The bundle throws exceptions implementing `ProcessExceptionInterface` of the process bundle instead of raw SPL exceptions (as [cleverage/process-bundle#317](https://github.com/cleverage/process-bundle/issues/317)): new `Exception\UnexpectedValueException`, extending the SPL exceptions thrown before (same messages, the existing `catch` keep working). Add tests. * [#63](https://github.com/cleverage/flysystem-process-bundle/issues/63) Composer: require PHP `^8.2` instead of `>=8.2` (PHP 9 is no longer accepted before being tested), remove the authorization of the `symfony/flex` plugin, which is not required (the CI installs it globally), as [cleverage/process-bundle#319](https://github.com/cleverage/process-bundle/issues/319). * [#58](https://github.com/cleverage/flysystem-process-bundle/issues/58) Define the public API (Symfony BC promise, as [cleverage/process-bundle#279](https://github.com/cleverage/process-bundle/issues/279)): `FileFetchTask`, `ListContentTask`, `RemoveFileTask` and `CleverAgeFlysystemProcessBundle` are marked `@final since 3.3`, they will be `final` in 4.0: extending them triggers a deprecation with the Symfony `DebugClassLoader`. `CleverAgeFlysystemProcessExtension` is marked `@internal`. * [#57](https://github.com/cleverage/flysystem-process-bundle/issues/57) `CleverAgeFlysystemProcessExtension::findServices()` loads the service definition files with a glob pattern instead of a `Finder` (same files, as [cleverage/process-bundle#271](https://github.com/cleverage/process-bundle/issues/271)), `symfony/finder` is no longer required. Add tests. diff --git a/src/Exception/UnexpectedValueException.php b/src/Exception/UnexpectedValueException.php new file mode 100644 index 0000000..e880731 --- /dev/null +++ b/src/Exception/UnexpectedValueException.php @@ -0,0 +1,23 @@ +getInput(); if (null === $input || '' === $input || [] === $input) { - throw new \UnexpectedValueException('No pattern neither input provided for the Task'); + throw new UnexpectedValueException('No pattern neither input provided for the Task'); } /** @var list $files */ $files = \is_array($input) ? array_values($input) : [$input]; @@ -135,12 +136,12 @@ protected function findMatchingFiles(ProcessState $state): array if ($this->sourceFS->fileExists($file)) { $matchingFiles[] = $file; } elseif (!$ignoreMissing) { - throw new \UnexpectedValueException("File {$file} not found in source filesystem"); + throw new UnexpectedValueException("File {$file} not found in source filesystem"); } } } if ([] === $matchingFiles && !$ignoreMissing) { - throw new \UnexpectedValueException('File(s) not found in source filesystem'); + throw new UnexpectedValueException('File(s) not found in source filesystem'); } return $matchingFiles; diff --git a/src/Task/RemoveFileTask.php b/src/Task/RemoveFileTask.php index a53d99e..928a0dc 100644 --- a/src/Task/RemoveFileTask.php +++ b/src/Task/RemoveFileTask.php @@ -13,6 +13,7 @@ namespace CleverAge\FlysystemProcessBundle\Task; +use CleverAge\FlysystemProcessBundle\Exception\UnexpectedValueException; use CleverAge\ProcessBundle\Model\AbstractConfigurableTask; use CleverAge\ProcessBundle\Model\ProcessState; use League\Flysystem\FilesystemException; @@ -63,7 +64,7 @@ public function execute(ProcessState $state): void } else { $input = $state->getInput(); if (null === $input || '' === $input || [] === $input) { - throw new \UnexpectedValueException('No pattern neither input provided for the Task'); + throw new UnexpectedValueException('No pattern neither input provided for the Task'); } /** @var list $files */ diff --git a/tests/Exception/SplExceptionsTest.php b/tests/Exception/SplExceptionsTest.php new file mode 100644 index 0000000..543e3ca --- /dev/null +++ b/tests/Exception/SplExceptionsTest.php @@ -0,0 +1,50 @@ +, class-string<\Throwable>}> + */ + public static function provideExceptions(): iterable + { + yield 'UnexpectedValueException' => [UnexpectedValueException::class, \UnexpectedValueException::class]; + } + + /** + * @param class-string<\Throwable> $class + * @param class-string<\Throwable> $splClass + */ + #[DataProvider('provideExceptions')] + public function testExtendsTheSplExceptionAndImplementsTheInterface(string $class, string $splClass): void + { + $exception = new $class('message', 12); + + self::assertInstanceOf($splClass, $exception); + self::assertInstanceOf(ProcessExceptionInterface::class, $exception); + self::assertSame(['message', 12], [$exception->getMessage(), $exception->getCode()]); + } +}