Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Fix statamic-prefixed commands not working when running Artisan::call() within please #9926

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading