HelpCommandTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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\Tests\Component\Console\Command;
  11. use Symfony\Component\Console\Tester\CommandTester;
  12. use Symfony\Component\Console\Command\HelpCommand;
  13. use Symfony\Component\Console\Command\ListCommand;
  14. use Symfony\Component\Console\Application;
  15. class HelpCommandTest extends \PHPUnit_Framework_TestCase
  16. {
  17. public function testExecute()
  18. {
  19. $command = new HelpCommand();
  20. $commandTester = new CommandTester($command);
  21. $command->setCommand(new ListCommand());
  22. $commandTester->execute(array());
  23. $this->assertRegExp('/list \[--xml\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
  24. $command->setCommand(new ListCommand());
  25. $commandTester->execute(array('--xml' => true));
  26. $this->assertRegExp('/<command/', $commandTester->getDisplay(), '->execute() returns an XML help text if --xml is passed');
  27. $application = new Application();
  28. $commandTester = new CommandTester($application->get('help'));
  29. $commandTester->execute(array('command_name' => 'list'));
  30. $this->assertRegExp('/list \[--xml\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
  31. $commandTester->execute(array('command_name' => 'list', '--xml' => true));
  32. $this->assertRegExp('/<command/', $commandTester->getDisplay(), '->execute() returns an XML help text if --xml is passed');
  33. }
  34. }