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 @@ -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
------
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/tasks/unzip_task.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`).
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/tasks/zip_task.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`).
Expand Down
3 changes: 3 additions & 0 deletions src/Task/UnzipTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
3 changes: 3 additions & 0 deletions src/Task/ZipTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -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>|string, files_base_path: string} $options
*/
Expand Down
12 changes: 12 additions & 0 deletions tests/Task/UnzipTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, mixed> $options
*
Expand Down
12 changes: 12 additions & 0 deletions tests/Task/ZipTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, mixed> $options
*
Expand Down
Loading