From cd9b0608226bcf801fe366b4591ddb97b9d4daa7 Mon Sep 17 00:00:00 2001 From: Nicolas Joubert Date: Wed, 30 Sep 2026 15:27:25 +0200 Subject: [PATCH] fix(task) #18 ZipTask and UnzipTask throw an explicit UnexpectedValueException on a non-array input Co-Authored-By: Claude Opus 5.5 (1M context) --- CHANGELOG.md | 1 + docs/reference/tasks/unzip_task.md | 2 +- docs/reference/tasks/zip_task.md | 2 +- src/Task/UnzipTask.php | 3 +++ src/Task/ZipTask.php | 3 +++ tests/Task/UnzipTaskTest.php | 12 ++++++++++++ tests/Task/ZipTaskTest.php | 12 ++++++++++++ 7 files changed, 33 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa62bc4..9231346 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Latest * [#15](https://github.com/cleverage/archive-process-bundle/issues/15) Fix ZipTask and UnzipTask: resolve the options on every execution, so that each input is used (the options of the first input were reused for the following ones). Update documentation, add tests. * [#16](https://github.com/cleverage/archive-process-bundle/issues/16) Fix ZipTask: only remove the leading `files_base_path` from the file paths (every occurrence was removed), and read the files at the given path when `files_base_path` is empty (relative paths were resolved from the filesystem root). Update documentation, add tests. * [#17](https://github.com/cleverage/archive-process-bundle/issues/17) Fix ZipTask and UnzipTask: throw a `\RuntimeException` when the archive cannot be written (ZipTask) or extracted (UnzipTask), instead of outputting the path anyway; add the `ZipArchive` error code to the UnzipTask open failure message. Update documentation, add tests. +* [#18](https://github.com/cleverage/archive-process-bundle/issues/18) Fix ZipTask and UnzipTask: throw an explicit `\UnexpectedValueException` on a non-array input (e.g. a `string` path) instead of an unrelated warning or `TypeError`. Update documentation, add tests. v2.1 ------ diff --git a/docs/reference/tasks/unzip_task.md b/docs/reference/tasks/unzip_task.md index af4e46f..e324cc1 100644 --- a/docs/reference/tasks/unzip_task.md +++ b/docs/reference/tasks/unzip_task.md @@ -17,7 +17,7 @@ configured ones. It may only contain the `filename` and/or `destination` keys (a `UndefinedOptionsException`). A `null` input is handled as an empty array, so the options come from the task configuration only. -Any other input type (e.g. a `string` file path) is not supported: convert it into an array first, for instance with a +Any other input type (e.g. a `string` file path) is not supported and throws an `\UnexpectedValueException`: convert it into an array first, for instance with a [TransformerTask](https://github.com/cleverage/process-bundle/blob/main/docs/reference/tasks/transformer_task.md) and the [wrapper](https://github.com/cleverage/process-bundle/blob/main/docs/reference/transformers/wrapper_transformer.md) transformer (`wrapper_key: filename`). diff --git a/docs/reference/tasks/zip_task.md b/docs/reference/tasks/zip_task.md index 018f52e..44f188a 100644 --- a/docs/reference/tasks/zip_task.md +++ b/docs/reference/tasks/zip_task.md @@ -17,7 +17,7 @@ configured ones. It may only contain the `filename`, `files` and/or `files_base_ `UndefinedOptionsException`). A `null` input is handled as an empty array, so the options come from the task configuration only. -Any other input type (e.g. a `string` file path) is not supported: convert it into an array first, for instance with a +Any other input type (e.g. a `string` file path) is not supported and throws an `\UnexpectedValueException`: convert it into an array first, for instance with a [TransformerTask](https://github.com/cleverage/process-bundle/blob/main/docs/reference/tasks/transformer_task.md) and the [wrapper](https://github.com/cleverage/process-bundle/blob/main/docs/reference/transformers/wrapper_transformer.md) transformer (`wrapper_key: files`). diff --git a/src/Task/UnzipTask.php b/src/Task/UnzipTask.php index ea87e72..12bb462 100644 --- a/src/Task/UnzipTask.php +++ b/src/Task/UnzipTask.php @@ -27,6 +27,9 @@ public function execute(ProcessState $state): void if (null === $state->getInput()) { $state->setInput([]); } + if (!\is_array($state->getInput())) { + throw new \UnexpectedValueException(\sprintf('UnzipTask expects an array or null input, %s given', get_debug_type($state->getInput()))); + } /** * @var array{filename: string, destination: string} $options */ diff --git a/src/Task/ZipTask.php b/src/Task/ZipTask.php index 69e41b2..5a59fd4 100644 --- a/src/Task/ZipTask.php +++ b/src/Task/ZipTask.php @@ -27,6 +27,9 @@ public function execute(ProcessState $state): void if (null === $state->getInput()) { $state->setInput([]); } + if (!\is_array($state->getInput())) { + throw new \UnexpectedValueException(\sprintf('ZipTask expects an array or null input, %s given', get_debug_type($state->getInput()))); + } /** * @var array{filename: string, files: array|string, files_base_path: string} $options */ diff --git a/tests/Task/UnzipTaskTest.php b/tests/Task/UnzipTaskTest.php index 4aa49df..63848be 100644 --- a/tests/Task/UnzipTaskTest.php +++ b/tests/Task/UnzipTaskTest.php @@ -99,6 +99,18 @@ public function testOpenFailureGivesTheErrorCode(): void } } + public function testNonArrayInput(): void + { + [$task, $state] = $this->createTask([]); + + try { + $this->execute($task, $state, 'file.zip'); + self::fail('An \UnexpectedValueException should have been thrown'); + } catch (\UnexpectedValueException $e) { + self::assertSame('UnzipTask expects an array or null input, string given', $e->getMessage()); + } + } + /** * @param array $options * diff --git a/tests/Task/ZipTaskTest.php b/tests/Task/ZipTaskTest.php index 40ea9df..cab5fc0 100644 --- a/tests/Task/ZipTaskTest.php +++ b/tests/Task/ZipTaskTest.php @@ -116,6 +116,18 @@ public function testWriteFailure(): void self::assertNull($state->getOutput()); } + public function testNonArrayInput(): void + { + [$task, $state] = $this->createTask([]); + + try { + $this->execute($task, $state, 'file.zip'); + self::fail('An \UnexpectedValueException should have been thrown'); + } catch (\UnexpectedValueException $e) { + self::assertSame('ZipTask expects an array or null input, string given', $e->getMessage()); + } + } + /** * @param array $options *