11
11
/**
12
12
* @group tty
13
13
*/
14
- class SymfonyQuestionHelperTest extends \PHPUnit_Framework_TestCase
14
+ class SymfonyQuestionHelperTest extends AbstractQuestionHelperTest
15
15
{
16
16
public function testAskChoice ()
17
17
{
@@ -22,29 +22,29 @@ public function testAskChoice()
22
22
23
23
$ heroes = array ('Superman ' , 'Batman ' , 'Spiderman ' );
24
24
25
- $ questionHelper -> setInputStream ( $ this ->getInputStream ("\n1 \n 1 \nFabien \n1 \nFabien \n1 \n0,2 \n 0 , 2 \n\n\n" ) );
25
+ $ inputStream = $ this ->getInputStream ("\n1 \n 1 \nFabien \n1 \nFabien \n1 \n0,2 \n 0 , 2 \n\n\n" );
26
26
27
27
$ question = new ChoiceQuestion ('What is your favorite superhero? ' , $ heroes , '2 ' );
28
28
$ question ->setMaxAttempts (1 );
29
29
// first answer is an empty answer, we're supposed to receive the default value
30
- $ this ->assertEquals ('Spiderman ' , $ questionHelper ->ask ($ this ->createInputInterfaceMock ( ), $ output = $ this ->createOutputInterface (), $ question ));
30
+ $ this ->assertEquals ('Spiderman ' , $ questionHelper ->ask ($ this ->createStreamableInputInterfaceMock ( $ inputStream ), $ output = $ this ->createOutputInterface (), $ question ));
31
31
$ this ->assertOutputContains ('What is your favorite superhero? [Spiderman] ' , $ output );
32
32
33
33
$ question = new ChoiceQuestion ('What is your favorite superhero? ' , $ heroes );
34
34
$ question ->setMaxAttempts (1 );
35
- $ this ->assertEquals ('Batman ' , $ questionHelper ->ask ($ this ->createInputInterfaceMock ( ), $ this ->createOutputInterface (), $ question ));
36
- $ this ->assertEquals ('Batman ' , $ questionHelper ->ask ($ this ->createInputInterfaceMock ( ), $ this ->createOutputInterface (), $ question ));
35
+ $ this ->assertEquals ('Batman ' , $ questionHelper ->ask ($ this ->createStreamableInputInterfaceMock ( $ inputStream ), $ this ->createOutputInterface (), $ question ));
36
+ $ this ->assertEquals ('Batman ' , $ questionHelper ->ask ($ this ->createStreamableInputInterfaceMock ( $ inputStream ), $ this ->createOutputInterface (), $ question ));
37
37
38
38
$ question = new ChoiceQuestion ('What is your favorite superhero? ' , $ heroes );
39
39
$ question ->setErrorMessage ('Input "%s" is not a superhero! ' );
40
40
$ question ->setMaxAttempts (2 );
41
- $ this ->assertEquals ('Batman ' , $ questionHelper ->ask ($ this ->createInputInterfaceMock ( ), $ output = $ this ->createOutputInterface (), $ question ));
41
+ $ this ->assertEquals ('Batman ' , $ questionHelper ->ask ($ this ->createStreamableInputInterfaceMock ( $ inputStream ), $ output = $ this ->createOutputInterface (), $ question ));
42
42
$ this ->assertOutputContains ('Input "Fabien" is not a superhero! ' , $ output );
43
43
44
44
try {
45
45
$ question = new ChoiceQuestion ('What is your favorite superhero? ' , $ heroes , '1 ' );
46
46
$ question ->setMaxAttempts (1 );
47
- $ questionHelper ->ask ($ this ->createInputInterfaceMock ( ), $ output = $ this ->createOutputInterface (), $ question );
47
+ $ questionHelper ->ask ($ this ->createStreamableInputInterfaceMock ( $ inputStream ), $ output = $ this ->createOutputInterface (), $ question );
48
48
$ this ->fail ();
49
49
} catch (\InvalidArgumentException $ e ) {
50
50
$ this ->assertEquals ('Value "Fabien" is invalid ' , $ e ->getMessage ());
@@ -54,22 +54,22 @@ public function testAskChoice()
54
54
$ question ->setMaxAttempts (1 );
55
55
$ question ->setMultiselect (true );
56
56
57
- $ this ->assertEquals (array ('Batman ' ), $ questionHelper ->ask ($ this ->createInputInterfaceMock ( ), $ this ->createOutputInterface (), $ question ));
58
- $ this ->assertEquals (array ('Superman ' , 'Spiderman ' ), $ questionHelper ->ask ($ this ->createInputInterfaceMock ( ), $ this ->createOutputInterface (), $ question ));
59
- $ this ->assertEquals (array ('Superman ' , 'Spiderman ' ), $ questionHelper ->ask ($ this ->createInputInterfaceMock ( ), $ this ->createOutputInterface (), $ question ));
57
+ $ this ->assertEquals (array ('Batman ' ), $ questionHelper ->ask ($ this ->createStreamableInputInterfaceMock ( $ inputStream ), $ this ->createOutputInterface (), $ question ));
58
+ $ this ->assertEquals (array ('Superman ' , 'Spiderman ' ), $ questionHelper ->ask ($ this ->createStreamableInputInterfaceMock ( $ inputStream ), $ this ->createOutputInterface (), $ question ));
59
+ $ this ->assertEquals (array ('Superman ' , 'Spiderman ' ), $ questionHelper ->ask ($ this ->createStreamableInputInterfaceMock ( $ inputStream ), $ this ->createOutputInterface (), $ question ));
60
60
61
61
$ question = new ChoiceQuestion ('What is your favorite superhero? ' , $ heroes , '0,1 ' );
62
62
$ question ->setMaxAttempts (1 );
63
63
$ question ->setMultiselect (true );
64
64
65
- $ this ->assertEquals (array ('Superman ' , 'Batman ' ), $ questionHelper ->ask ($ this ->createInputInterfaceMock ( ), $ output = $ this ->createOutputInterface (), $ question ));
65
+ $ this ->assertEquals (array ('Superman ' , 'Batman ' ), $ questionHelper ->ask ($ this ->createStreamableInputInterfaceMock ( $ inputStream ), $ output = $ this ->createOutputInterface (), $ question ));
66
66
$ this ->assertOutputContains ('What is your favorite superhero? [Superman, Batman] ' , $ output );
67
67
68
68
$ question = new ChoiceQuestion ('What is your favorite superhero? ' , $ heroes , ' 0 , 1 ' );
69
69
$ question ->setMaxAttempts (1 );
70
70
$ question ->setMultiselect (true );
71
71
72
- $ this ->assertEquals (array ('Superman ' , 'Batman ' ), $ questionHelper ->ask ($ this ->createInputInterfaceMock ( ), $ output = $ this ->createOutputInterface (), $ question ));
72
+ $ this ->assertEquals (array ('Superman ' , 'Batman ' ), $ questionHelper ->ask ($ this ->createStreamableInputInterfaceMock ( $ inputStream ), $ output = $ this ->createOutputInterface (), $ question ));
73
73
$ this ->assertOutputContains ('What is your favorite superhero? [Superman, Batman] ' , $ output );
74
74
}
75
75
0 commit comments