From c2d9a4bda6eaf44388c015a0ab6b0ff98910dc40 Mon Sep 17 00:00:00 2001 From: Enzo Innocenzi Date: Mon, 23 Mar 2026 19:30:26 +0100 Subject: [PATCH] fix(console): discrepancy between interactive and static single choice result --- .../src/Components/Static/StaticSingleChoiceComponent.php | 8 +++++++- .../Components/Static/StaticSingleChoiceComponentTest.php | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/console/src/Components/Static/StaticSingleChoiceComponent.php b/packages/console/src/Components/Static/StaticSingleChoiceComponent.php index 41853a12ba..6a923ab5ec 100644 --- a/packages/console/src/Components/Static/StaticSingleChoiceComponent.php +++ b/packages/console/src/Components/Static/StaticSingleChoiceComponent.php @@ -67,6 +67,10 @@ public function render(Console $console): null|int|UnitEnum|string return true; } + if (! $this->options->isList() && $answer === (string) $option->key) { + return true; + } + if ($this->options->getOptions()->isList() && $answer === (string) $index) { return true; } @@ -75,7 +79,9 @@ public function render(Console $console): null|int|UnitEnum|string }); if ($selectedOption !== null) { - return $selectedOption->value; + return $this->options->isList() + ? $selectedOption->value + : $selectedOption->key; } return $this->render($console); diff --git a/tests/Integration/Console/Components/Static/StaticSingleChoiceComponentTest.php b/tests/Integration/Console/Components/Static/StaticSingleChoiceComponentTest.php index 3f0df9bcac..c73482f86b 100644 --- a/tests/Integration/Console/Components/Static/StaticSingleChoiceComponentTest.php +++ b/tests/Integration/Console/Components/Static/StaticSingleChoiceComponentTest.php @@ -61,7 +61,7 @@ public function test_assoc_submit_key(): void $console->writeln("picked {$answer}"); }) ->submit(1) - ->assertContains('picked B'); + ->assertContains('picked b'); } public function test_assoc_submit_value(): void @@ -73,7 +73,7 @@ public function test_assoc_submit_value(): void $console->writeln("picked {$answer}"); }) ->submit('B') - ->assertContains('picked B'); + ->assertContains('picked b'); } public function test_enum_submit_value(): void