8000 Use Console InvalidArgumentException, test the exception · symfony/symfony@2d3e78b · GitHub
[go: up one dir, main page]

Skip to content

Commit 2d3e78b

Browse files
committed
Use Console InvalidArgumentException, test the exception
1 parent 3a6b05d commit 2d3e78b

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
use Symfony\Component\Console\Application;
1515
use Symfony\Component\Console\Exception\RuntimeException;
16+
use Symfony\Component\Console\Exception\InvalidArgumentException;
1617
use Symfony\Component\Console\Formatter\OutputFormatter;
1718
use Symfony\Component\Console\Helper\Helper;
1819
use Symfony\Component\Console\Helper\ProgressBar;
@@ -398,7 +399,7 @@ public function newLine($count = 1)
398399
public function setInputStream($stream)
399400
{
400401
if (!is_resource($stream)) {
401-
throw new \InvalidArgumentException(sprintf('The stream must be a valid resource, %s given'), gettype($stream));
402+
throw new InvalidArgumentException(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 = new SymfonyStyle($input, $output);
83+
$sfStyle = new SymfonyStyle($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+
public function testSetInputStreamWithWrongResource()
98+
{
99+
$this->command->setCode(function ($input, $output) {
100+
$sfStyle = new SymfonyStyle($input, $output);
101+
$sfStyle->setInputStream('invalid type');
102+
});
103+
104+
$this->tester->execute(array());
105+
}
92106
}
93107

94108
/**

0 commit comments

Comments
 (0)
0