Skip to content

Commit d3f16e8

Browse files
authored
[10.x] Fixes unable to call another command as a initialized instance of Command class. (#51824)
fixes #51822 Signed-off-by: Mior Muhammad Zaki <[email protected]>
1 parent a753876 commit d3f16e8

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

src/Illuminate/Console/Command.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,13 @@ protected function commandIsolationMutex()
236236
*/
237237
protected function resolveCommand($command)
238238
{
239-
if (! class_exists($command)) {
240-
return $this->getApplication()->find($command);
241-
}
239+
if (is_string($command)) {
240+
if (! class_exists($command)) {
241+
return $this->getApplication()->find($command);
242+
}
242243

243-
$command = $this->laravel->make($command);
244+
$command = $this->laravel->make($command);
245+
}
244246

245247
if ($command instanceof SymfonyCommand) {
246248
$command->setApplication($this->getApplication());
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Illuminate\Tests\Integration\Console;
4+
5+
use Illuminate\Foundation\Console\ViewClearCommand;
6+
use Illuminate\Support\Facades\Artisan;
7+
use Orchestra\Testbench\TestCase;
8+
use PHPUnit\Framework\Attributes\TestWith;
9+
10+
class CallCommandsTest extends TestCase
11+
{
12+
protected function setUp(): void
13+
{
14+
$this->afterApplicationCreated(function () {
15+
Artisan::command('test:a', function () {
16+
$this->call('view:clear');
17+
});
18+
19+
Artisan::command('test:b', function () {
20+
$this->call(ViewClearCommand::class);
21+
});
22+
23+
Artisan::command('test:c', function () {
24+
$this->call($this->laravel->make(ViewClearCommand::class));
25+
});
26+
});
27+
28+
parent::setUp();
29+
}
30+
31+
#[TestWith(['test:a'])]
32+
#[TestWith(['test:b'])]
33+
#[TestWith(['test:c'])]
34+
public function testItCanCallCommands(string $command)
35+
{
36+
$this->artisan($command)->assertSuccessful();
37+
}
38+
}

0 commit comments

Comments
 (0)