diff --git a/src/Console/Commands/Concerns/HasExcludes.php b/src/Console/Commands/Concerns/HasExcludes.php new file mode 100644 index 00000000000..977ae2c75f1 --- /dev/null +++ b/src/Console/Commands/Concerns/HasExcludes.php @@ -0,0 +1,19 @@ +addExcludes($this->option('exclude')); + Stache::clear(); $this->components->info('You have trimmed the Stache. It looks dashing.'); diff --git a/src/Console/Commands/StacheRefresh.php b/src/Console/Commands/StacheRefresh.php index aaa98bebd74..9c6272b8879 100644 --- a/src/Console/Commands/StacheRefresh.php +++ b/src/Console/Commands/StacheRefresh.php @@ -3,6 +3,7 @@ namespace Statamic\Console\Commands; use Illuminate\Console\Command; +use Statamic\Console\Commands\Concerns\HasExcludes; use Statamic\Console\RunsInPlease; use Statamic\Facades\Stache; @@ -10,13 +11,16 @@ 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...'); diff --git a/src/Console/Commands/StacheWarm.php b/src/Console/Commands/StacheWarm.php index 0a6965c744b..0797251c186 100644 --- a/src/Console/Commands/StacheWarm.php +++ b/src/Console/Commands/StacheWarm.php @@ -3,6 +3,7 @@ namespace Statamic\Console\Commands; use Illuminate\Console\Command; +use Statamic\Console\Commands\Concerns\HasExcludes; use Statamic\Console\RunsInPlease; use Statamic\Facades\Stache; @@ -10,13 +11,16 @@ 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'); diff --git a/tests/Console/Commands/StacheClearTest.php b/tests/Console/Commands/StacheClearTest.php new file mode 100644 index 00000000000..d3097e48a87 --- /dev/null +++ b/tests/Console/Commands/StacheClearTest.php @@ -0,0 +1,39 @@ +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']); + } +} diff --git a/tests/Console/Commands/StacheWarmTest.php b/tests/Console/Commands/StacheWarmTest.php new file mode 100644 index 00000000000..d74ce4bbe04 --- /dev/null +++ b/tests/Console/Commands/StacheWarmTest.php @@ -0,0 +1,39 @@ +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']); + } +}