HelpCommandTest.php 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. }