Skip to content
Open
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
19 changes: 19 additions & 0 deletions src/Console/Commands/Concerns/HasExcludes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Statamic\Console\Commands\Concerns;

use Statamic\Facades\Stache;

trait HasExcludes
{
protected function addExcludes(?string $excludes = null): void
{
if (empty($excludes)) {
return;
}

foreach (explode(',', $excludes) as $key) {
Stache::exclude($key);
}
}
}
26 changes: 7 additions & 19 deletions src/Console/Commands/StacheClear.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,22 @@
namespace Statamic\Console\Commands;

use Illuminate\Console\Command;
use Statamic\Console\Commands\Concerns\HasExcludes;
use Statamic\Console\RunsInPlease;
use Statamic\Facades\Stache;

class StacheClear extends Command
{
use RunsInPlease;

/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'statamic:stache:clear';

/**
* The console command description.
*
* @var string
*/
use HasExcludes, RunsInPlease;

protected $signature = 'statamic:stache:clear {--exclude=}';

protected $description = 'Clear the "Stache" cache';

/**
* Execute the console command.
*
* @return void
*/
public function handle()
{
$this->addExcludes($this->option('exclude'));

Stache::clear();

$this->components->info('You have trimmed the Stache. It looks dashing.');
Expand Down
8 changes: 6 additions & 2 deletions src/Console/Commands/StacheRefresh.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@
namespace Statamic\Console\Commands;

use Illuminate\Console\Command;
use Statamic\Console\Commands\Concerns\HasExcludes;
use Statamic\Console\RunsInPlease;
use Statamic\Facades\Stache;

use function Laravel\Prompts\spin;

class StacheRefresh extends Command
{
use RunsInPlease;
use HasExcludes, RunsInPlease;

protected $signature = 'statamic:stache:refresh {--exclude=}';

protected $signature = 'statamic:stache:refresh';
protected $description = 'Clear and rebuild the "Stache" cache';

public function handle()
{
$this->addExcludes($this->option('exclude'));

spin(callback: fn () => Stache::clear(), message: 'Clearing the Stache...');
spin(callback: fn () => Stache::warm(), message: 'Warming the Stache...');

Expand Down
8 changes: 6 additions & 2 deletions src/Console/Commands/StacheWarm.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@
namespace Statamic\Console\Commands;

use Illuminate\Console\Command;
use Statamic\Console\Commands\Concerns\HasExcludes;
use Statamic\Console\RunsInPlease;
use Statamic\Facades\Stache;

use function Laravel\Prompts\spin;

class StacheWarm extends Command
{
use RunsInPlease;
use HasExcludes, RunsInPlease;

protected $signature = 'statamic:stache:warm {--exclude=}';

protected $signature = 'statamic:stache:warm';
protected $description = 'Build the "Stache" cache';

public function handle()
{
$this->addExcludes($this->option('exclude'));

spin(callback: fn () => Stache::warm(), message: 'Warming the Stache...');

$this->components->info('You have poured oil over the Stache and polished it until it shines. It is warm and ready');
Expand Down
39 changes: 39 additions & 0 deletions tests/Console/Commands/StacheClearTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Tests\Console\Commands;

use PHPUnit\Framework\Attributes\Test;
use Statamic\Console\Commands\StacheClear;
use Statamic\Facades\Stache;
use Tests\TestCase;

class StacheClearTest extends TestCase
{
#[Test]
public function it_doesnt_add_any_exclusion_if_no_parameter()
{
Stache::shouldReceive('exclude')->never()
->shouldReceive('clear')->once();

$this->artisan(StacheClear::class);
}

#[Test]
public function it_adds_exclude()
{
Stache::shouldReceive('exclude')->once()->with('foo')->andReturn()
->shouldReceive('clear')->once()->andReturn();

$this->artisan(StacheClear::class, ['--exclude' => 'foo']);
}

#[Test]
public function it_adds_multiple_excludes()
{
Stache::shouldReceive('exclude')->once()->with('foo')->andReturn()
->shouldReceive('exclude')->once()->with('bar')->andReturn()
->shouldReceive('clear')->once()->andReturn();

$this->artisan(StacheClear::class, ['--exclude' => 'foo,bar']);
}
}
39 changes: 39 additions & 0 deletions tests/Console/Commands/StacheWarmTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Tests\Console\Commands;

use PHPUnit\Framework\Attributes\Test;
use Statamic\Console\Commands\StacheWarm;
use Statamic\Facades\Stache;
use Tests\TestCase;

class StacheWarmTest extends TestCase
{
#[Test]
public function it_doesnt_add_any_exclusion_if_no_parameter()
{
Stache::shouldReceive('exclude')->never()
->shouldReceive('warm')->once();

$this->artisan(StacheWarm::class);
}

#[Test]
public function it_adds_exclude()
{
Stache::shouldReceive('exclude')->once()->with('foo')->andReturn()
->shouldReceive('warm')->once()->andReturn();

$this->artisan(StacheWarm::class, ['--exclude' => 'foo']);
}

#[Test]
public function it_adds_multiple_excludes()
{
Stache::shouldReceive('exclude')->once()->with('foo')->andReturn()
->shouldReceive('exclude')->once()->with('bar')->andReturn()
->shouldReceive('warm')->once()->andReturn();

$this->artisan(StacheWarm::class, ['--exclude' => 'foo,bar']);
}
}
Loading