Skip to content

Commit 87c20ca

Browse files
committed
fix
1 parent bd82694 commit 87c20ca

File tree

2 files changed

+48
-16
lines changed

2 files changed

+48
-16
lines changed

tests/Fixtures/Command/DebugChildProcessCommand.php

+25-5
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@
2222
use Webmozarts\Console\Parallelization\ParallelExecutorFactory;
2323
use function file_put_contents;
2424
use function func_get_args;
25+
use function implode;
2526
use const LOCK_EX;
2627

2728
final class DebugChildProcessCommand extends ParallelCommand
2829
{
2930
public const string OUTPUT_FILE = __DIR__.'/../../../dist/debug-child-input.txt';
3031

31-
private const string OPT_VALUE = 'optValue';
32+
private const string SIMPLE_OPTION = 'simple-option';
33+
private const string ARRAY_OPTION = 'array-option';
3234

3335
private string $item = 'item';
3436
private ?Logger $logger = null;
@@ -44,10 +46,15 @@ protected function configure(): void
4446
parent::configure();
4547

4648
$this->addOption(
47-
self::OPT_VALUE,
49+
self::SIMPLE_OPTION,
4850
null,
4951
InputOption::VALUE_OPTIONAL,
5052
);
53+
$this->addOption(
54+
self::ARRAY_OPTION,
55+
null,
56+
InputOption::VALUE_OPTIONAL + InputOption::VALUE_IS_ARRAY,
57+
);
5158
}
5259

5360
public function setItem(string $item): void
@@ -89,7 +96,8 @@ protected function runSingleCommand(string $item, InputInterface $input, OutputI
8996
self::OUTPUT_FILE,
9097
self::createContent(
9198
$item,
92-
$input->getOption(self::OPT_VALUE),
99+
$input->getOption(self::SIMPLE_OPTION),
100+
$input->getOption(self::ARRAY_OPTION),
93101
),
94102
flags: LOCK_EX,
95103
);
@@ -102,11 +110,23 @@ protected function getItemName(?int $count): string
102110

103111
public static function createContent(
104112
string $item,
105-
?string $option,
113+
?string $simpleOption,
114+
array $arrayOption,
106115
): string {
116+
$normalizedArrayOption = implode(
117+
"\n",
118+
array_map(
119+
static fn (string $option): string => " - {$option}",
120+
$arrayOption,
121+
),
122+
);
123+
107124
return <<<EOF
108125
Item: {$item}
109-
Option: {$option}
126+
Simple Option: {$simpleOption}
127+
Array Option:
128+
{$normalizedArrayOption}
129+
110130
EOF;
111131
}
112132
}

tests/Integration/DebugChildProcessInputsTest.php

+23-11
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ protected function tearDown(): void
4747
#[DataProvider('inputProvider')]
4848
public function test_it_can_run_the_command_without_sub_processes(
4949
string $item,
50-
?string $option,
50+
?string $simpleOption,
51+
array $arrayOption,
5152
string $expected,
5253
): void {
5354
$logger = new DummyLogger();
@@ -58,8 +59,8 @@ public function test_it_can_run_the_command_without_sub_processes(
5859
$this->commandTester->execute(
5960
[
6061
'command' => 'debug:process',
61-
'--optValue' => $option,
62-
'-vvv' => null,
62+
'--simple-option' => $simpleOption,
63+
'--array-option' => $arrayOption,
6364
],
6465
['interactive' => true],
6566
);
@@ -73,48 +74,59 @@ public function test_it_can_run_the_command_without_sub_processes(
7374

7475
public static function inputProvider(): iterable
7576
{
76-
yield 'default' => [
77-
'item',
78-
null,
79-
DebugChildProcessCommand::createContent(
80-
'item',
81-
'',
82-
),
83-
];
77+
// This test fails...
78+
// yield 'default' => [
79+
// 'item',
80+
// null,
81+
// [],
82+
// DebugChildProcessCommand::createContent(
83+
// 'item',
84+
// '',
85+
// [],
86+
// ),
87+
// ];
8488

8589
yield 'with values' => [
8690
'item',
8791
'option',
92+
['option1', 'option2'],
8893
DebugChildProcessCommand::createContent(
8994
'item',
9095
'option',
96+
['option1--array-option=option2'],
9197
),
9298
];
9399

94100
yield 'escaped string token' => [
95101
'"foo"',
96102
'"bar"',
103+
['"option1"', '"option2"'],
97104
DebugChildProcessCommand::createContent(
98105
'"foo"',
99106
'"\"bar\""',
107+
['"\"option1\""--array-option="\"option2\""'],
100108
),
101109
];
102110

103111
yield 'escaped string token with both types of quotes' => [
104112
'"o_id in(\'20\')"',
105113
'"p_id in(\'22\')"',
114+
['"option in(\'1\')"', '"option in(\'2\')"'],
106115
DebugChildProcessCommand::createContent(
107116
'"o_id in(\'20\')"',
108117
'"\"p_id in(\'22\')\""',
118+
['"\"option in(\'1\')\""--array-option="\"option in(\'2\')\""'],
109119
),
110120
];
111121

112122
yield 'with values with spaces' => [
113123
'a b c d',
114124
'd c b a',
125+
['option 1', 'option 2'],
115126
DebugChildProcessCommand::createContent(
116127
'a b c d',
117128
'"d c b a"',
129+
['"option 1"--array-option="option 2"'],
118130
),
119131
];
120132
}

0 commit comments

Comments
 (0)