ApplicationTesterTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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\Application;
  11. use Symfony\Components\Console\Output\Output;
  12. use Symfony\Components\Console\Tester\ApplicationTester;
  13. class ApplicationTesterTest extends \PHPUnit_Framework_TestCase
  14. {
  15. protected $application;
  16. protected $tester;
  17. public function setUp()
  18. {
  19. $this->application = new Application();
  20. $this->application->setAutoExit(false);
  21. $this->application->register('foo')
  22. ->addArgument('command')
  23. ->addArgument('foo')
  24. ->setCode(function ($input, $output) { $output->writeln('foo'); })
  25. ;
  26. $this->tester = new ApplicationTester($this->application);
  27. $this->tester->run(array('command' => 'foo', 'foo' => 'bar'), array('interactive' => false, 'decorated' => false, 'verbosity' => Output::VERBOSITY_VERBOSE));
  28. }
  29. public function testRun()
  30. {
  31. $this->assertEquals(false, $this->tester->getInput()->isInteractive(), '->execute() takes an interactive option');
  32. $this->assertEquals(false, $this->tester->getOutput()->isDecorated(), '->execute() takes a decorated option');
  33. $this->assertEquals(Output::VERBOSITY_VERBOSE, $this->tester->getOutput()->getVerbosity(), '->execute() takes a verbosity option');
  34. }
  35. public function testGetInput()
  36. {
  37. $this->assertEquals('bar', $this->tester->getInput()->getArgument('foo'), '->getInput() returns the current input instance');
  38. }
  39. public function testGetOutput()
  40. {
  41. rewind($this->tester->getOutput()->getStream());
  42. $this->assertEquals("foo\n", stream_get_contents($this->tester->getOutput()->getStream()), '->getOutput() returns the current output instance');
  43. }
  44. public function testGetDisplay()
  45. {
  46. $this->assertEquals("foo\n", $this->tester->getDisplay(), '->getDisplay() returns the display of the last execution');
  47. }
  48. }