Skip to content

Commit 4e53ecc

Browse files
committed
tests(settings): Correctly only return bool for Symfony Input::hasParameterOption calls
Signed-off-by: Joas Schilling <[email protected]>
1 parent 5ddbcee commit 4e53ecc

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

tests/Core/Command/User/SettingTest.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,16 @@ public function testCheckInput($arguments, $options, $parameterOptions, $user, $
193193
->willReturnMap($options);
194194
$this->consoleInput->expects($this->any())
195195
->method('hasParameterOption')
196-
->willReturnMap($parameterOptions);
196+
->willReturnCallback(function (string|array $config, bool $default = false) use ($parameterOptions): bool {
197+
foreach ($parameterOptions as $parameterOption) {
198+
if ($config === $parameterOption[0]
199+
// Check the default value if the maps has 3 entries
200+
&& (!isset($parameterOption[2]) || $default === $parameterOption[1])) {
201+
return end($parameterOption);
202+
}
203+
}
204+
return false;
205+
});
197206

198207
if ($user !== false) {
199208
$this->userManager->expects($this->once())
@@ -401,15 +410,16 @@ public function testExecuteGet($value, $defaultValue, $expectedLine, $expectedRe
401410
if ($defaultValue === null) {
402411
$this->consoleInput->expects($this->atLeastOnce())
403412
->method('hasParameterOption')
404-
->willReturnMap([
405-
['--default-value', false],
406-
]);
413+
->willReturn(false);
407414
} else {
408415
$this->consoleInput->expects($this->atLeastOnce())
409416
->method('hasParameterOption')
410-
->willReturnMap([
411-
['--default-value', false, true],
412-
]);
417+
->willReturnCallback(function (string|array $config, bool $default = false): bool {
418+
if ($config === '--default-value' && $default === false) {
419+
return true;
420+
}
421+
return false;
422+
});
413423
$this->consoleInput->expects($this->once())
414424
->method('getOption')
415425
->with('default-value')

0 commit comments

Comments
 (0)