ApplicationTesterTest.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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\Application;
  12. use Symfony\Component\Console\Output\Output;
  13. use Symfony\Component\Console\Tester\ApplicationTester;
  14. class ApplicationTesterTest extends \PHPUnit_Framework_TestCase
  15. {
  16. protected $application;
  17. protected $tester;
  18. protected function setUp()
  19. {
  20. $this->application = new Application();
  21. $this->application->setAutoExit(false);
  22. $this->application->register('foo')
  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. protected function tearDown()
  30. {
  31. $this->application = null;
  32. $this->tester = null;
  33. }
  34. public function testRun()
  35. {
  36. $this->assertFalse($this->tester->getInput()->isInteractive(), '->execute() takes an interactive option');
  37. $this->assertFalse($this->tester->getOutput()->isDecorated(), '->execute() takes a decorated option');
  38. $this->assertEquals(Output::VERBOSITY_VERBOSE, $this->tester->getOutput()->getVerbosity(), '->execute() takes a verbosity option');
  39. }
  40. public function testGetInput()
  41. {
  42. $this->assertEquals('bar', $this->tester->getInput()->getArgument('foo'), '->getInput() returns the current input instance');
  43. }
  44. public function testGetOutput()
  45. {
  46. rewind($this->tester->getOutput()->getStream());
  47. $this->assertEquals('foo'.PHP_EOL, stream_get_contents($this->tester->getOutput()->getStream()), '->getOutput() returns the current output instance');
  48. }
  49. public function testGetDisplay()
  50. {
  51. $this->assertEquals('foo'.PHP_EOL, $this->tester->getDisplay(), '->getDisplay() returns the display of the last execution');
  52. }
  53. }