diff --git a/src/Tasks/CollectionFactory/CollectionFactory.php b/src/Tasks/CollectionFactory/CollectionFactory.php index b26f753..cc06685 100644 --- a/src/Tasks/CollectionFactory/CollectionFactory.php +++ b/src/Tasks/CollectionFactory/CollectionFactory.php @@ -173,7 +173,9 @@ protected function taskFactory($task) $taskExec->args($task['arguments']); } if (!empty($task['options'])) { - $taskExec->options($task['options'], '='); + foreach ($task['options'] as $option => $value) { + $taskExec->optionList($option, $value); + } } return $taskExec; @@ -214,7 +216,9 @@ protected function taskFactory($task) $taskExec->args($task['arguments']); } if (!empty($task['options'])) { - $taskExec->options($task['options']); + foreach ($task['options'] as $option => $value) { + $taskExec->optionList($option, $value); + } } if (!empty($task['dir'])) { $taskExec->dir($task['dir']); diff --git a/tests/Tasks/CollectionFactoryTest.php b/tests/Tasks/CollectionFactoryTest.php index 49ef235..205a0d4 100644 --- a/tests/Tasks/CollectionFactoryTest.php +++ b/tests/Tasks/CollectionFactoryTest.php @@ -78,7 +78,7 @@ public function testProcessPhpTask($type, $override, $destinationExists, $source */ public function testRunTask() { - $filePath = $this->getSandboxFilepath('test-file.txt'); + $filePath = $this->getSandboxFilepath('test-file-run.txt'); $tasks = []; $tasks[] = [ @@ -89,10 +89,14 @@ public function testRunTask() ], 'options' => [ 'filepath' => $filePath, + 'array-opt' => [ + 'opt1', + 'opt2', + ], ], ]; $this->taskCollectionFactory($tasks)->run(); - $this->assertSame(__METHOD__, file_get_contents($filePath)); + $this->assertSame(__METHOD__ . 'opt1opt2', file_get_contents($filePath)); } /** @@ -100,25 +104,28 @@ public function testRunTask() */ public function testExecTask(): void { + $filePath = $this->getSandboxFilepath('test-file-exec.txt'); + $tasks = [ [ 'task' => 'exec', - 'command' => 'touch', + 'command' => __DIR__ . '/../../bin/run', 'arguments' => [ - 'file.txt', + 'custom:test', + __METHOD__, ], 'options' => [ - // 1980-06-06 23:59:59. - '-t' => '198006062359.59' + 'filepath' => $filePath, + 'array-opt' => [ + 'opt1', + 'opt2', + ], ], 'dir' => $this->getSandboxRoot(), ], ]; $this->taskCollectionFactory($tasks)->run(); - - $this->assertFileExists($this->getSandboxFilepath('file.txt')); - $mtime = gmdate('Y-m-d H:i:s', filemtime($this->getSandboxFilepath('file.txt'))); - $this->assertSame('1980-06-06 23:59:59', $mtime); + $this->assertSame(__METHOD__ . 'opt1opt2', file_get_contents($filePath)); } /** diff --git a/tests/custom/src/TaskRunner/Commands/TestCommands.php b/tests/custom/src/TaskRunner/Commands/TestCommands.php index 334931b..f2d4ffd 100644 --- a/tests/custom/src/TaskRunner/Commands/TestCommands.php +++ b/tests/custom/src/TaskRunner/Commands/TestCommands.php @@ -19,11 +19,13 @@ class TestCommands extends AbstractCommands * @param array $options * * @option filepath + * @option array-opt */ public function customTest(string $content, array $options = [ 'filepath' => InputOption::VALUE_REQUIRED, + 'array-opt' => [], ]): void { - file_put_contents($options['filepath'], $content); + file_put_contents($options['filepath'], $content . $options['array-opt'][0] . $options['array-opt'][1]); } }