ApplicationTesterTest.php 2.1 KB

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