2010-03-18 07:48:03 +00:00
< ? php
/*
2010-04-25 16:06:54 +01:00
* This file is part of the Symfony package .
2011-01-15 13:29:43 +00:00
*
2011-03-06 11:40:06 +00:00
* ( c ) Fabien Potencier < fabien @ symfony . com >
2010-03-18 07:48:03 +00:00
*
* For the full copyright and license information , please view the LICENSE
* file that was distributed with this source code .
*/
2012-03-28 14:43:52 +01:00
namespace Symfony\Component\Console\Tests\Command ;
2010-03-18 07:48:03 +00:00
2010-08-20 22:09:55 +01:00
use Symfony\Component\Console\Tester\CommandTester ;
use Symfony\Component\Console\Application ;
2010-03-18 07:48:03 +00:00
class ListCommandTest extends \PHPUnit_Framework_TestCase
{
2013-02-05 21:55:33 +00:00
public function testExecuteListsCommands ()
2010-05-06 12:25:53 +01:00
{
$application = new Application ();
2010-11-23 08:42:19 +00:00
$commandTester = new CommandTester ( $command = $application -> get ( 'list' ));
2011-07-22 20:02:15 +01:00
$commandTester -> execute ( array ( 'command' => $command -> getName ()), array ( 'decorated' => false ));
2013-02-05 21:55:33 +00:00
2010-05-06 12:25:53 +01:00
$this -> assertRegExp ( '/help Displays help for a command/' , $commandTester -> getDisplay (), '->execute() returns a list of available commands' );
2013-02-05 21:55:33 +00:00
}
2010-03-18 07:48:03 +00:00
2013-02-05 21:55:33 +00:00
public function testExecuteListsCommandsWithXmlOption ()
{
$application = new Application ();
$commandTester = new CommandTester ( $command = $application -> get ( 'list' ));
2013-03-22 13:40:47 +00:00
$commandTester -> execute ( array ( 'command' => $command -> getName (), '--format' => 'xml' ));
2011-06-07 16:51:43 +01:00
$this -> assertRegExp ( '/<command id="list" name="list">/' , $commandTester -> getDisplay (), '->execute() returns a list of available commands in XML if --xml is passed' );
2013-02-05 21:55:33 +00:00
}
2011-12-18 13:33:54 +00:00
2013-02-05 21:55:33 +00:00
public function testExecuteListsCommandsWithRawOption ()
{
$application = new Application ();
$commandTester = new CommandTester ( $command = $application -> get ( 'list' ));
2011-12-17 23:19:10 +00:00
$commandTester -> execute ( array ( 'command' => $command -> getName (), '--raw' => true ));
2011-12-18 13:32:45 +00:00
$output = <<< EOF
help Displays help for a command
list Lists commands
2013-05-22 03:45:49 +01:00
EOF ;
$this -> assertEquals ( $output , $commandTester -> getDisplay ( true ));
}
public function testExecuteListsCommandsWithNamespaceArgument ()
{
2014-07-29 19:09:11 +01:00
require_once realpath ( __DIR__ . '/../Fixtures/FooCommand.php' );
2013-05-22 03:45:49 +01:00
$application = new Application ();
$application -> add ( new \FooCommand ());
$commandTester = new CommandTester ( $command = $application -> get ( 'list' ));
$commandTester -> execute ( array ( 'command' => $command -> getName (), 'namespace' => 'foo' , '--raw' => true ));
$output = <<< EOF
foo : bar The foo : bar command
2011-12-18 13:32:45 +00:00
EOF ;
2013-02-05 21:55:33 +00:00
2013-04-25 12:56:40 +01:00
$this -> assertEquals ( $output , $commandTester -> getDisplay ( true ));
2010-05-06 12:25:53 +01:00
}
2014-11-18 00:17:03 +00:00
public function testExecuteListsCommandsNameAndNamespaceRaw ()
{
require_once realpath ( __DIR__ . '/../Fixtures/Foo6Command.php' );
$application = new Application ();
$application -> add ( new \Foo6Command ());
$commandTester = new CommandTester ( $command = $application -> get ( 'list' ));
$commandTester -> execute ( array ( 'command' => $command -> getName ()));
$output = <<< EOF
Console Tool
Usage :
[ options ] command [ arguments ]
Options :
-- help ( - h ) Display this help message .
-- quiet ( - q ) Do not output any message .
-- verbose ( - v | vv | vvv ) Increase the verbosity of messages : 1 for normal output , 2 for more verbose output and 3 for debug .
-- version ( - V ) Display this application version .
-- ansi Force ANSI output .
-- no - ansi Disable ANSI output .
-- no - interaction ( - n ) Do not ask any interactive question .
Available commands :
help Displays help for a command
list Lists commands
< fg = blue > foo
< fg = blue > foo : bar </ fg = blue >
EOF ;
$this -> assertEquals ( $output , trim ( $commandTester -> getDisplay ( true )));
}
2010-03-18 07:48:03 +00:00
}