From d80e840b7f35b1c7a3d6953ad7a7ad1987a34bde Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 30 Sep 2013 21:59:36 +0200 Subject: [PATCH] [Console] added some tests for previous merge (refs #8626) --- .../Component/Console/Tester/CommandTester.php | 13 +++++-------- .../Console/Tests/Tester/CommandTesterTest.php | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/Symfony/Component/Console/Tester/CommandTester.php b/src/Symfony/Component/Console/Tester/CommandTester.php index 705abf718f..6866bc6420 100644 --- a/src/Symfony/Component/Console/Tester/CommandTester.php +++ b/src/Symfony/Component/Console/Tester/CommandTester.php @@ -57,14 +57,11 @@ class CommandTester { // set the command name automatically if the application requires // this argument and no command name was passed - if (!isset($input['command'])) { - $application = $this->command->getApplication(); - if (null !== $application) { - $definition = $application->getDefinition(); - if ($definition->hasArgument('command')) { - $input['command'] = $this->command->getName(); - } - } + if (!isset($input['command']) + && (null !== $application = $this->command->getApplication()) + && $application->getDefinition()->hasArgument('command') + ) { + $input['command'] = $this->command->getName(); } $this->input = new ArrayInput($input); diff --git a/src/Symfony/Component/Console/Tests/Tester/CommandTesterTest.php b/src/Symfony/Component/Console/Tests/Tester/CommandTesterTest.php index 1067e9ffc6..b54c00e83d 100644 --- a/src/Symfony/Component/Console/Tests/Tester/CommandTesterTest.php +++ b/src/Symfony/Component/Console/Tests/Tester/CommandTesterTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Console\Tests\Tester; +use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Output\Output; use Symfony\Component\Console\Tester\CommandTester; @@ -64,4 +65,20 @@ class CommandTesterTest extends \PHPUnit_Framework_TestCase { $this->assertSame(0, $this->tester->getStatusCode(), '->getStatusCode() returns the status code'); } + + public function testCommandFromApplication() + { + $application = new Application(); + $application->setAutoExit(false); + + $command = new Command('foo'); + $command->setCode(function ($input, $output) { $output->writeln('foo'); }); + + $application->add($command); + + $tester = new CommandTester($application->find('foo')); + + // check that there is no need to pass the command name here + $this->assertEquals(0, $tester->execute(array())); + } }