Yaffs site version 1.1
[yaffs-website] / vendor / symfony / console / Tests / Command / ListCommandTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\Console\Tests\Command;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Console\Tester\CommandTester;
16 use Symfony\Component\Console\Application;
17
18 class ListCommandTest extends TestCase
19 {
20     public function testExecuteListsCommands()
21     {
22         $application = new Application();
23         $commandTester = new CommandTester($command = $application->get('list'));
24         $commandTester->execute(array('command' => $command->getName()), array('decorated' => false));
25
26         $this->assertRegExp('/help\s{2,}Displays help for a command/', $commandTester->getDisplay(), '->execute() returns a list of available commands');
27     }
28
29     public function testExecuteListsCommandsWithXmlOption()
30     {
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');
35     }
36
37     public function testExecuteListsCommandsWithRawOption()
38     {
39         $application = new Application();
40         $commandTester = new CommandTester($command = $application->get('list'));
41         $commandTester->execute(array('command' => $command->getName(), '--raw' => true));
42         $output = <<<'EOF'
43 help   Displays help for a command
44 list   Lists commands
45
46 EOF;
47
48         $this->assertEquals($output, $commandTester->getDisplay(true));
49     }
50
51     public function testExecuteListsCommandsWithNamespaceArgument()
52     {
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));
58         $output = <<<'EOF'
59 foo:bar   The foo:bar command
60
61 EOF;
62
63         $this->assertEquals($output, $commandTester->getDisplay(true));
64     }
65
66     public function testExecuteListsCommandsOrder()
67     {
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));
73         $output = <<<'EOF'
74 Console Tool
75
76 Usage:
77   command [options] [arguments]
78
79 Options:
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
87
88 Available commands:
89   help      Displays help for a command
90   list      Lists commands
91  0foo
92   0foo:bar  0foo:bar command
93 EOF;
94
95         $this->assertEquals($output, trim($commandTester->getDisplay(true)));
96     }
97
98     public function testExecuteListsCommandsOrderRaw()
99     {
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));
105         $output = <<<'EOF'
106 help       Displays help for a command
107 list       Lists commands
108 0foo:bar   0foo:bar command
109 EOF;
110
111         $this->assertEquals($output, trim($commandTester->getDisplay(true)));
112     }
113 }