HelpCommandTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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\Component\Console\Tests\Command;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Console\Application;
  13. use Symfony\Component\Console\Command\HelpCommand;
  14. use Symfony\Component\Console\Command\ListCommand;
  15. use Symfony\Component\Console\Tester\CommandTester;
  16. class HelpCommandTest extends TestCase
  17. {
  18. public function testExecuteForCommandAlias()
  19. {
  20. $command = new HelpCommand();
  21. $command->setApplication(new Application());
  22. $commandTester = new CommandTester($command);
  23. $commandTester->execute(['command_name' => 'li'], ['decorated' => false]);
  24. $this->assertContains('list [options] [--] [<namespace>]', $commandTester->getDisplay(), '->execute() returns a text help for the given command alias');
  25. $this->assertContains('format=FORMAT', $commandTester->getDisplay(), '->execute() returns a text help for the given command alias');
  26. $this->assertContains('raw', $commandTester->getDisplay(), '->execute() returns a text help for the given command alias');
  27. }
  28. public function testExecuteForCommand()
  29. {
  30. $command = new HelpCommand();
  31. $commandTester = new CommandTester($command);
  32. $command->setCommand(new ListCommand());
  33. $commandTester->execute([], ['decorated' => false]);
  34. $this->assertContains('list [options] [--] [<namespace>]', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
  35. $this->assertContains('format=FORMAT', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
  36. $this->assertContains('raw', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
  37. }
  38. public function testExecuteForCommandWithXmlOption()
  39. {
  40. $command = new HelpCommand();
  41. $commandTester = new CommandTester($command);
  42. $command->setCommand(new ListCommand());
  43. $commandTester->execute(['--format' => 'xml']);
  44. $this->assertContains('<command', $commandTester->getDisplay(), '->execute() returns an XML help text if --xml is passed');
  45. }
  46. public function testExecuteForApplicationCommand()
  47. {
  48. $application = new Application();
  49. $commandTester = new CommandTester($application->get('help'));
  50. $commandTester->execute(['command_name' => 'list']);
  51. $this->assertContains('list [options] [--] [<namespace>]', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
  52. $this->assertContains('format=FORMAT', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
  53. $this->assertContains('raw', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
  54. }
  55. public function testExecuteForApplicationCommandWithXmlOption()
  56. {
  57. $application = new Application();
  58. $commandTester = new CommandTester($application->get('help'));
  59. $commandTester->execute(['command_name' => 'list', '--format' => 'xml']);
  60. $this->assertContains('list [--raw] [--format FORMAT] [--] [&lt;namespace&gt;]', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
  61. $this->assertContains('<command', $commandTester->getDisplay(), '->execute() returns an XML help text if --format=xml is passed');
  62. }
  63. }