ApplicationTesterTest.php 2.4 KB

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