From 0b07e0f94073eab6b0e47dd0f1d50664021b4611 Mon Sep 17 00:00:00 2001 From: Alexandre D'Eschambeault Date: Wed, 4 Sep 2019 21:59:16 -0400 Subject: [PATCH] Resolve class command via application resolution --- src/Illuminate/Console/Command.php | 2 +- tests/Console/CommandTest.php | 45 ++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 tests/Console/CommandTest.php 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..5075fdb767e3 --- /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); + } +}