diff --git a/src/Illuminate/Console/Command.php b/src/Illuminate/Console/Command.php index 7e1b3a1ff6ed..1c6d949fd12f 100755 --- a/src/Illuminate/Console/Command.php +++ b/src/Illuminate/Console/Command.php @@ -236,11 +236,13 @@ protected function commandIsolationMutex() */ protected function resolveCommand($command) { - if (! class_exists($command)) { - return $this->getApplication()->find($command); - } + if (is_string($command)) { + if (! class_exists($command)) { + return $this->getApplication()->find($command); + } - $command = $this->laravel->make($command); + $command = $this->laravel->make($command); + } if ($command instanceof SymfonyCommand) { $command->setApplication($this->getApplication()); diff --git a/tests/Integration/Console/CallCommandsTest.php b/tests/Integration/Console/CallCommandsTest.php new file mode 100644 index 000000000000..4724b538aec1 --- /dev/null +++ b/tests/Integration/Console/CallCommandsTest.php @@ -0,0 +1,38 @@ +afterApplicationCreated(function () { + Artisan::command('test:a', function () { + $this->call('view:clear'); + }); + + Artisan::command('test:b', function () { + $this->call(ViewClearCommand::class); + }); + + Artisan::command('test:c', function () { + $this->call($this->laravel->make(ViewClearCommand::class)); + }); + }); + + parent::setUp(); + } + + #[TestWith(['test:a'])] + #[TestWith(['test:b'])] + #[TestWith(['test:c'])] + public function testItCanCallCommands(string $command) + { + $this->artisan($command)->assertSuccessful(); + } +}