Skip to content

Commit

Permalink
[Console] changed CommandTester to allow testing Command classes with…
Browse files Browse the repository at this point in the history
…out the need for an Application
  • Loading branch information
fabpot committed Jul 20, 2010
1 parent c57cae7 commit e6cbfd7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Symfony/Components/Console/Tester/CommandTester.php
Expand Up @@ -51,7 +51,7 @@ public function __construct(Command $command)
*/
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']);
}
Expand Down
Expand Up @@ -35,7 +35,6 @@ static public function setUpBeforeClass()

public function testConstructor()
{
$application = new Application();
try {
$command = new Command();
$this->fail('__construct() throws a \LogicException if the name is null');
Expand Down Expand Up @@ -195,8 +194,6 @@ public function testMergeApplicationDefinition()
public function testRun()
{
$command = new \TestCommand();
$application = new Application();
$command->setApplication($application);
$tester = new CommandTester($command);
try {
$tester->execute(array('--bar' => true));
Expand All @@ -221,9 +218,7 @@ public function testRun()

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...');
Expand All @@ -239,7 +234,7 @@ public function testAsText()
$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');
}

Expand All @@ -248,7 +243,7 @@ public function testAsXml()
$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');
}
}
Expand Up @@ -19,11 +19,11 @@ public function testExecute()
{
$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');
}
}

0 comments on commit e6cbfd7

Please sign in to comment.