CommandTesterTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. require_once __DIR__.'/../../../bootstrap.php';
  11. use Symfony\Components\Console\Command\Command;
  12. use Symfony\Components\Console\Output\Output;
  13. use Symfony\Components\Console\Tester\CommandTester;
  14. class CommandTesterTest extends \PHPUnit_Framework_TestCase
  15. {
  16. protected $application;
  17. protected $tester;
  18. public 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. public function testExecute()
  28. {
  29. $this->assertEquals(false, $this->tester->getInput()->isInteractive(), '->execute() takes an interactive option');
  30. $this->assertEquals(false, $this->tester->getOutput()->isDecorated(), '->execute() takes a decorated option');
  31. $this->assertEquals(Output::VERBOSITY_VERBOSE, $this->tester->getOutput()->getVerbosity(), '->execute() takes a verbosity option');
  32. }
  33. public function testGetInput()
  34. {
  35. $this->assertEquals('bar', $this->tester->getInput()->getArgument('foo'), '->getInput() returns the current input instance');
  36. }
  37. public function testGetOutput()
  38. {
  39. rewind($this->tester->getOutput()->getStream());
  40. $this->assertEquals("foo\n", stream_get_contents($this->tester->getOutput()->getStream()), '->getOutput() returns the current output instance');
  41. }
  42. public function testGetDisplay()
  43. {
  44. $this->assertEquals("foo\n", $this->tester->getDisplay(), '->getDisplay() returns the display of the last execution');
  45. }
  46. }