HelpCommandTest.php 3.6 KB

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