Skip to content

Commit

Permalink
Resolve class command via application resolution (#29869)
Browse files Browse the repository at this point in the history
  • Loading branch information
xel1045 authored and taylorotwell committed Sep 6, 2019
1 parent aa2e7b6 commit 8d4a301
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Illuminate/Console/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ protected function resolveCommand($command)
return $this->getApplication()->find($command);
}

$command = new $command;
$command = $this->laravel->make($command);

if ($command instanceof SymfonyCommand) {
$command->setApplication($this->getApplication());
Expand Down
45 changes: 45 additions & 0 deletions tests/Console/CommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Illuminate\Tests\Console;

use Mockery as m;
use Illuminate\Console\Command;
use PHPUnit\Framework\TestCase;
use Illuminate\Console\Application;
use Illuminate\Console\OutputStyle;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput;

class CommandTest extends TestCase
{
protected function tearDown(): void
{
m::close();
}

public function testCallingClassCommandResolveCommandViaApplicationResolution()
{
$command = new Command();

$application = m::mock(Application::class);
$command->setLaravel($application);

$input = new ArrayInput([]);
$output = new NullOutput();
$application->shouldReceive('make')->with(OutputStyle::class, ['input' => $input, 'output' => $output])->andReturn(m::mock(OutputStyle::class));

$application->shouldReceive('call')->with([$command, 'handle'])->andReturnUsing(function () use ($command, $application) {
$commandCalled = m::mock(Command::class);

$application->shouldReceive('make')->once()->with(Command::class)->andReturn($commandCalled);

$commandCalled->shouldReceive('setApplication')->once()->with(null);
$commandCalled->shouldReceive('setLaravel')->once()->with($application);
$commandCalled->shouldReceive('run')->once();

$command->call(Command::class);
});

$command->run($input, $output);
}
}

0 comments on commit 8d4a301

Please sign in to comment.