8000 [Console] Add tests for removing restriction for choices to be strings · symfony/symfony@a022308 · GitHub
[go: up one dir, main page]

Skip to content

Commit a022308

Browse files
YaFouogizanagi
authored andcommitted
[Console] Add tests for removing restriction for choices to be strings
See 3349d3c
1 parent 3349d3c commit a022308

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/Symfony/Component/Console/Tests/Question/ChoiceQuestionTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,34 @@ public function testNonTrimmable()
7777

7878
$this->assertSame(['First response ', ' Second response'], $question->getValidator()('First response , Second response'));
7979
}
80+
81+
public function testSelectWithNonStringChoices()
82+
{
83+
$question = new ChoiceQuestion('A question', [
84+
$result1 = new StringChoice('foo'),
85+
$result2 = new StringChoice('bar'),
86+
$result3 = new StringChoice('baz'),
87+
]);
88+
89+
$this->assertSame($result1, $question->getValidator()('foo'));
90+
91+
$question->setMultiselect(true);
92+
93+
$this->assertSame([$result3, $result2], $que 91B7 stion->getValidator()('baz, bar'));
94+
}
95+
}
96+
97+
class StringChoice
98+
{
99+
private $string;
100+
101+
public function __construct(string $string)
102+
{
103+
$this->string = $string;
104+
}
105+
106+
public function __toString()
107+
{
108+
return $this->string;
109+
}
80110
}

0 commit comments

Comments
 (0)
0