diff --git a/src/Illuminate/Console/Command.php b/src/Illuminate/Console/Command.php index 3988a6a335d3..8957cd100110 100755 --- a/src/Illuminate/Console/Command.php +++ b/src/Illuminate/Console/Command.php @@ -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()); diff --git a/tests/Console/CommandTest.php b/tests/Console/CommandTest.php new file mode 100644 index 000000000000..033c47dc2de7 --- /dev/null +++ b/tests/Console/CommandTest.php @@ -0,0 +1,45 @@ +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); + } +}