Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdaab5d1

Browse files
committed
Improve tests
Fix wrong phpdoc
1 parentce8658c commitdaab5d1

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 thefakeduser 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 thefakeduser inputs.
156+
* Gets the user inputs.
157157
*
158-
* @return array $inputs
158+
* @return array
159159
*/
160160
publicfunctiongetUserInputs()
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
publicfunctiontestCommandWithUserInputs()
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 =newCommand('foo');
94+
95+
$command->setCode(function ($input,$output)use ($questions,$command) {
96+
$helper =$command->getHelper('question');
97+
$helper->ask($input,$output,newQuestion($questions[0]));
98+
$helper->ask($input,$output,newQuestion($questions[1]));
99+
$helper->ask($input,$output,newQuestion($questions[2]));
100+
});
101+
102+
$tester =newCommandTester($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+
publicfunctiontestCommandWithWrongNumberOfUserInputs()
115+
{
116+
$questions =array(
117+
'What\'s your name?',
118+
'How are you?',
119+
'Where do you come from?'
120+
);
89121

90122
$command =newCommand('foo');
91-
$command->setCode(function ($input,$output)use ($question,$command) {
92-
$command->getHelper('question')->ask($input,$output,newQuestion($question));
123+
$command->setCode(function ($input,$output)use ($questions,$command) {
124+
$helper =$command->getHelper('question');
125+
$helper->ask($input,$output,newQuestion($questions[0]));
126+
$helper->ask($input,$output,newQuestion($questions[1]));
127+
$helper->ask($input,$output,newQuestion($questions[2]));
93128
});
94129

95130
$tester =newCommandTester($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)

[8]ページ先頭

©2009-2025 Movatter.jp