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 Symfony\Component\Console\Tester\CommandTester;
15 use Symfony\Component\Console\Command\HelpCommand;
16 use Symfony\Component\Console\Command\ListCommand;
17 use Symfony\Component\Console\Application;
19 class HelpCommandTest extends \PHPUnit_Framework_TestCase
21 public function testExecute()
23 $command = new HelpCommand();
25 $commandTester = new CommandTester($command);
26 $command->setCommand(new ListCommand());
27 $commandTester->execute(array());
28 $this->assertRegExp('/list \[--xml\] \[--raw\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
30 $command->setCommand(new ListCommand());
31 $commandTester->execute(array('--xml' => true));
32 $this->assertRegExp('/<command/', $commandTester->getDisplay(), '->execute() returns an XML help text if --xml is passed');
34 $application = new Application();
35 $commandTester = new CommandTester($application->get('help'));
36 $commandTester->execute(array('command_name' => 'list'));
37 $this->assertRegExp('/list \[--xml\] \[--raw\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
39 $commandTester->execute(array('command_name' => 'list', '--xml' => true));
40 $this->assertRegExp('/<command/', $commandTester->getDisplay(), '->execute() returns an XML help text if --xml is passed');