HelpCommandTest.php 1.6 KB

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