4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Console\Tests\Command;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Console\Tester\CommandTester;
16 use Symfony\Component\Console\Application;
18 class ListCommandTest extends TestCase
20 public function testExecuteListsCommands()
22 $application = new Application();
23 $commandTester = new CommandTester($command = $application->get('list'));
24 $commandTester->execute(array('command' => $command->getName()), array('decorated' => false));
26 $this->assertRegExp('/help\s{2,}Displays help for a command/', $commandTester->getDisplay(), '->execute() returns a list of available commands');
29 public function testExecuteListsCommandsWithXmlOption()
31 $application = new Application();
32 $commandTester = new CommandTester($command = $application->get('list'));
33 $commandTester->execute(array('command' => $command->getName(), '--format' => 'xml'));
34 $this->assertRegExp('/<command id="list" name="list">/', $commandTester->getDisplay(), '->execute() returns a list of available commands in XML if --xml is passed');
37 public function testExecuteListsCommandsWithRawOption()
39 $application = new Application();
40 $commandTester = new CommandTester($command = $application->get('list'));
41 $commandTester->execute(array('command' => $command->getName(), '--raw' => true));
43 help Displays help for a command
48 $this->assertEquals($output, $commandTester->getDisplay(true));
51 public function testExecuteListsCommandsWithNamespaceArgument()
53 require_once realpath(__DIR__.'/../Fixtures/FooCommand.php');
54 $application = new Application();
55 $application->add(new \FooCommand());
56 $commandTester = new CommandTester($command = $application->get('list'));
57 $commandTester->execute(array('command' => $command->getName(), 'namespace' => 'foo', '--raw' => true));
59 foo:bar The foo:bar command
63 $this->assertEquals($output, $commandTester->getDisplay(true));
66 public function testExecuteListsCommandsOrder()
68 require_once realpath(__DIR__.'/../Fixtures/Foo6Command.php');
69 $application = new Application();
70 $application->add(new \Foo6Command());
71 $commandTester = new CommandTester($command = $application->get('list'));
72 $commandTester->execute(array('command' => $command->getName()), array('decorated' => false));
77 command [options] [arguments]
80 -h, --help Display this help message
81 -q, --quiet Do not output any message
82 -V, --version Display this application version
83 --ansi Force ANSI output
84 --no-ansi Disable ANSI output
85 -n, --no-interaction Do not ask any interactive question
86 -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
89 help Displays help for a command
92 0foo:bar 0foo:bar command
95 $this->assertEquals($output, trim($commandTester->getDisplay(true)));
98 public function testExecuteListsCommandsOrderRaw()
100 require_once realpath(__DIR__.'/../Fixtures/Foo6Command.php');
101 $application = new Application();
102 $application->add(new \Foo6Command());
103 $commandTester = new CommandTester($command = $application->get('list'));
104 $commandTester->execute(array('command' => $command->getName(), '--raw' => true));
106 help Displays help for a command
108 0foo:bar 0foo:bar command
111 $this->assertEquals($output, trim($commandTester->getDisplay(true)));