@@ -85,18 +85,52 @@ public function testCommandFromApplication()
85
85
86
86
public function testCommandWithUserInputs ()
87
87
{
88
- $ question = 'What \'s your name? ' ;
88
+ $ questions = array (
89
+ 'What \'s your name? ' ,
90
+ 'How are you? ' ,
91
+ 'Where do you come from? ' ,
92
+ );
93
+ $ command = new Command ('foo ' );
94
+
95
+ $ command ->setCode (function ($ input , $ output ) use ($ questions , $ command ) {
96
+ $ helper = $ command ->getHelper ('question ' );
97
+ $ helper ->ask ($ input , $ output , new Question ($ questions [0 ]));
98
+ $ helper ->ask ($ input , $ output , new Question ($ questions [1 ]));
99
+ $ helper ->ask ($ input , $ output , new Question ($ questions [2 ]));
100
+ });
101
+
102
+ $ tester = new CommandTester ($ command );
103
+ $ tester ->setUserInputs (array ('Bobby ' , 'Fine ' , 'France ' ));
104
+ $ tester ->execute (array ());
105
+
106
+ $ this ->assertEquals (0 , $ tester ->getStatusCode ());
107
+ $ this ->assertEquals (implode ('' , $ questions ), $ tester ->getDisplay ());
108
+ }
109
+
110
+ /**
111
+ * @expectedException \RuntimeException
112
+ * @expectedMessage Aborted
113
+ */
114
+ public function testCommandWithWrongNumberOfUserInputs ()
115
+ {
116
+ $ questions = array (
117
+ 'What \'s your name? ' ,
118
+ 'How are you? ' ,
119
+ 'Where do you come from? ' ,
120
+ );
89
121
90
122
$ command = new Command ('foo ' );
91
- $ command ->setCode (function ($ input , $ output ) use ($ question , $ command ) {
92
- $ command ->getHelper ('question ' )->ask ($ input , $ output , new Question ($ question ));
123
+ $ command ->setCode (function ($ input , $ output ) use ($ questions , $ command ) {
124
+ $ helper = $ command ->getHelper ('question ' );
125
+ $ helper ->ask ($ input , $ output , new Question ($ questions [0 ]));
126
+ $ helper ->ask ($ input , $ output , new Question ($ questions [1 ]));
127
+ $ helper ->ask ($ input , $ output , new Question ($ questions [2 ]));
93
128
});
94
129
95
130
$ tester = new CommandTester ($ command );
96
- $ tester ->setUserInputs (array ('Bobby ' ));
131
+ $ tester ->setUserInputs (array ('Bobby ' , 'Fine ' ));
132
+ $ tester ->execute (array ());
97
133
98
- $ this ->assertEquals (0 , $ tester ->execute (array ()));
99
- $ this ->assertEquals ($ question , $ tester ->getDisplay (true ));
100
- $ this ->assertInternalType ('resource ' , $ command ->getHelper ('question ' )->getInputStream ());
134
+ $ this ->assertEquals (implode ('' , $ questions ), $ tester ->getDisplay ());
101
135
}
102
136
}
0 commit comments