From e6cbfd7292f9d94750d00b7f36d0ec4bee685892 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 20 Jul 2010 09:02:54 +0200 Subject: [PATCH] [Console] changed CommandTester to allow testing Command classes without the need for an Application --- src/Symfony/Components/Console/Tester/CommandTester.php | 2 +- .../Tests/Components/Console/Command/CommandTest.php | 9 ++------- .../Tests/Components/Console/Command/ListCommandTest.php | 6 +++--- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/Symfony/Components/Console/Tester/CommandTester.php b/src/Symfony/Components/Console/Tester/CommandTester.php index 59994357b411..f5d21e3c96a6 100644 --- a/src/Symfony/Components/Console/Tester/CommandTester.php +++ b/src/Symfony/Components/Console/Tester/CommandTester.php @@ -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']); } diff --git a/tests/Symfony/Tests/Components/Console/Command/CommandTest.php b/tests/Symfony/Tests/Components/Console/Command/CommandTest.php index 76d10b7aa3b7..42b0eeb99c45 100644 --- a/tests/Symfony/Tests/Components/Console/Command/CommandTest.php +++ b/tests/Symfony/Tests/Components/Console/Command/CommandTest.php @@ -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'); @@ -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)); @@ -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...'); @@ -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'); } @@ -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'); } } diff --git a/tests/Symfony/Tests/Components/Console/Command/ListCommandTest.php b/tests/Symfony/Tests/Components/Console/Command/ListCommandTest.php index 8527465d5e73..1c3496b82e2c 100644 --- a/tests/Symfony/Tests/Components/Console/Command/ListCommandTest.php +++ b/tests/Symfony/Tests/Components/Console/Command/ListCommandTest.php @@ -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('//', $commandTester->getDisplay(), '->execute() returns a list of available commands in XML if --xml is passed'); } }