CommandTesterTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. namespace Symfony\Tests\Components\Console\Tester;
  10. use Symfony\Components\Console\Command\Command;
  11. use Symfony\Components\Console\Output\Output;
  12. use Symfony\Components\Console\Tester\CommandTester;
  13. class CommandTesterTest extends \PHPUnit_Framework_TestCase
  14. {
  15. protected $application;
  16. protected $tester;
  17. public function setUp()
  18. {
  19. $this->command = new Command('foo');
  20. $this->command->addArgument('command');
  21. $this->command->addArgument('foo');
  22. $this->command->setCode(function ($input, $output) { $output->writeln('foo'); });
  23. $this->tester = new CommandTester($this->command);
  24. $this->tester->execute(array('foo' => 'bar'), array('interactive' => false, 'decorated' => false, 'verbosity' => Output::VERBOSITY_VERBOSE));
  25. }
  26. public function testExecute()
  27. {
  28. $this->assertFalse($this->tester->getInput()->isInteractive(), '->execute() takes an interactive option');
  29. $this->assertFalse($this->tester->getOutput()->isDecorated(), '->execute() takes a decorated option');
  30. $this->assertEquals(Output::VERBOSITY_VERBOSE, $this->tester->getOutput()->getVerbosity(), '->execute() takes a verbosity option');
  31. }
  32. public function testGetInput()
  33. {
  34. $this->assertEquals('bar', $this->tester->getInput()->getArgument('foo'), '->getInput() returns the current input instance');
  35. }
  36. public function testGetOutput()
  37. {
  38. rewind($this->tester->getOutput()->getStream());
  39. $this->assertEquals('foo'.PHP_EOL, stream_get_contents($this->tester->getOutput()->getStream()), '->getOutput() returns the current output instance');
  40. }
  41. public function testGetDisplay()
  42. {
  43. $this->assertEquals('foo'.PHP_EOL, $this->tester->getDisplay(), '->getDisplay() returns the display of the last execution');
  44. }
  45. }