Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
23 changes: 23 additions & 0 deletions src/Exception/UnexpectedValueException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

/*
* This file is part of the CleverAge/FlysystemProcessBundle package.
*
* Copyright (c) Clever-Age
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace CleverAge\FlysystemProcessBundle\Exception;

use CleverAge\ProcessBundle\Exception\ProcessExceptionInterface;

/**
* Thrown by the bundle, can be caught with the ProcessExceptionInterface of the process bundle.
*/
class UnexpectedValueException extends \UnexpectedValueException implements ProcessExceptionInterface
{
}
7 changes: 4 additions & 3 deletions src/Task/FileFetchTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace CleverAge\FlysystemProcessBundle\Task;

use CleverAge\FlysystemProcessBundle\Exception\UnexpectedValueException;
use CleverAge\ProcessBundle\Model\AbstractConfigurableTask;
use CleverAge\ProcessBundle\Model\IterableTaskInterface;
use CleverAge\ProcessBundle\Model\ProcessState;
Expand Down Expand Up @@ -127,20 +128,20 @@ protected function findMatchingFiles(ProcessState $state): array
} 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<string> $files */
$files = \is_array($input) ? array_values($input) : [$input];
foreach (array_unique($files) as $file) {
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;
Expand Down
3 changes: 2 additions & 1 deletion src/Task/RemoveFileTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<string> $files */
Expand Down
50 changes: 50 additions & 0 deletions tests/Exception/SplExceptionsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

/*
* This file is part of the CleverAge/FlysystemProcessBundle package.
*
* Copyright (c) Clever-Age
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace CleverAge\FlysystemProcessBundle\Tests\Exception;

use CleverAge\FlysystemProcessBundle\Exception\UnexpectedValueException;
use CleverAge\ProcessBundle\Exception\ProcessExceptionInterface;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

/**
* The exceptions thrown by the bundle can be caught as ProcessExceptionInterface, and still as the SPL exceptions they
* were before.
*/
#[CoversClass(UnexpectedValueException::class)]
class SplExceptionsTest extends TestCase
{
/**
* @return iterable<string, array{class-string<\Throwable>, 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()]);
}
}
Loading