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\Command\HelpCommand ;
use Symfony\Component\Console\Command\ListCommand ;
use Symfony\Component\Console\Application ;
2010-03-18 07:48:03 +00:00
class HelpCommandTest extends \PHPUnit_Framework_TestCase
{
2013-02-05 21:55:33 +00:00
public function testExecuteForCommandAlias ()
2010-05-06 12:25:53 +01:00
{
$command = new HelpCommand ();
2013-02-05 21:55:33 +00:00
$command -> setApplication ( new Application ());
2012-09-20 09:09:17 +01:00
$commandTester = new CommandTester ( $command );
$commandTester -> execute ( array ( 'command_name' => 'li' ));
2013-02-05 21:55:33 +00:00
2012-09-20 09:09:17 +01:00
$this -> assertRegExp ( '/list \[--xml\] \[--raw\] \[namespace\]/' , $commandTester -> getDisplay (), '->execute() returns a text help for the given command alias' );
2013-02-05 21:55:33 +00:00
}
2012-09-20 09:09:17 +01:00
2013-02-05 21:55:33 +00:00
public function testExecuteForCommand ()
{
2012-09-20 09:09:17 +01:00
$command = new HelpCommand ();
2010-05-06 12:25:53 +01:00
$commandTester = new CommandTester ( $command );
2012-03-02 22:14:57 +00:00
$command -> setCommand ( new ListCommand ());
2010-05-06 12:25:53 +01:00
$commandTester -> execute ( array ());
2013-02-05 21:55:33 +00:00
2011-12-17 23:19:10 +00:00
$this -> assertRegExp ( '/list \[--xml\] \[--raw\] \[namespace\]/' , $commandTester -> getDisplay (), '->execute() returns a text help for the given command' );
2013-02-05 21:55:33 +00:00
}
2010-05-06 12:25:53 +01:00
2013-02-05 21:55:33 +00:00
public function testExecuteForCommandWithXmlOption ()
{
$command = new HelpCommand ();
$commandTester = new CommandTester ( $command );
2012-03-02 22:14:57 +00:00
$command -> setCommand ( new ListCommand ());
2010-05-06 12:25:53 +01:00
$commandTester -> execute ( array ( '--xml' => true ));
2013-02-05 21:55:33 +00:00
2010-05-06 12:25:53 +01:00
$this -> assertRegExp ( '/<command/' , $commandTester -> getDisplay (), '->execute() returns an XML help text if --xml is passed' );
2013-02-05 21:55:33 +00:00
}
2010-05-06 12:25:53 +01:00
2013-02-05 21:55:33 +00:00
public function testExecuteForApplicationCommand ()
{
2010-05-06 12:25:53 +01:00
$application = new Application ();
2010-11-23 08:42:19 +00:00
$commandTester = new CommandTester ( $application -> get ( 'help' ));
2010-05-06 12:25:53 +01:00
$commandTester -> execute ( array ( 'command_name' => 'list' ));
2013-02-05 21:55:33 +00:00
2011-12-17 23:19:10 +00:00
$this -> assertRegExp ( '/list \[--xml\] \[--raw\] \[namespace\]/' , $commandTester -> getDisplay (), '->execute() returns a text help for the given command' );
2013-02-05 21:55:33 +00:00
}
2010-05-06 12:25:53 +01:00
2013-02-05 21:55:33 +00:00
public function testExecuteForApplicationCommandWithXmlOption ()
{
$application = new Application ();
$commandTester = new CommandTester ( $application -> get ( 'help' ));
2010-05-06 12:25:53 +01:00
$commandTester -> execute ( array ( 'command_name' => 'list' , '--xml' => true ));
2013-02-05 21:55:33 +00:00
2010-05-06 12:25:53 +01:00
$this -> assertRegExp ( '/<command/' , $commandTester -> getDisplay (), '->execute() returns an XML help text if --xml is passed' );
}
2010-03-18 07:48:03 +00:00
}