CommandTesterTest.php 1.6 KB

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