[Console] added some tests for previous merge (refs #8626)

This commit is contained in:
Fabien Potencier 2013-09-30 21:59:36 +02:00
parent ad7be73e40
commit d80e840b7f
2 changed files with 22 additions and 8 deletions

View File

@ -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);

View File

@ -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()));
}
}