Yaffs site version 1.1
[yaffs-website] / vendor / symfony / console / Tests / Tester / CommandTesterTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\Console\Tests\Tester;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Console\Application;
16 use Symfony\Component\Console\Command\Command;
17 use Symfony\Component\Console\Output\Output;
18 use Symfony\Component\Console\Tester\CommandTester;
19
20 class CommandTesterTest extends TestCase
21 {
22     protected $command;
23     protected $tester;
24
25     protected function setUp()
26     {
27         $this->command = new Command('foo');
28         $this->command->addArgument('command');
29         $this->command->addArgument('foo');
30         $this->command->setCode(function ($input, $output) { $output->writeln('foo'); });
31
32         $this->tester = new CommandTester($this->command);
33         $this->tester->execute(array('foo' => 'bar'), array('interactive' => false, 'decorated' => false, 'verbosity' => Output::VERBOSITY_VERBOSE));
34     }
35
36     protected function tearDown()
37     {
38         $this->command = null;
39         $this->tester = null;
40     }
41
42     public function testExecute()
43     {
44         $this->assertFalse($this->tester->getInput()->isInteractive(), '->execute() takes an interactive option');
45         $this->assertFalse($this->tester->getOutput()->isDecorated(), '->execute() takes a decorated option');
46         $this->assertEquals(Output::VERBOSITY_VERBOSE, $this->tester->getOutput()->getVerbosity(), '->execute() takes a verbosity option');
47     }
48
49     public function testGetInput()
50     {
51         $this->assertEquals('bar', $this->tester->getInput()->getArgument('foo'), '->getInput() returns the current input instance');
52     }
53
54     public function testGetOutput()
55     {
56         rewind($this->tester->getOutput()->getStream());
57         $this->assertEquals('foo'.PHP_EOL, stream_get_contents($this->tester->getOutput()->getStream()), '->getOutput() returns the current output instance');
58     }
59
60     public function testGetDisplay()
61     {
62         $this->assertEquals('foo'.PHP_EOL, $this->tester->getDisplay(), '->getDisplay() returns the display of the last execution');
63     }
64
65     public function testGetStatusCode()
66     {
67         $this->assertSame(0, $this->tester->getStatusCode(), '->getStatusCode() returns the status code');
68     }
69
70     public function testCommandFromApplication()
71     {
72         $application = new Application();
73         $application->setAutoExit(false);
74
75         $command = new Command('foo');
76         $command->setCode(function ($input, $output) { $output->writeln('foo'); });
77
78         $application->add($command);
79
80         $tester = new CommandTester($application->find('foo'));
81
82         // check that there is no need to pass the command name here
83         $this->assertEquals(0, $tester->execute(array()));
84     }
85 }