Skip to content

Commit abd9b72

Browse files
committed
minor #14638 [Console] Fix QuestionHelperTest (ogizanagi)
This PR was merged into the 2.7 branch. Discussion ---------- [Console] Fix QuestionHelperTest | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - This PR fixes the following issues in `QuestionHelperTest`: - When using the `InputInterface` mock with interactive option, asking a ChoiceQuestion without specifying max attempts nor a default value led to an infinite loop when invalid values are submitted. In case there is something wrong in tests, it wasn't obvious to understand what's happening, as the process was constantly waiting for inputs. - `testAmbiguousChoiceFromChoicelist` test was wrong as the autocompleter filled the value and the test was never triggered (+max attempt issue). Commits ------- 6a0308d [Console] Fix QuestionHelperTest
2 parents 0542a17 + 6a0308d commit abd9b72

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,15 +227,20 @@ public function testSelectChoiceFromChoiceList($providedAnswer, $expectedValue)
227227
$dialog->setHelperSet($helperSet);
228228

229229
$question = new ChoiceQuestion('Please select the environment to load', $possibleChoices);
230+
$question->setMaxAttempts(1);
230231
$answer = $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question);
231232

232233
$this->assertSame($expectedValue, $answer);
233234
}
234235

236+
/**
237+
* @expectedException \InvalidArgumentException
238+
* @expectedExceptionMessage The provided answer is ambiguous. Value should be one of env_2 or env_3.
239+
*/
235240
public function testAmbiguousChoiceFromChoicelist()
236241
{
237242
$possibleChoices = array(
238-
'env_1' => 'My environment 1',
243+
'env_1' => 'My first environment',
239244
'env_2' => 'My environment',
240245
'env_3' => 'My environment',
241246
);
@@ -246,12 +251,9 @@ public function testAmbiguousChoiceFromChoicelist()
246251
$dialog->setHelperSet($helperSet);
247252

248253
$question = new ChoiceQuestion('Please select the environment to load', $possibleChoices);
254+
$question->setMaxAttempts(1);
249255

250-
try {
251-
$dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question);
252-
} catch (\InvalidArgumentException $e) {
253-
$this->assertEquals('The provided answer is ambiguous. Value should be one of env_2 or env_3.', $e->getMessage());
254-
}
256+
$dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question);
255257
}
256258

257259
public function answerProvider()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy