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
12namespace Symfony\Component\Console\Tests\Command;
13
14use Symfony\Component\Console\Tester\CommandTester;
15use Symfony\Component\Console\Command\HelpCommand;
16use Symfony\Component\Console\Command\ListCommand;
17use Symfony\Component\Console\Application;
18
19class HelpCommandTest extends \PHPUnit_Framework_TestCase
20{
21    public function testExecuteForCommandAlias()
22    {
23        $command = new HelpCommand();
24        $command->setApplication(new Application());
25        $commandTester = new CommandTester($command);
26        $commandTester->execute(array('command_name' => 'li'));
27        $this->assertRegExp('/list \[--xml\] \[--raw\] \[--format="\.\.\."\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command alias');
28    }
29
30    public function testExecuteForCommand()
31    {
32        $command = new HelpCommand();
33        $commandTester = new CommandTester($command);
34        $command->setCommand(new ListCommand());
35        $commandTester->execute(array());
36        $this->assertRegExp('/list \[--xml\] \[--raw\] \[--format="\.\.\."\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
37    }
38
39    public function testExecuteForCommandWithXmlOption()
40    {
41        $command = new HelpCommand();
42        $commandTester = new CommandTester($command);
43        $command->setCommand(new ListCommand());
44        $commandTester->execute(array('--format' => 'xml'));
45        $this->assertRegExp('/<command/', $commandTester->getDisplay(), '->execute() returns an XML help text if --xml is passed');
46    }
47
48    public function testExecuteForApplicationCommand()
49    {
50        $application = new Application();
51        $commandTester = new CommandTester($application->get('help'));
52        $commandTester->execute(array('command_name' => 'list'));
53        $this->assertRegExp('/list \[--xml\] \[--raw\] \[--format="\.\.\."\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
54    }
55
56    public function testExecuteForApplicationCommandWithXmlOption()
57    {
58        $application = new Application();
59        $commandTester = new CommandTester($application->get('help'));
60        $commandTester->execute(array('command_name' => 'list', '--format' => 'xml'));
61        $this->assertRegExp('/list \[--xml\] \[--raw\] \[--format="\.\.\."\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
62        $this->assertRegExp('/<command/', $commandTester->getDisplay(), '->execute() returns an XML help text if --format=xml is passed');
63    }
64}
65