Skip to content

Commit 9f13a03

Browse files
committed
fix
1 parent fd902f7 commit 9f13a03

File tree

3 files changed

+33
-29
lines changed

3 files changed

+33
-29
lines changed

src/Input/InputOptionsSerializer.php

+18-13
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
use function array_fill_keys;
2121
use function array_keys;
2222
use function array_map;
23-
use function implode;
23+
use function array_merge;
24+
use function is_array;
2425
use function is_string;
2526
use function preg_match;
2627
use function sprintf;
@@ -52,24 +53,31 @@ public static function serialize(
5253
array_fill_keys($excludedOptionNames, ''),
5354
);
5455

55-
return array_map(
56-
static fn (string $name) => self::serializeOption(
56+
$serializedOptionsList = [];
57+
58+
foreach (array_keys($filteredOptions) as $name) {
59+
$serializedOption = self::serializeOption(
5760
$commandDefinition->getOption($name),
5861
$name,
5962
$filteredOptions[$name],
60-
),
61-
array_keys($filteredOptions),
62-
);
63+
);
64+
65+
$serializedOptionsList[] = is_array($serializedOption) ? $serializedOption : [$serializedOption];
66+
}
67+
68+
return array_merge(...$serializedOptionsList);
6369
}
6470

6571
/**
6672
* @param string|bool|int|float|null|array<string|bool|int|float|null> $value
73+
*
74+
* @return string|list<string>
6775
*/
6876
private static function serializeOption(
6977
InputOption $option,
7078
string $name,
7179
array|bool|float|int|string|null $value,
72-
): string {
80+
): string|array {
7381
if ($option->isNegatable()) {
7482
return sprintf(
7583
'--%s%s',
@@ -87,12 +95,9 @@ private static function serializeOption(
8795

8896
if ($option->isArray()) {
8997
/** @var array<string|bool|int|float|null> $value */
90-
return implode(
91-
'',
92-
array_map(
93-
static fn ($item) => self::serializeOptionWithValue($name, $item),
94-
$value,
95-
),
98+
return array_map(
99+
static fn ($item) => self::serializeOptionWithValue($name, $item),
100+
$value,
96101
);
97102
}
98103

tests/Input/InputOptionsSerializerTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ private static function optionSerializationProvider(): iterable
255255
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
256256
),
257257
['--opt' => ['v1', 'v2', 'v3']],
258-
['--opt=v1--opt=v2--opt=v3'],
258+
['--opt=v1', '--opt=v2', '--opt=v3'],
259259
);
260260

261261
if (!$isSymfony4) {

tests/Integration/DebugChildProcessInputsTest.php

+14-15
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,16 @@ public function test_it_can_run_the_command_without_sub_processes(
7474

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

8988
yield 'with values' => [
9089
'item',
@@ -93,7 +92,7 @@ public static function inputProvider(): iterable
9392
DebugChildProcessCommand::createContent(
9493
'item',
9594
'option',
96-
['option1--array-option=option2'],
95+
['option1', 'option2'],
9796
),
9897
];
9998

@@ -104,7 +103,7 @@ public static function inputProvider(): iterable
104103
DebugChildProcessCommand::createContent(
105104
'"foo"',
106105
'"\"bar\""',
107-
['"\"option1\""--array-option="\"option2\""'],
106+
['"\"option1\""', '"\"option2\""'],
108107
),
109108
];
110109

@@ -115,7 +114,7 @@ public static function inputProvider(): iterable
115114
DebugChildProcessCommand::createContent(
116115
'"o_id in(\'20\')"',
117116
'"\"p_id in(\'22\')\""',
118-
['"\"option in(\'1\')\""--array-option="\"option in(\'2\')\""'],
117+
['"\"option in(\'1\')\""', '"\"option in(\'2\')\""'],
119118
),
120119
];
121120

@@ -126,7 +125,7 @@ public static function inputProvider(): iterable
126125
DebugChildProcessCommand::createContent(
127126
'a b c d',
128127
'"d c b a"',
129-
['"option 1"--array-option="option 2"'],
128+
['"option 1"', '"option 2"'],
130129
),
131130
];
132131
}

0 commit comments

Comments
 (0)