HelpCommandTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. require_once __DIR__.'/../../../bootstrap.php';
  11. use Symfony\Components\Console\Tester\CommandTester;
  12. use Symfony\Components\Console\Command\HelpCommand;
  13. use Symfony\Components\Console\Command\ListCommand;
  14. use Symfony\Components\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->getCommand('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. }