10000 Use Console InvalidArgumentException, test the exception · symfony/symfony@1ab89a1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1ab89a1

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

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

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

Lines changed: 6 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;
@@ -393,12 +394,16 @@ public function newLine($count = 1)
393394
}
394395

395396
/**
397+
* Sets the input stream used by the SymfonyQuestionHelper.
398+
*
396399
* @param resource $stream
400+
*
401+
* @throws InvalidArgumentException If the given stream is not a resource
397402
*/
398403
public function setInputStream($stream)
399404
{
400405
if (!is_resource($stream)) {
401-
throw new \InvalidArgumentException(sprintf('The stream must be a valid resource, %s given'), gettype($stream));
406+
throw new InvalidArgumentException(sprintf('Input stream must be a valid resource, %s given', gettype($stream)));
402407
}
403408

404409
$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