Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e0be96f

Browse files
committed
Improve tests
Fix wrong phpdoc Fabbot fixes
1 parent ce8658c commit e0be96f

File tree

2 files changed

+45
-11
lines changed

2 files changed

+45
-11
lines changed

src/Symfony/Component/Console/Tester/CommandTester.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ public function getStatusCode()
139139
}
140140

141141
/**
142-
* Sets the faked user inputs.
142+
* Sets the user inputs.
143143
*
144-
* @param array $inputs
144+
* @param array
145145
*
146146
* @return CommandTester
147147
*/
@@ -153,9 +153,9 @@ public function setUserInputs(array $inputs)
153153
}
154154

155155
/**
156-
* Gets the faked user inputs.
156+
* Gets the user inputs.
157157
*
158-
* @return array $inputs
158+
* @return array
159159
*/
160160
public function getUserInputs()
161161
{

src/Symfony/Component/Console/Tests/Tester/CommandTesterTest.php

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,52 @@ public function testCommandFromApplication()
8585

8686
public function testCommandWithUserInputs()
8787
{
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+
);
89121

90122
$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]));
93128
});
94129

95130
$tester = new CommandTester($command);
96-
$tester->setUserInputs(array('Bobby'));
131+
$tester->setUserInputs(array('Bobby', 'Fine'));
132+
$tester->execute(array());
97133

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());
101135
}
102136
}

0 commit comments

Comments
 (0)