|
14 | 14 | use PHPUnit_Framework_TestCase;
|
15 | 15 | use Symfony\Component\Console\Command\Command;
|
16 | 16 | use Symfony\Component\Console\Tester\CommandTester;
|
| 17 | +use Symfony\Component\Console\Formatter\OutputFormatter; |
| 18 | +use Symfony\Component\Console\Output\NullOutput; |
| 19 | +use Symfony\Component\Console\Output\StreamOutput; |
| 20 | +use Symfony\Component\Console\Output\OutputInterface; |
| 21 | +use Symfony\Component\Console\Output\ConsoleOutputInterface; |
| 22 | +use Symfony\Component\Console\Input\InputInterface; |
| 23 | +use Symfony\Component\Console\Style\SymfonyStyle; |
17 | 24 |
|
18 | 25 | class SymfonyStyleTest extends PHPUnit_Framework_TestCase
|
19 | 26 | {
|
@@ -70,4 +77,38 @@ public function inputCommandToOutputFilesProvider()
|
70 | 77 |
|
71 | 78 | return array_map(null, glob($baseDir.'/command/command_*.php'), glob($baseDir.'/output/output_*.txt'));
|
72 | 79 | }
|
| 80 | + |
| 81 | + public function testGetErrorStyle() |
| 82 | + { |
| 83 | + $input = $this->getMockBuilder(InputInterface::class)->getMock(); |
| 84 | + |
| 85 | + $errorOutput = $this->getMockBuilder(OutputInterface::class)->getMock(); |
| 86 | + $errorOutput |
| 87 | + ->method('getFormatter') |
| 88 | + ->willReturn(new OutputFormatter()); |
| 89 | + $errorOutput |
| 90 | + ->expects($this->once()) |
| 91 | + ->method('write'); |
| 92 | + |
| 93 | + $output = $this->getMockBuilder(ConsoleOutputInterface::class)->getMock(); |
| 94 | + $output |
| 95 | + ->method('getFormatter') |
| 96 | + ->willReturn(new OutputFormatter()); |
| 97 | + $output |
| 98 | + ->expects($this->once()) |
| 99 | + ->method('getErrorOutput') |
| 100 | + ->willReturn($errorOutput); |
| 101 | + |
| 102 | + $io = new SymfonyStyle($input, $output); |
| 103 | + $io->getErrorStyle()->write(''); |
| 104 | + } |
| 105 | + |
| 106 | + /** |
| 107 | + * @expectedException Symfony\Component\Console\Exception\LogicException |
| 108 | + * @expectedExceptionMessage The output must be an instance of Symfony\Component\Console\Output\ConsoleOutputInterface for using getErrorOutput(). |
| 109 | + */ |
| 110 | + public function testGetErrorStyleThrowsExceptionOnInvalidOutput() |
| 111 | + { |
| 112 | + (new SymfonyStyle($this->getMockBuilder(InputInterface::class)->getMock(), new NullOutput()))->getErrorStyle(); |
| 113 | + } |
73 | 114 | }
|
0 commit comments