Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d80e840

Browse files
committed
[Console] added some tests for previous merge (refs #8626)
1 parent ad7be73 commit d80e840

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/Symfony/Component/Console/Tester/CommandTester.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,11 @@ public function execute(array $input, array $options = array())
5757
{
5858
// set the command name automatically if the application requires
5959
// this argument and no command name was passed
60-
if (!isset($input['command'])) {
61-
$application = $this->command->getApplication();
62-
if (null !== $application) {
63-
$definition = $application->getDefinition();
64-
if ($definition->hasArgument('command')) {
65-
$input['command'] = $this->command->getName();
66-
}
67-
}
60+
if (!isset($input['command'])
61+
&& (null !== $application = $this->command->getApplication())
62+
&& $application->getDefinition()->hasArgument('command')
63+
) {
64+
$input['command'] = $this->command->getName();
6865
}
6966

7067
$this->input = new ArrayInput($input);

src/Symfony/Component/Console/Tests/Tester/CommandTesterTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Console\Tests\Tester;
1313

14+
use Symfony\Component\Console\Application;
1415
use Symfony\Component\Console\Command\Command;
1516
use Symfony\Component\Console\Output\Output;
1617
use Symfony\Component\Console\Tester\CommandTester;
@@ -64,4 +65,20 @@ public function testGetStatusCode()
6465
{
6566
$this->assertSame(0, $this->tester->getStatusCode(), '->getStatusCode() returns the status code');
6667
}
68+
69+
public function testCommandFromApplication()
70+
{
71+
$application = new Application();
72+
$application->setAutoExit(false);
73+
74+
$command = new Command('foo');
75+
$command->setCode(function ($input, $output) { $output->writeln('foo'); });
76+
77+
$application->add($command);
78+
79+
$tester = new CommandTester($application->find('foo'));
80+
81+
// check that there is no need to pass the command name here
82+
$this->assertEquals(0, $tester->execute(array()));
83+
}
6784
}

0 commit comments

Comments
 (0)