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\Command\HelpCommand;
17 use Symfony\Component\Console\Command\ListCommand;
18 use Symfony\Component\Console\Application;
20 class HelpCommandTest extends TestCase
22 public function testExecuteForCommandAlias()
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');
33 public function testExecuteForCommand()
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');
44 public function testExecuteForCommandWithXmlOption()
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');
53 public function testExecuteForApplicationCommand()
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');
63 public function testExecuteForApplicationCommandWithXmlOption()
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] [--] [<namespace>]', $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');