[Console] changed CommandTester to allow testing Command classes without the need for an Application
This commit is contained in:
parent
c57cae7600
commit
e6cbfd7292
@ -51,7 +51,7 @@ class CommandTester
|
||||
*/
|
||||
public function execute(array $input, array $options = array())
|
||||
{
|
||||
$this->input = new ArrayInput(array_merge($input, array('command' => $this->command->getFullName())));
|
||||
$this->input = new ArrayInput($input);
|
||||
if (isset($options['interactive'])) {
|
||||
$this->input->setInteractive($options['interactive']);
|
||||
}
|
||||
|
@ -35,7 +35,6 @@ class CommandTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testConstructor()
|
||||
{
|
||||
$application = new Application();
|
||||
try {
|
||||
$command = new Command();
|
||||
$this->fail('__construct() throws a \LogicException if the name is null');
|
||||
@ -195,8 +194,6 @@ class CommandTest extends \PHPUnit_Framework_TestCase
|
||||
public function testRun()
|
||||
{
|
||||
$command = new \TestCommand();
|
||||
$application = new Application();
|
||||
$command->setApplication($application);
|
||||
$tester = new CommandTester($command);
|
||||
try {
|
||||
$tester->execute(array('--bar' => true));
|
||||
@ -221,9 +218,7 @@ class CommandTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testSetCode()
|
||||
{
|
||||
$application = new Application();
|
||||
$command = new \TestCommand();
|
||||
$command->setApplication($application);
|
||||
$ret = $command->setCode(function (InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$output->writeln('from the code...');
|
||||
@ -239,7 +234,7 @@ class CommandTest extends \PHPUnit_Framework_TestCase
|
||||
$command = new \TestCommand();
|
||||
$command->setApplication(new Application());
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(array());
|
||||
$tester->execute(array('command' => $command->getFullName()));
|
||||
$this->assertStringEqualsFile(self::$fixturesPath.'/command_astext.txt', $command->asText(), '->asText() returns a text representation of the command');
|
||||
}
|
||||
|
||||
@ -248,7 +243,7 @@ class CommandTest extends \PHPUnit_Framework_TestCase
|
||||
$command = new \TestCommand();
|
||||
$command->setApplication(new Application());
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(array());
|
||||
$tester->execute(array('command' => $command->getFullName()));
|
||||
$this->assertXmlStringEqualsXmlFile(self::$fixturesPath.'/command_asxml.txt', $command->asXml(), '->asXml() returns an XML representation of the command');
|
||||
}
|
||||
}
|
||||
|
@ -19,11 +19,11 @@ class ListCommandTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$application = new Application();
|
||||
|
||||
$commandTester = new CommandTester($application->getCommand('list'));
|
||||
$commandTester->execute(array());
|
||||
$commandTester = new CommandTester($command = $application->getCommand('list'));
|
||||
$commandTester->execute(array('command' => $command->getFullName()));
|
||||
$this->assertRegExp('/help Displays help for a command/', $commandTester->getDisplay(), '->execute() returns a list of available commands');
|
||||
|
||||
$commandTester->execute(array('--xml' => true));
|
||||
$commandTester->execute(array('command' => $command->getFullName(), '--xml' => true));
|
||||
$this->assertRegExp('/<command id="list" namespace="_global" name="list">/', $commandTester->getDisplay(), '->execute() returns a list of available commands in XML if --xml is passed');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user