8000 Fix review, fix test, not it show that previouse code fails with utf · symfony/symfony@21c5a8b · GitHub
[go: up one dir, main page]

Skip to content

Commit 21c 8000 5a8b

Browse files
committed
Fix review, fix test, not it show that previouse code fails with utf
1 parent fe8ae78 commit 21c5a8b

File tree

5 files changed

+38
-28
lines changed

5 files changed

+38
-28
lines changed

src/Symfony/Component/Console/Helper/QuestionHelper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
*/
3131
class QuestionHelper extends Helper
3232
{
33-
const DEFAULT_PROMPT = ' > ';
3433
private $inputStream;
3534
private static $shell;
3635
private static $stty;
@@ -209,7 +208,8 @@ protected function writePrompt(OutputInterface $output, Question $question)
209208
}
210209

211210
/**
212-
* @param $tag
211+
* @param string $tag
212+
* @param ChoiceQuestion $question
213213
*
214214
* @return string[]
215215
*/

src/Symfony/Component/Console/Helper/SymfonyQuestionHelper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ protected function writePrompt(OutputInterface $output, Question $question)
101101

102102
$output->writeln($messages);
103103
// ChoiceQuestion can have any prompt
104-
$output->write($question->getPrompt() ?: static::DEFAULT_PROMPT);
104+
$output->write($question->getPrompt() ?: Question::DEFAULT_PROMPT);
105105
} else {
106-
$output->write(static::DEFAULT_PROMPT);
106+
$output->write(Question::DEFAULT_PROMPT);
107107
}
108108
}
109109

src/Symfony/Component/Console/Question/ChoiceQuestion.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ChoiceQuestion extends Question
2222
{
2323
private $choices;
2424
private $multiselect = false;
25-
private $prompt = null;
25+
private $prompt = ' > ';
2626
private $errorMessage = 'Value "%s" is invalid';
2727

2828
/**

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
*/
2222
class Question
2323
{
24+
const DEFAULT_PROMPT = ' > ';
2425
private $question;
2526
private $attempts;
2627
private $hidden = false;

src/Symfony/Component/Console/Tests/Helper/SymfonyQuestionHelperTest.php

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -116,29 +116,38 @@ public function testAskEscapeAndFormatLabel()
116116

117117
public function testForUtf8Keys()
118118
{
119-
$question = 'Lorem ipsum?';
120-
$possibleChoices = [
121-
'foo' => 'foo',
122-
'żółw' => 'bar',
123-
'łabądź' => 'baz',
124-
];
125-
$question_result = ' <info>Lorem ipsum?</info> [<comment>foo</comment>]:';
126-
$outputShown = [
127-
' [<comment>foo </comment>] foo',
128-
' [<comment>żółw </comment>] bar',
129-
' [<comment>łabądź</comment>] baz',
130-
];
131-
132-
$dialog = new SymfonyQuestionHelper();
133-
134-
$question = new ChoiceQuestion($question, $possibleChoices, 'foo');
135-
136-
$output = $this->getMockBuilder('\Symfony\Component\Console\Output\OutputInterface')->getMock();
137-
$output->method('getFormatter')->willReturn(new OutputFormatter());
138-
139-
$input = $this->createStreamableInputInterfaceMock($this->getInputStream('foo'));
140-
$output->expects($this->exactly(2))->method('writeln')->withConsecutive([$question_result], [$outputShown]);
141-
$dialog->ask($input, $output, $question);
119+
$question = 'Lorem ipsum?';
120+
$possibleChoices = [
121+
'foo' => 'foo',
122+
'żółw' => 'bar',
123+
'łabądź' => 'baz',
124+
];
125+
$question_result = ' <info>Lorem ipsum?</info> [<comment>foo</comment>]:';
126+
$outputShown = [
127+
' [<comment>foo </comment>] foo',
128+
' [<comment>żółw </comment>] bar',
129+
' [<comment>łabądź</comment>] baz',
130+
];
131+
132+
$dialog = new SymfonyQuestionHelper();
133+
134+
$question = new ChoiceQuestion($question, $possibleChoices, 'foo');
135+
136+
$output = $this->getMockBuilder('\Symfony\Component\Console\Output\OutputInterface')->getMock();
137+
$output->method('getFormatter')->willReturn(new OutputFormatter());
138+
$question->setValidator(null);
139+
140+
$input = $this->createStreamableInputInterfaceMock($this->getInputStream('foo'));
141+
$result = [];
142+
$output->method('writeln')->willReturnCallback(function ($params) use (&$result) {
143+
if (is_array($params)) {
144+
$result = array_merge($result, $params);
145+
} else {
146+
$result[] = $params;
147+
}
148+
});
149+
$dialog->ask($input, $output, $question);
150+
$this->assertEquals(array_merge([$question_result],$outputShown), $result);
142151
}
143152

144153
public function testAskDefaultPrompt()

0 commit comments

Comments
 (0)
0