[Console] added some tests for previous merge (refs #8626)
This commit is contained in:
parent
ad7be73e40
commit
d80e840b7f
@ -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);
|
||||
|
@ -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()));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user