diff --git a/CHANGELOG.md b/CHANGELOG.md index c8165776..035cff3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ Latest * [#292](https://github.com/cleverage/process-bundle/issues/292) Remove the classes, methods and options deprecated during v5: `ProcessState::getReturnCode()` / `setReturnCode()` (#503), the `cleverage_process.event_listener.data_queue` service and `DataQueueEventListener` (#311), `CheckSerializerCompilerPass`, the `KernelInterface` argument and the `$kernel` / `$logDir` properties of `CommandRunnerTask`, `ProcessLauncherTask` and `SubprocessInstance` (#318), the `process_options` option of the `process_launcher` task (see `UPGRADE.md`). Update documentation and tests. * [#292](https://github.com/cleverage/process-bundle/issues/292) Apply the behaviours announced by the deprecations of v5: an exception thrown by the `initialize()` of a task makes the process fail before any task is executed, with a `ProcessFailedException` (#222); the `event_dispatcher` task no longer dispatches its event under the class name of the event too when `event_name` is set (#189); a target property of an array destination that is neither a simple property name nor an index notation (`address.city`) throws an `UnexpectedValueException` in the `mapping` transformer (#117); the `additional_parameters` option of the `callback` transformer is removed, use `right_parameters`; a negative `flush_every` of the `counter` task is rejected (#491) (see `UPGRADE.md`). Update documentation and tests. * [#279](https://github.com/cleverage/process-bundle/issues/279) The 109 classes marked `@final since 5.4` are `final` (engine, registries, models, configurations, events, `CleverAgeProcessBundle`, concrete tasks and transformers): they can no longer be extended nor doubled by PHPUnit. The services of the bundle are typed on `ProcessManagerInterface`, `ProcessConfigurationRegistryInterface` and `TransformerRegistryInterface`, so that a decorator is injected everywhere; `ProcessManagerInterface` declares `getProcessHistory()` and `getTaskConfiguration()`, `ProcessConfigurationRegistryInterface` declares `getProcessCodes()`, and both extend `ResetInterface` (a decorator receives the `kernel.reset` tag and must delegate `reset()`). `PregFilterTransformer::transform()` returns `?string`, the `$transformerRegistry` property of `TransformerTrait` is typed on `TransformerRegistryInterface`, `SplFile::readLine()` no longer has its unused `$length` parameter (see `UPGRADE.md`). Update documentation and tests. +* [#505](https://github.com/cleverage/process-bundle/issues/505) Consistent names for the equivalent options of the tasks: `filename` is renamed `file_path` (`file_reader`, `file_writer`, `line_reader`) and `base_folder_path` is renamed `base_path` (`input_folder_browser`), without deprecation in 5.x; `input_folder_browser` adds a single `/` between a non-empty `base_path` and the input, as `input_csv_reader` does (see `UPGRADE.md`). Update documentation and tests. ## Changes * [#428](https://github.com/cleverage/process-bundle/issues/428) Tests on PHPUnit 12.5 and 13 (PHPUnit 10 and 11 dropped), with the lowest dependencies on PHP 8.3 and 8.5. diff --git a/UPGRADE.md b/UPGRADE.md index 49929de7..5324bd0e 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -69,6 +69,34 @@ A line that `csv_reader` or `input_csv_reader` cannot read (number of columns no cannot be parsed) sends `['csv_file' => , 'csv_line' => , 'csv_values' => ]` to the error output. Before, `input_csv_reader` sent its input, the file path: read it from `[csv_file]` in the error branch. +### Renamed task options + +Equivalent options have the same name in every task (without deprecation in 5.x): + +| Tasks | 5.x | 6.0 | +|---------------------------------------------|--------------------|-------------| +| `file_reader`, `file_writer`, `line_reader` | `filename` | `file_path` | +| `input_folder_browser` | `base_folder_path` | `base_path` | + +A former name fails when the process starts with `The option "filename" does not exist. Defined options are: …`. +Find them in the processes: + +```bash +grep -rnE '\b(filename|base_folder_path):' config/ +``` + +and rename the occurrences in the options of the tasks listed above only. The search also finds a task named +`filename`, a `filename` key of the data built by the process (`constant_output`, `mapping`...), or the `filename` +option of a bridge task (`archive_zip` / `archive_unzip`, renamed in archive-process-bundle v3.0, see its upgrade +guide): leave those unchanged here. A class extending `FileReaderTask` or `LineReaderTask` reads +`$options['file_path']`. + +`input_folder_browser` now adds a single `/` between a non-empty `base_path` and the input, as `input_csv_reader` +does: `base_path: /data` and the input `imports` browse `/data/imports` (`/dataimports` before). A base path used as a +prefix of the folder name (`/data/prefix_`) must be moved to the input. With a non-empty `base_path`, remove the +leading `/` of the input: `base_path: /data` and the input `/imports` browse `/data//imports` (the folder is found, but +the file paths output contain `//`). + ### Code of the transformers The code of a transformer is only given by the `code` attribute of its `cleverage.transformer` tag, or by the diff --git a/docs/reference/tasks/file_reader_task.md b/docs/reference/tasks/file_reader_task.md index c710744b..17430028 100644 --- a/docs/reference/tasks/file_reader_task.md +++ b/docs/reference/tasks/file_reader_task.md @@ -23,9 +23,9 @@ Underlying method is [file_get_contents](https://www.php.net/manual/en/function. Options ------- -| Code | Type | Required | Default | Description | -|------------|----------|:--------:|---------|------------------------------------------------------------------------------------------------------------------| -| `filename` | `string` | **X** | | Path of the file to read. An `UnexpectedValueException` is thrown if the file does not exist or is not readable | +| Code | Type | Required | Default | Description | +|-------------|----------|:--------:|---------|------------------------------------------------------------------------------------------------------------------| +| `file_path` | `string` | **X** | | Path of the file to read. An `UnexpectedValueException` is thrown if the file does not exist or is not readable | Examples -------- @@ -35,7 +35,7 @@ Examples entry: task: file_reader options: - filename: '%kernel.project_dir%/var/data/sample.txt' + file_path: '%kernel.project_dir%/var/data/sample.txt' outputs: [debug] ``` diff --git a/docs/reference/tasks/file_writer_task.md b/docs/reference/tasks/file_writer_task.md index 6b8b8c4d..4ccc8f4a 100644 --- a/docs/reference/tasks/file_writer_task.md +++ b/docs/reference/tasks/file_writer_task.md @@ -18,14 +18,14 @@ Underlying method is Symfony `Filesystem::dumpFile()` (parent directories are cr Possible outputs ---------------- -`string`: path of the written file (value of the `filename` option). +`string`: path of the written file (value of the `file_path` option). Options ------- -| Code | Type | Required | Default | Description | -|------------|----------|:--------:|---------|---------------------------| -| `filename` | `string` | **X** | | Path of the file to write | +| Code | Type | Required | Default | Description | +|-------------|----------|:--------:|---------|---------------------------| +| `file_path` | `string` | **X** | | Path of the file to write | Examples -------- @@ -35,7 +35,7 @@ Examples write_file: task: file_writer options: - filename: '%kernel.project_dir%/var/data/result.txt' + file_path: '%kernel.project_dir%/var/data/result.txt' ``` Notes diff --git a/docs/reference/tasks/input_folder_browser_task.md b/docs/reference/tasks/input_folder_browser_task.md index 35d82666..40859a19 100644 --- a/docs/reference/tasks/input_folder_browser_task.md +++ b/docs/reference/tasks/input_folder_browser_task.md @@ -15,7 +15,7 @@ Task reference Accepted inputs --------------- -`string`: path of the folder to browse, prefixed by the `base_folder_path` option. It must be an existing readable +`string`: path of the folder to browse, prefixed by the `base_path` option. It must be an existing readable directory. The folder path is released once its files have all been iterated, so each input (the same path again or a different @@ -35,11 +35,11 @@ set as error output. Options ------- -| Code | Type | Required | Default | Description | -|--------------------|-----------------------|:--------:|-----------|----------------------------------------------------------------------------------------------------------------| -| `base_folder_path` | `string` | | `''` | Prepended to the input path, without adding any separator | -| `name_pattern` | `string\|array\|null` | | `null` | Restrict files by name using a pattern (glob, regexp or string) or an array of patterns (see `Finder::name()`) | -| `empty_log_level` | `string` | | `warning` | Log level used when no file is found, one of the `Psr\Log\LogLevel` constants | +| Code | Type | Required | Default | Description | +|-------------------|-----------------------|:--------:|-----------|----------------------------------------------------------------------------------------------------------------| +| `base_path` | `string` | | `''` | Prepended to the input path; when not empty, followed by a single `/` (a trailing `/` is not doubled) | +| `name_pattern` | `string\|array\|null` | | `null` | Restrict files by name using a pattern (glob, regexp or string) or an array of patterns (see `Finder::name()`) | +| `empty_log_level` | `string` | | `warning` | Log level used when no file is found, one of the `Psr\Log\LogLevel` constants | The `folder_path` option of [FolderBrowserTask](folder_browser_task.md) is removed: the path comes from the input. @@ -51,12 +51,12 @@ Examples entry: task: constant_output options: - output: '/var/data' + output: 'var/data' outputs: [directory] directory: task: input_folder_browser options: - base_folder_path: '%kernel.project_dir%' + base_path: '%kernel.project_dir%' outputs: [read] read: task: input_file_reader diff --git a/docs/reference/tasks/line_reader_task.md b/docs/reference/tasks/line_reader_task.md index 3915bb54..8caf6631 100644 --- a/docs/reference/tasks/line_reader_task.md +++ b/docs/reference/tasks/line_reader_task.md @@ -26,9 +26,9 @@ Underlying class is [SplFileObject](https://www.php.net/manual/en/class.splfileo Options ------- -| Code | Type | Required | Default | Description | -|------------|----------|:--------:|---------|------------------------------------------------------------------------------------------------------------------| -| `filename` | `string` | **X** | | Path of the file to read. An `UnexpectedValueException` is thrown if the file does not exist or is not readable | +| Code | Type | Required | Default | Description | +|-------------|----------|:--------:|---------|------------------------------------------------------------------------------------------------------------------| +| `file_path` | `string` | **X** | | Path of the file to read. An `UnexpectedValueException` is thrown if the file does not exist or is not readable | Examples -------- @@ -40,7 +40,7 @@ Examples entry: task: line_reader options: - filename: '%kernel.project_dir%/var/data/sample.txt' + file_path: '%kernel.project_dir%/var/data/sample.txt' outputs: [trim] trim: task: transformer diff --git a/src/Task/File/FileReaderTask.php b/src/Task/File/FileReaderTask.php index 3ca9c7e6..8b6f7dc7 100644 --- a/src/Task/File/FileReaderTask.php +++ b/src/Task/File/FileReaderTask.php @@ -26,22 +26,22 @@ class FileReaderTask extends AbstractConfigurableTask public function execute(ProcessState $state): void { $options = $this->getOptions($state); - $filename = $options['filename']; + $filePath = $options['file_path']; - if (!file_exists($filename)) { - throw new UnexpectedValueException("File does not exists: '{$filename}'"); + if (!file_exists($filePath)) { + throw new UnexpectedValueException("File does not exists: '{$filePath}'"); } - if (!is_readable($filename)) { - throw new UnexpectedValueException("File is not readable: '{$filename}'"); + if (!is_readable($filePath)) { + throw new UnexpectedValueException("File is not readable: '{$filePath}'"); } - $state->setOutput(file_get_contents($filename)); + $state->setOutput(file_get_contents($filePath)); } protected function configureOptions(OptionsResolver $resolver): void { - $resolver->setRequired(['filename']); - $resolver->setAllowedTypes('filename', ['string']); + $resolver->setRequired(['file_path']); + $resolver->setAllowedTypes('file_path', ['string']); } } diff --git a/src/Task/File/FileWriterTask.php b/src/Task/File/FileWriterTask.php index ea039838..03ec9e24 100644 --- a/src/Task/File/FileWriterTask.php +++ b/src/Task/File/FileWriterTask.php @@ -25,14 +25,14 @@ public function execute(ProcessState $state): void $options = $this->getOptions($state); $fs = new Filesystem(); - $fs->dumpFile($options['filename'], $state->getInput()); + $fs->dumpFile($options['file_path'], $state->getInput()); - $state->setOutput($options['filename']); + $state->setOutput($options['file_path']); } protected function configureOptions(OptionsResolver $resolver): void { - $resolver->setRequired(['filename']); - $resolver->setAllowedTypes('filename', ['string']); + $resolver->setRequired(['file_path']); + $resolver->setAllowedTypes('file_path', ['string']); } } diff --git a/src/Task/File/InputFileReaderTask.php b/src/Task/File/InputFileReaderTask.php index 9ef9623a..2fd9063c 100644 --- a/src/Task/File/InputFileReaderTask.php +++ b/src/Task/File/InputFileReaderTask.php @@ -36,11 +36,11 @@ public function initialize(ProcessState $state): void protected function getOptions(ProcessState $state): array { $options = parent::getOptions($state); - $filename = $state->getInput(); - if (!\is_string($filename) || '' === $filename) { + $filePath = $state->getInput(); + if (!\is_string($filePath) || '' === $filePath) { throw new UnexpectedValueException('No file path given as input'); } - $options['filename'] = $filename; + $options['file_path'] = $filePath; return $options; } @@ -49,6 +49,6 @@ protected function getOptions(ProcessState $state): array protected function configureOptions(OptionsResolver $resolver): void { parent::configureOptions($resolver); - $resolver->remove('filename'); + $resolver->remove('file_path'); } } diff --git a/src/Task/File/InputFolderBrowserTask.php b/src/Task/File/InputFolderBrowserTask.php index 24245e2b..82cb6807 100644 --- a/src/Task/File/InputFolderBrowserTask.php +++ b/src/Task/File/InputFolderBrowserTask.php @@ -58,9 +58,9 @@ protected function configureOptions(OptionsResolver $resolver): void $resolver->remove(['folder_path']); $resolver->setDefaults([ - 'base_folder_path' => '', + 'base_path' => '', ]); - $resolver->setAllowedTypes('base_folder_path', ['string']); + $resolver->setAllowedTypes('base_path', ['string']); } /** @@ -71,7 +71,12 @@ protected function getOptions(ProcessState $state): array { $options = parent::getOptions($state); if ($state->getInput()) { - $folderPath = $options['base_folder_path'].$state->getInput(); + // As input_csv_reader: a non-empty base path is followed by a single separator + $basePath = (string) $options['base_path']; + if ('' !== $basePath) { + $basePath = rtrim($basePath, '/').'/'; + } + $folderPath = $basePath.$state->getInput(); if ($this->folderPath && $folderPath !== $this->folderPath) { throw new LogicException("Folder path '{$folderPath}' already initialized with a different value {$this->folderPath}"); } diff --git a/src/Task/File/InputLineReaderTask.php b/src/Task/File/InputLineReaderTask.php index 7570b0f9..a4009743 100644 --- a/src/Task/File/InputLineReaderTask.php +++ b/src/Task/File/InputLineReaderTask.php @@ -29,7 +29,7 @@ protected function getOptions(ProcessState $state): array { $options = parent::getOptions($state); if (null !== $state->getInput()) { - $options['filename'] = $state->getInput(); + $options['file_path'] = $state->getInput(); } return $options; @@ -39,6 +39,6 @@ protected function getOptions(ProcessState $state): array protected function configureOptions(OptionsResolver $resolver): void { parent::configureOptions($resolver); - $resolver->remove('filename'); + $resolver->remove('file_path'); } } diff --git a/src/Task/File/LineReaderTask.php b/src/Task/File/LineReaderTask.php index 9e2fc5de..ec238ccb 100644 --- a/src/Task/File/LineReaderTask.php +++ b/src/Task/File/LineReaderTask.php @@ -30,23 +30,23 @@ class LineReaderTask extends AbstractConfigurableTask implements IterableTaskInt public function execute(ProcessState $state): void { $options = $this->getOptions($state); - $filename = $options['filename']; + $filePath = $options['file_path']; if ($this->file instanceof \SplFileObject - && $this->file->getPathname() !== $filename) { + && $this->file->getPathname() !== $filePath) { $this->file = null; } if (!$this->file instanceof \SplFileObject) { - if (!file_exists($filename)) { - throw new UnexpectedValueException("File does not exist: '{$filename}'"); + if (!file_exists($filePath)) { + throw new UnexpectedValueException("File does not exist: '{$filePath}'"); } - if (!is_readable($filename)) { - throw new UnexpectedValueException("File is not readable: '{$filename}'"); + if (!is_readable($filePath)) { + throw new UnexpectedValueException("File is not readable: '{$filePath}'"); } - $this->file = new \SplFileObject($filename); + $this->file = new \SplFileObject($filePath); $this->file->setFlags(\SplFileObject::READ_AHEAD | \SplFileObject::SKIP_EMPTY); $this->file->rewind(); } @@ -73,7 +73,7 @@ public function next(ProcessState $state): bool protected function configureOptions(OptionsResolver $resolver): void { - $resolver->setRequired(['filename']); - $resolver->setAllowedTypes('filename', ['string']); + $resolver->setRequired(['file_path']); + $resolver->setAllowedTypes('file_path', ['string']); } } diff --git a/tests/Task/File/FileReaderTaskTest.php b/tests/Task/File/FileReaderTaskTest.php index c9601222..6b6946aa 100644 --- a/tests/Task/File/FileReaderTaskTest.php +++ b/tests/Task/File/FileReaderTaskTest.php @@ -24,6 +24,7 @@ use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException; use Symfony\Component\OptionsResolver\Exception\MissingOptionsException; +use Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException; #[\PHPUnit\Framework\Attributes\CoversClass(FileReaderTask::class)] #[\PHPUnit\Framework\Attributes\UsesClass(AbstractConfigurableTask::class)] @@ -51,14 +52,14 @@ protected function tearDown(): void public function testOutputsWholeFileContent(): void { - $state = $this->execute(['filename' => $this->tmpDir.'/sample.txt']); + $state = $this->execute(['file_path' => $this->tmpDir.'/sample.txt']); self::assertSame("line 1\nline 2\n", $state->getOutput()); } public function testIgnoresInput(): void { - $state = $this->execute(['filename' => $this->tmpDir.'/sample.txt'], $this->tmpDir.'/other.txt'); + $state = $this->execute(['file_path' => $this->tmpDir.'/sample.txt'], $this->tmpDir.'/other.txt'); self::assertSame("line 1\nline 2\n", $state->getOutput()); } @@ -67,7 +68,7 @@ public function testOutputsEmptyStringForEmptyFile(): void { (new Filesystem())->dumpFile($this->tmpDir.'/empty.txt', ''); - $state = $this->execute(['filename' => $this->tmpDir.'/empty.txt']); + $state = $this->execute(['file_path' => $this->tmpDir.'/empty.txt']); self::assertSame('', $state->getOutput()); } @@ -77,7 +78,7 @@ public function testThrowsWhenFileDoesNotExist(): void $this->expectException(\UnexpectedValueException::class); $this->expectExceptionMessage("File does not exists: '{$this->tmpDir}/missing.txt'"); - $this->execute(['filename' => $this->tmpDir.'/missing.txt']); + $this->execute(['file_path' => $this->tmpDir.'/missing.txt']); } public function testThrowsWhenFileIsNotReadable(): void @@ -92,21 +93,32 @@ public function testThrowsWhenFileIsNotReadable(): void $this->expectException(\UnexpectedValueException::class); $this->expectExceptionMessage("File is not readable: '{$filename}'"); - $this->execute(['filename' => $filename]); + $this->execute(['file_path' => $filename]); } - public function testThrowsOnMissingFilenameOption(): void + public function testThrowsOnMissingFilePathOption(): void { $this->expectException(MissingOptionsException::class); $this->execute([]); } - public function testThrowsOnInvalidFilenameOptionType(): void + public function testThrowsOnInvalidFilePathOptionType(): void { $this->expectException(InvalidOptionsException::class); - $this->execute(['filename' => 42]); + $this->execute(['file_path' => 42]); + } + + /** + * The former name of the option (before v6.0) is rejected. + */ + public function testRejectsFormerFilenameOption(): void + { + $this->expectException(UndefinedOptionsException::class); + $this->expectExceptionMessage('The option "filename" does not exist.'); + + $this->execute(['filename' => $this->tmpDir.'/sample.txt']); } /** diff --git a/tests/Task/File/FileWriterTaskTest.php b/tests/Task/File/FileWriterTaskTest.php index f3cd312a..044ff339 100644 --- a/tests/Task/File/FileWriterTaskTest.php +++ b/tests/Task/File/FileWriterTaskTest.php @@ -24,6 +24,7 @@ use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException; use Symfony\Component\OptionsResolver\Exception\MissingOptionsException; +use Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException; #[\PHPUnit\Framework\Attributes\CoversClass(FileWriterTask::class)] #[\PHPUnit\Framework\Attributes\UsesClass(AbstractConfigurableTask::class)] @@ -46,11 +47,11 @@ protected function tearDown(): void (new Filesystem())->remove($this->tmpDir); } - public function testWritesInputAndOutputsFilename(): void + public function testWritesInputAndOutputsFilePath(): void { $filename = $this->tmpDir.'/result.txt'; $task = new FileWriterTask(); - $state = $this->createState(['filename' => $filename]); + $state = $this->createState(['file_path' => $filename]); $task->initialize($state); $this->write($task, $state, "hello\nworld"); @@ -63,7 +64,7 @@ public function testCreatesMissingParentDirectories(): void { $filename = $this->tmpDir.'/sub/dir/result.txt'; $task = new FileWriterTask(); - $state = $this->createState(['filename' => $filename]); + $state = $this->createState(['file_path' => $filename]); $task->initialize($state); $this->write($task, $state, 'content'); @@ -76,7 +77,7 @@ public function testEachInputOverwritesTheFile(): void $filename = $this->tmpDir.'/result.txt'; (new Filesystem())->dumpFile($filename, 'previous content'); $task = new FileWriterTask(); - $state = $this->createState(['filename' => $filename]); + $state = $this->createState(['file_path' => $filename]); $task->initialize($state); $this->write($task, $state, 'first'); @@ -86,7 +87,7 @@ public function testEachInputOverwritesTheFile(): void self::assertSame('second', file_get_contents($filename)); } - public function testThrowsOnMissingFilenameOption(): void + public function testThrowsOnMissingFilePathOption(): void { $task = new FileWriterTask(); $state = $this->createState([]); @@ -96,16 +97,30 @@ public function testThrowsOnMissingFilenameOption(): void $task->initialize($state); } - public function testThrowsOnInvalidFilenameOptionType(): void + public function testThrowsOnInvalidFilePathOptionType(): void { $task = new FileWriterTask(); - $state = $this->createState(['filename' => ['result.txt']]); + $state = $this->createState(['file_path' => ['result.txt']]); $this->expectException(InvalidOptionsException::class); $task->initialize($state); } + /** + * The former name of the option (before v6.0) is rejected. + */ + public function testRejectsFormerFilenameOption(): void + { + $task = new FileWriterTask(); + $state = $this->createState(['filename' => $this->tmpDir.'/result.txt']); + + $this->expectException(UndefinedOptionsException::class); + $this->expectExceptionMessage('The option "filename" does not exist.'); + + $task->initialize($state); + } + private function write(FileWriterTask $task, ProcessState $state, mixed $input): void { $state->setInput($input); diff --git a/tests/Task/File/FolderBrowserTaskTest.php b/tests/Task/File/FolderBrowserTaskTest.php index 89391cff..edc9b0f6 100644 --- a/tests/Task/File/FolderBrowserTaskTest.php +++ b/tests/Task/File/FolderBrowserTaskTest.php @@ -26,6 +26,7 @@ use Psr\Log\NullLogger; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException; +use Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException; #[\PHPUnit\Framework\Attributes\CoversClass(FolderBrowserTask::class)] #[\PHPUnit\Framework\Attributes\CoversClass(InputFolderBrowserTask::class)] @@ -112,16 +113,31 @@ public function testInputFolderBrowserRequiresAFolderPathAsInput(): void } /** - * The input is concatenated to base_folder_path (without separator). + * A non-empty base_path is followed by a single separator, with or without a trailing slash. */ - public function testInputFolderBrowserBaseFolderPath(): void + #[\PHPUnit\Framework\Attributes\TestWith(['/'])] + #[\PHPUnit\Framework\Attributes\TestWith([''])] + public function testInputFolderBrowserBasePath(string $trailingSlash): void { $task = new InputFolderBrowserTask(new NullLogger()); - $state = $this->createState(['base_folder_path' => $this->tmpDir.'/']); + $state = $this->createState(['base_path' => $this->tmpDir.$trailingSlash]); self::assertSame([$this->tmpDir.'/dirB/b1.txt'], $this->iterate($task, $state, 'dirB')); } + /** + * The former name of the option (before v6.0) is rejected. + */ + public function testInputFolderBrowserRejectsFormerBaseFolderPathOption(): void + { + $task = new InputFolderBrowserTask(new NullLogger()); + + $this->expectException(UndefinedOptionsException::class); + $this->expectExceptionMessage('The option "base_folder_path" does not exist.'); + + $task->initialize($this->createState(['base_folder_path' => $this->tmpDir.'/'])); + } + /** * The options are validated when the task is initialized, before any input. */ @@ -131,7 +147,7 @@ public function testInputFolderBrowserOptionsAreValidatedOnInitialization(): voi $this->expectException(InvalidOptionsException::class); - $task->initialize($this->createState(['base_folder_path' => ['a']])); + $task->initialize($this->createState(['base_path' => ['a']])); } /** diff --git a/tests/Task/File/InputFileReaderTaskTest.php b/tests/Task/File/InputFileReaderTaskTest.php index bcbd10da..24cddbc8 100644 --- a/tests/Task/File/InputFileReaderTaskTest.php +++ b/tests/Task/File/InputFileReaderTaskTest.php @@ -130,12 +130,18 @@ public function testThrowsWhenNoFilePathIsGivenAsInput(mixed $input): void $this->read($task, $state, $input); } - public function testRejectsFilenameOption(): void + /** + * The file path comes from the input only: neither file_path nor its former name (before v6.0) is an option. + */ + #[\PHPUnit\Framework\Attributes\TestWith(['file_path'])] + #[\PHPUnit\Framework\Attributes\TestWith(['filename'])] + public function testRejectsFilePathOption(string $option): void { $task = new InputFileReaderTask(); - $state = $this->createState(['filename' => $this->tmpDir.'/a.txt']); + $state = $this->createState([$option => $this->tmpDir.'/a.txt']); $this->expectException(UndefinedOptionsException::class); + $this->expectExceptionMessage("The option \"{$option}\" does not exist."); $task->initialize($state); } diff --git a/tests/Task/File/LineReaderTaskTest.php b/tests/Task/File/LineReaderTaskTest.php index fff1bc3b..07aceb76 100644 --- a/tests/Task/File/LineReaderTaskTest.php +++ b/tests/Task/File/LineReaderTaskTest.php @@ -24,6 +24,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException; +use Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException; #[\PHPUnit\Framework\Attributes\CoversClass(LineReaderTask::class)] #[\PHPUnit\Framework\Attributes\CoversClass(InputLineReaderTask::class)] @@ -54,7 +55,7 @@ protected function tearDown(): void public function testSameFileIsReadAgainOnSecondExecution(): void { $task = new LineReaderTask(); - $state = $this->createState(['filename' => $this->tmpDir.'/a.txt']); + $state = $this->createState(['file_path' => $this->tmpDir.'/a.txt']); self::assertSame( [["a1\n", "a2\n"], ["a1\n", "a2\n"]], @@ -66,7 +67,7 @@ public function testTheLastLineIsReadWithoutFinalLineBreak(): void { self::assertSame( ["l1\n", "\n", "l3\r\n", 'l4'], - $this->iterate(new LineReaderTask(), $this->createState(['filename' => $this->tmpDir.'/no_final_line_break.txt'])), + $this->iterate(new LineReaderTask(), $this->createState(['file_path' => $this->tmpDir.'/no_final_line_break.txt'])), ); self::assertSame( ["l1\n", "\n", "l3\r\n", 'l4'], @@ -85,6 +86,19 @@ public function testInputLineReaderReadsSameFileTwice(): void ); } + /** + * The file path comes from the input only: neither file_path nor its former name (before v6.0) is an option. + */ + #[\PHPUnit\Framework\Attributes\TestWith(['file_path'])] + #[\PHPUnit\Framework\Attributes\TestWith(['filename'])] + public function testInputLineReaderRejectsFilePathOption(string $option): void + { + $this->expectException(UndefinedOptionsException::class); + $this->expectExceptionMessage("The option \"{$option}\" does not exist."); + + $this->iterate(new InputLineReaderTask(), $this->createState([$option => $this->tmpDir.'/a.txt']), $this->tmpDir.'/a.txt'); + } + public function testInputLineReaderReadsDifferentFilesSuccessively(): void { $task = new InputLineReaderTask(); @@ -94,11 +108,22 @@ public function testInputLineReaderReadsDifferentFilesSuccessively(): void self::assertSame(["b1\n"], $this->iterate($task, $state, $this->tmpDir.'/b.txt')); } - public function testFilenameMustBeAString(): void + public function testFilePathMustBeAString(): void { $this->expectException(InvalidOptionsException::class); - $this->iterate(new LineReaderTask(), $this->createState(['filename' => ['a.txt']])); + $this->iterate(new LineReaderTask(), $this->createState(['file_path' => ['a.txt']])); + } + + /** + * The former name of the option (before v6.0) is rejected. + */ + public function testRejectsFormerFilenameOption(): void + { + $this->expectException(UndefinedOptionsException::class); + $this->expectExceptionMessage('The option "filename" does not exist.'); + + $this->iterate(new LineReaderTask(), $this->createState(['filename' => $this->tmpDir.'/a.txt'])); } /**