CommandTesterTest.php 2.1 KB

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