Skip to content

Commit

Permalink
[10.x] Fixes unable to call another command as a initialized instance…
Browse files Browse the repository at this point in the history
… of `Command` class. (#51824)

fixes #51822

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
  • Loading branch information
crynobone authored Jun 18, 2024
1 parent a753876 commit d3f16e8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Illuminate/Console/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
38 changes: 38 additions & 0 deletions tests/Integration/Console/CallCommandsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Illuminate\Tests\Integration\Console;

use Illuminate\Foundation\Console\ViewClearCommand;
use Illuminate\Support\Facades\Artisan;
use Orchestra\Testbench\TestCase;
use PHPUnit\Framework\Attributes\TestWith;

class CallCommandsTest extends TestCase
{
protected function setUp(): void
{
$this->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();
}
}

0 comments on commit d3f16e8

Please sign in to comment.