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

Commit2d3e78b

Browse files
committed
Use Console InvalidArgumentException, test the exception
1 parent3a6b05d commit2d3e78b

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

‎src/Symfony/Component/Console/Style/SymfonyStyle.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
useSymfony\Component\Console\Application;
1515
useSymfony\Component\Console\Exception\RuntimeException;
16+
useSymfony\Component\Console\Exception\InvalidArgumentException;
1617
useSymfony\Component\Console\Formatter\OutputFormatter;
1718
useSymfony\Component\Console\Helper\Helper;
1819
useSymfony\Component\Console\Helper\ProgressBar;
@@ -398,7 +399,7 @@ public function newLine($count = 1)
398399
publicfunctionsetInputStream($stream)
399400
{
400401
if (!is_resource($stream)) {
401-
thrownew\InvalidArgumentException(sprintf('The stream must be a valid resource, %s given'),gettype($stream));
402+
thrownewInvalidArgumentException(sprintf('Input stream must be a valid resource, %s given',gettype($stream)));
402403
}
403404

404405
$this->inputStream =$stream;

‎src/Symfony/Component/Console/Tests/Style/SymfonyStyleTest.php‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,29 @@ public function testSetInputStream()
8080
rewind($stream);
8181

8282
$command->setCode(function ($input,$output)use ($command,$stream) {
83-
$io =newSymfonyStyle($input,$output);
83+
$sfStyle =newSymfonyStyle($input,$output);
8484

85-
$io->setInputStream($stream);
86-
$io->ask('What\'s your name?');
85+
$sfStyle->setInputStream($stream);
86+
$sfStyle->ask('What\'s your name?');
8787
});
8888

8989
$this->tester->execute(array());
9090
$this->assertSame(0,$this->tester->getStatusCode());
9191
}
92+
93+
/**
94+
* @expectedException \Symfony\Component\Console\Exception\InvalidArgumentException
95+
* @expectedMessage Input stream must be a valid resource, string given
96+
*/
97+
publicfunctiontestSetInputStreamWithWrongResource()
98+
{
99+
$this->command->setCode(function ($input,$output) {
100+
$sfStyle =newSymfonyStyle($input,$output);
101+
$sfStyle->setInputStream('invalid type');
102+
});
103+
104+
$this->tester->execute(array());
105+
}
92106
}
93107

94108
/**

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp