ListCommandTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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\Application;
  13. class ListCommandTest extends \PHPUnit_Framework_TestCase
  14. {
  15. public function testExecuteListsCommands()
  16. {
  17. $application = new Application();
  18. $commandTester = new CommandTester($command = $application->get('list'));
  19. $commandTester->execute(array('command' => $command->getName()), array('decorated' => false));
  20. $this->assertRegExp('/help\s{2,}Displays help for a command/', $commandTester->getDisplay(), '->execute() returns a list of available commands');
  21. }
  22. public function testExecuteListsCommandsWithXmlOption()
  23. {
  24. $application = new Application();
  25. $commandTester = new CommandTester($command = $application->get('list'));
  26. $commandTester->execute(array('command' => $command->getName(), '--format' => 'xml'));
  27. $this->assertRegExp('/<command id="list" name="list">/', $commandTester->getDisplay(), '->execute() returns a list of available commands in XML if --xml is passed');
  28. }
  29. public function testExecuteListsCommandsWithRawOption()
  30. {
  31. $application = new Application();
  32. $commandTester = new CommandTester($command = $application->get('list'));
  33. $commandTester->execute(array('command' => $command->getName(), '--raw' => true));
  34. $output = <<<EOF
  35. help Displays help for a command
  36. list Lists commands
  37. EOF;
  38. $this->assertEquals($output, $commandTester->getDisplay(true));
  39. }
  40. public function testExecuteListsCommandsWithNamespaceArgument()
  41. {
  42. require_once realpath(__DIR__.'/../Fixtures/FooCommand.php');
  43. $application = new Application();
  44. $application->add(new \FooCommand());
  45. $commandTester = new CommandTester($command = $application->get('list'));
  46. $commandTester->execute(array('command' => $command->getName(), 'namespace' => 'foo', '--raw' => true));
  47. $output = <<<EOF
  48. foo:bar The foo:bar command
  49. EOF;
  50. $this->assertEquals($output, $commandTester->getDisplay(true));
  51. }
  52. }