HelpCommandTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. $command->setCommand(new ListCommand());
  21. $commandTester = new CommandTester($command);
  22. $commandTester->execute(array());
  23. $this->assertRegExp('/list \[--xml\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
  24. $commandTester->execute(array('--xml' => true));
  25. $this->assertRegExp('/<command/', $commandTester->getDisplay(), '->execute() returns an XML help text if --xml is passed');
  26. $application = new Application();
  27. $commandTester = new CommandTester($application->get('help'));
  28. $commandTester->execute(array('command_name' => 'list'));
  29. $this->assertRegExp('/list \[--xml\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
  30. $commandTester->execute(array('command_name' => 'list', '--xml' => true));
  31. $this->assertRegExp('/<command/', $commandTester->getDisplay(), '->execute() returns an XML help text if --xml is passed');
  32. }
  33. }