TYPO3  7.6
ListCommandTest.php
Go to the documentation of this file.
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 
16 
17 class ListCommandTest extends \PHPUnit_Framework_TestCase
18 {
19  public function testExecuteListsCommands()
20  {
21  $application = new Application();
22  $commandTester = new CommandTester($command = $application->get('list'));
23  $commandTester->execute(array('command' => $command->getName()), array('decorated' => false));
24 
25  $this->assertRegExp('/help\s{2,}Displays help for a command/', $commandTester->getDisplay(), '->execute() returns a list of available commands');
26  }
27 
29  {
30  $application = new Application();
31  $commandTester = new CommandTester($command = $application->get('list'));
32  $commandTester->execute(array('command' => $command->getName(), '--format' => 'xml'));
33  $this->assertRegExp('/<command id="list" name="list">/', $commandTester->getDisplay(), '->execute() returns a list of available commands in XML if --xml is passed');
34  }
35 
37  {
38  $application = new Application();
39  $commandTester = new CommandTester($command = $application->get('list'));
40  $commandTester->execute(array('command' => $command->getName(), '--raw' => true));
41  $output = <<<EOF
42 help Displays help for a command
43 list Lists commands
44 
45 EOF;
46 
47  $this->assertEquals($output, $commandTester->getDisplay(true));
48  }
49 
51  {
52  require_once realpath(__DIR__.'/../Fixtures/FooCommand.php');
53  $application = new Application();
54  $application->add(new \FooCommand());
55  $commandTester = new CommandTester($command = $application->get('list'));
56  $commandTester->execute(array('command' => $command->getName(), 'namespace' => 'foo', '--raw' => true));
57  $output = <<<EOF
58 foo:bar The foo:bar command
59 
60 EOF;
61 
62  $this->assertEquals($output, $commandTester->getDisplay(true));
63  }
64 }