Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISAICP-5988-2: Allow to pass array options to 'run' & 'exec' tasks #137

Open
wants to merge 10 commits into
base: 2.x
Choose a base branch
from
8 changes: 6 additions & 2 deletions src/Tasks/CollectionFactory/CollectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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']);
Expand Down
27 changes: 17 additions & 10 deletions tests/Tasks/CollectionFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [
Expand All @@ -89,36 +89,43 @@ 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));
}

/**
* Tests the 'exec' task.
*/
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',
],
pfrenssen marked this conversation as resolved.
Show resolved Hide resolved
],
'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));
}

/**
Expand Down
4 changes: 3 additions & 1 deletion tests/custom/src/TaskRunner/Commands/TestCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}