diff --git a/src/Tasks/CollectionFactory/CollectionFactory.php b/src/Tasks/CollectionFactory/CollectionFactory.php index 13928979..a6e8d2fd 100644 --- a/src/Tasks/CollectionFactory/CollectionFactory.php +++ b/src/Tasks/CollectionFactory/CollectionFactory.php @@ -103,6 +103,7 @@ public function getHelp() protected function taskFactory($task) { if (is_string($task)) { + @trigger_error('Defining a task as a plain text is deprecated in openeuropa/task-runner:1.0.0 and is removed from openeuropa/task-runner:2.0.0. Use the "exec" task and pass arguments and options.', E_USER_DEPRECATED); return $this->taskExec($task)->interactive($this->isTtySupported()); } @@ -202,6 +203,19 @@ protected function taskFactory($task) return $this->collectionBuilder()->addTaskList($tasks); + case 'exec': + $taskExec = $this->taskExec($task['command'])->interactive($this->isTtySupported()); + if (!empty($task['arguments'])) { + $taskExec->args($task['arguments']); + } + if (!empty($task['options'])) { + $taskExec->options($task['options']); + } + if (!empty($task['dir'])) { + $taskExec->dir($task['dir']); + } + return $taskExec; + default: throw new TaskException($this, "Task '{$task['task']}' not supported."); } diff --git a/tests/Tasks/CollectionFactoryTest.php b/tests/Tasks/CollectionFactoryTest.php index ba218bad..88989752 100644 --- a/tests/Tasks/CollectionFactoryTest.php +++ b/tests/Tasks/CollectionFactoryTest.php @@ -95,6 +95,32 @@ public function testRunTask() $this->assertSame(__METHOD__, file_get_contents($filePath)); } + /** + * Tests the 'exec' task. + */ + public function testExecTask(): void + { + $tasks = [ + [ + 'task' => 'exec', + 'command' => 'touch', + 'arguments' => [ + 'file.txt', + ], + 'options' => [ + // 1980-06-06 23:59:59. + '-t' => '198006062359.59' + ], + '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); + } + /** * @return array */