Skip to content

Commit

Permalink
[5.x] Fix statamic-prefixed commands not working when running Artisan…
Browse files Browse the repository at this point in the history
…::call() within please (#9926)
  • Loading branch information
jasonvarga authored Apr 18, 2024
1 parent ff52ed0 commit 9c232fa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/Console/Please/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Console\Kernel as ConsoleKernel;
use Statamic\Console\Please\Application as Please;
use Statamic\Statamic;
use Statamic\Support\Str;
use Symfony\Component\EventDispatcher\EventDispatcher;

class Kernel extends ConsoleKernel
Expand Down Expand Up @@ -36,6 +37,10 @@ public function call($command, array $parameters = [], $outputBuffer = null)
{
$this->getArtisan()->resolveDeferredCommands();

if (Str::startsWith($command, 'statamic:')) {
$command = Str::after($command, 'statamic:');
}

return parent::call($command, $parameters, $outputBuffer);
}

Expand Down
14 changes: 13 additions & 1 deletion tests/Console/PleaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Tests\Console;

use Statamic\Console\Please\Kernel;
use Statamic\Facades\StaticCache;
use Symfony\Component\Console\Exception\CommandNotFoundException;
use Tests\TestCase;

Expand All @@ -18,18 +19,29 @@ public function setUp(): void
/** @test */
public function it_can_run_an_artisan_command_with_statamic_prefix()
{
StaticCache::shouldReceive('flush')->once();
$this->artisan('statamic:static:clear');
}

/** @test */
public function statamic_prefixed_commands_will_throw_exception_when_running_in_artisan_without_prefix()
{
StaticCache::shouldReceive('flush')->never();
$this->expectException(CommandNotFoundException::class);
$this->artisan('static:clear');
}

/** @test */
public function it_can_run_a_please_command_without_statamic_prefix()
{
StaticCache::shouldReceive('flush')->once();
$this->please('static:clear');
}

$this->expectException(CommandNotFoundException::class);
/** @test */
public function it_can_run_a_please_command_with_statamic_prefix()
{
StaticCache::shouldReceive('flush')->once();
$this->please('statamic:static:clear');
}

Expand Down

0 comments on commit 9c232fa

Please sign in to comment.