4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Console\Tests\Tester;
14 use Symfony\Component\Console\Command\Command;
15 use Symfony\Component\Console\Output\Output;
16 use Symfony\Component\Console\Tester\CommandTester;
18 class CommandTesterTest extends \PHPUnit_Framework_TestCase
20 protected $application;
23 protected function setUp()
25 $this->command = new Command('foo');
26 $this->command->addArgument('command');
27 $this->command->addArgument('foo');
28 $this->command->setCode(function ($input, $output) { $output->writeln('foo'); });
30 $this->tester = new CommandTester($this->command);
31 $this->tester->execute(array('foo' => 'bar'), array('interactive' => false, 'decorated' => false, 'verbosity' => Output::VERBOSITY_VERBOSE));
34 protected function tearDown()
36 $this->command = null;
40 public function testExecute()
42 $this->assertFalse($this->tester->getInput()->isInteractive(), '->execute() takes an interactive option');
43 $this->assertFalse($this->tester->getOutput()->isDecorated(), '->execute() takes a decorated option');
44 $this->assertEquals(Output::VERBOSITY_VERBOSE, $this->tester->getOutput()->getVerbosity(), '->execute() takes a verbosity option');
47 public function testGetInput()
49 $this->assertEquals('bar', $this->tester->getInput()->getArgument('foo'), '->getInput() returns the current input instance');
52 public function testGetOutput()
54 rewind($this->tester->getOutput()->getStream());
55 $this->assertEquals('foo'.PHP_EOL, stream_get_contents($this->tester->getOutput()->getStream()), '->getOutput() returns the current output instance');
58 public function testGetDisplay()
60 $this->assertEquals('foo'.PHP_EOL, $this->tester->getDisplay(), '->getDisplay() returns the display of the last execution');