TYPO3  7.6
CommandTesterTest.php
Go to the documentation of this file.
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 
18 
19 class CommandTesterTest extends \PHPUnit_Framework_TestCase
20 {
21  protected $command;
22  protected $tester;
23 
24  protected function setUp()
25  {
26  $this->command = new Command('foo');
27  $this->command->addArgument('command');
28  $this->command->addArgument('foo');
29  $this->command->setCode(function ($input, $output) { $output->writeln('foo'); });
30 
31  $this->tester = new CommandTester($this->command);
32  $this->tester->execute(array('foo' => 'bar'), array('interactive' => false, 'decorated' => false, 'verbosity' => Output::VERBOSITY_VERBOSE));
33  }
34 
35  protected function tearDown()
36  {
37  $this->command = null;
38  $this->tester = null;
39  }
40 
41  public function testExecute()
42  {
43  $this->assertFalse($this->tester->getInput()->isInteractive(), '->execute() takes an interactive option');
44  $this->assertFalse($this->tester->getOutput()->isDecorated(), '->execute() takes a decorated option');
45  $this->assertEquals(Output::VERBOSITY_VERBOSE, $this->tester->getOutput()->getVerbosity(), '->execute() takes a verbosity option');
46  }
47 
48  public function testGetInput()
49  {
50  $this->assertEquals('bar', $this->tester->getInput()->getArgument('foo'), '->getInput() returns the current input instance');
51  }
52 
53  public function testGetOutput()
54  {
55  rewind($this->tester->getOutput()->getStream());
56  $this->assertEquals('foo'.PHP_EOL, stream_get_contents($this->tester->getOutput()->getStream()), '->getOutput() returns the current output instance');
57  }
58 
59  public function testGetDisplay()
60  {
61  $this->assertEquals('foo'.PHP_EOL, $this->tester->getDisplay(), '->getDisplay() returns the display of the last execution');
62  }
63 
64  public function testGetStatusCode()
65  {
66  $this->assertSame(0, $this->tester->getStatusCode(), '->getStatusCode() returns the status code');
67  }
68 
69  public function testCommandFromApplication()
70  {
71  $application = new Application();
72  $application->setAutoExit(false);
73 
74  $command = new Command('foo');
75  $command->setCode(function ($input, $output) { $output->writeln('foo'); });
76 
77  $application->add($command);
78 
79  $tester = new CommandTester($application->find('foo'));
80 
81  // check that there is no need to pass the command name here
82  $this->assertEquals(0, $tester->execute(array()));
83  }
84 }