Yaffs site version 1.1
[yaffs-website] / vendor / symfony / console / Tests / Command / HelpCommandTest.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\Command\HelpCommand;
17 use Symfony\Component\Console\Command\ListCommand;
18 use Symfony\Component\Console\Application;
19
20 class HelpCommandTest extends TestCase
21 {
22     public function testExecuteForCommandAlias()
23     {
24         $command = new HelpCommand();
25         $command->setApplication(new Application());
26         $commandTester = new CommandTester($command);
27         $commandTester->execute(array('command_name' => 'li'), array('decorated' => false));
28         $this->assertContains('list [options] [--] [<namespace>]', $commandTester->getDisplay(), '->execute() returns a text help for the given command alias');
29         $this->assertContains('format=FORMAT', $commandTester->getDisplay(), '->execute() returns a text help for the given command alias');
30         $this->assertContains('raw', $commandTester->getDisplay(), '->execute() returns a text help for the given command alias');
31     }
32
33     public function testExecuteForCommand()
34     {
35         $command = new HelpCommand();
36         $commandTester = new CommandTester($command);
37         $command->setCommand(new ListCommand());
38         $commandTester->execute(array(), array('decorated' => false));
39         $this->assertContains('list [options] [--] [<namespace>]', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
40         $this->assertContains('format=FORMAT', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
41         $this->assertContains('raw', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
42     }
43
44     public function testExecuteForCommandWithXmlOption()
45     {
46         $command = new HelpCommand();
47         $commandTester = new CommandTester($command);
48         $command->setCommand(new ListCommand());
49         $commandTester->execute(array('--format' => 'xml'));
50         $this->assertContains('<command', $commandTester->getDisplay(), '->execute() returns an XML help text if --xml is passed');
51     }
52
53     public function testExecuteForApplicationCommand()
54     {
55         $application = new Application();
56         $commandTester = new CommandTester($application->get('help'));
57         $commandTester->execute(array('command_name' => 'list'));
58         $this->assertContains('list [options] [--] [<namespace>]', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
59         $this->assertContains('format=FORMAT', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
60         $this->assertContains('raw', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
61     }
62
63     public function testExecuteForApplicationCommandWithXmlOption()
64     {
65         $application = new Application();
66         $commandTester = new CommandTester($application->get('help'));
67         $commandTester->execute(array('command_name' => 'list', '--format' => 'xml'));
68         $this->assertContains('list [--xml] [--raw] [--format FORMAT] [--] [&lt;namespace&gt;]', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
69         $this->assertContains('<command', $commandTester->getDisplay(), '->execute() returns an XML help text if --format=xml is passed');
70     }
71 }