ApplicationTesterTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. require_once __DIR__.'/../../../../bootstrap.php';
  10. use Symfony\Components\Console\Application;
  11. use Symfony\Components\Console\Output\Output;
  12. use Symfony\Components\Console\Tester\ApplicationTester;
  13. $t = new LimeTest(6);
  14. $application = new Application();
  15. $application->setAutoExit(false);
  16. $application->register('foo')
  17. ->addArgument('command')
  18. ->addArgument('foo')
  19. ->setCode(function ($input, $output) { $output->write('foo'); })
  20. ;
  21. $tester = new ApplicationTester($application);
  22. $tester->run(array('command' => 'foo', 'foo' => 'bar'), array('interactive' => false, 'decorated' => false, 'verbosity' => Output::VERBOSITY_VERBOSE));
  23. // ->run()
  24. $t->diag('->run()');
  25. $t->is($tester->getInput()->isInteractive(), false, '->execute() takes an interactive option');
  26. $t->is($tester->getOutput()->isDecorated(), false, '->execute() takes a decorated option');
  27. $t->is($tester->getOutput()->getVerbosity(), Output::VERBOSITY_VERBOSE, '->execute() takes a verbosity option');
  28. // ->getInput()
  29. $t->diag('->getInput()');
  30. $t->is($tester->getInput()->getArgument('foo'), 'bar', '->getInput() returns the current input instance');
  31. // ->getOutput()
  32. $t->diag('->getOutput()');
  33. rewind($tester->getOutput()->getStream());
  34. $t->is(stream_get_contents($tester->getOutput()->getStream()), "foo\n", '->getOutput() returns the current output instance');
  35. // ->getDisplay()
  36. $t->diag('->getDisplay()');
  37. $t->is($tester->getDisplay(), "foo\n", '->getDisplay() returns the display of the last execution');