File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Statamic \Console \Commands \Concerns ;
4+
5+ use Statamic \Facades \Stache ;
6+
7+ trait HasExcludes
8+ {
9+ protected function addExcludes (?string $ excludes = null ): void
10+ {
11+ if (empty ($ excludes )) {
12+ return ;
13+ }
14+
15+ foreach (explode (', ' , $ excludes ) as $ key ) {
16+ Stache::exclude ($ key );
17+ }
18+ }
19+ }
Original file line number Diff line number Diff line change 33namespace Statamic \Console \Commands ;
44
55use Illuminate \Console \Command ;
6+ use Statamic \Console \Commands \Concerns \HasExcludes ;
67use Statamic \Console \RunsInPlease ;
78use Statamic \Facades \Stache ;
89
910class StacheClear extends Command
1011{
11- use RunsInPlease;
12-
13- /**
14- * The name and signature of the console command.
15- *
16- * @var string
17- */
18- protected $ signature = 'statamic:stache:clear ' ;
19-
20- /**
21- * The console command description.
22- *
23- * @var string
24- */
12+ use HasExcludes, RunsInPlease;
13+
14+ protected $ signature = 'statamic:stache:clear {--exclude=} ' ;
15+
2516 protected $ description = 'Clear the "Stache" cache ' ;
2617
27- /**
28- * Execute the console command.
29- *
30- * @return void
31- */
3218 public function handle ()
3319 {
20+ $ this ->addExcludes ($ this ->option ('exclude ' ));
21+
3422 Stache::clear ();
3523
3624 $ this ->components ->info ('You have trimmed the Stache. It looks dashing. ' );
Original file line number Diff line number Diff line change 33namespace Statamic \Console \Commands ;
44
55use Illuminate \Console \Command ;
6+ use Statamic \Console \Commands \Concerns \HasExcludes ;
67use Statamic \Console \RunsInPlease ;
78use Statamic \Facades \Stache ;
89
910use function Laravel \Prompts \spin ;
1011
1112class StacheRefresh extends Command
1213{
13- use RunsInPlease;
14+ use HasExcludes, RunsInPlease;
15+
16+ protected $ signature = 'statamic:stache:refresh {--exclude=} ' ;
1417
15- protected $ signature = 'statamic:stache:refresh ' ;
1618 protected $ description = 'Clear and rebuild the "Stache" cache ' ;
1719
1820 public function handle ()
1921 {
22+ $ this ->addExcludes ($ this ->option ('exclude ' ));
23+
2024 spin (callback: fn () => Stache::clear (), message: 'Clearing the Stache... ' );
2125 spin (callback: fn () => Stache::warm (), message: 'Warming the Stache... ' );
2226
Original file line number Diff line number Diff line change 33namespace Statamic \Console \Commands ;
44
55use Illuminate \Console \Command ;
6+ use Statamic \Console \Commands \Concerns \HasExcludes ;
67use Statamic \Console \RunsInPlease ;
78use Statamic \Facades \Stache ;
89
910use function Laravel \Prompts \spin ;
1011
1112class StacheWarm extends Command
1213{
13- use RunsInPlease;
14+ use HasExcludes, RunsInPlease;
15+
16+ protected $ signature = 'statamic:stache:warm {--exclude=} ' ;
1417
15- protected $ signature = 'statamic:stache:warm ' ;
1618 protected $ description = 'Build the "Stache" cache ' ;
1719
1820 public function handle ()
1921 {
22+ $ this ->addExcludes ($ this ->option ('exclude ' ));
23+
2024 spin (callback: fn () => Stache::warm (), message: 'Warming the Stache... ' );
2125
2226 $ this ->components ->info ('You have poured oil over the Stache and polished it until it shines. It is warm and ready ' );
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Tests \Console \Commands ;
4+
5+ use PHPUnit \Framework \Attributes \Test ;
6+ use Statamic \Console \Commands \StacheClear ;
7+ use Statamic \Facades \Stache ;
8+ use Tests \TestCase ;
9+
10+ class StacheClearTest extends TestCase
11+ {
12+ #[Test]
13+ public function it_doesnt_add_any_exclusion_if_no_parameter ()
14+ {
15+ Stache::shouldReceive ('exclude ' )->never ()
16+ ->shouldReceive ('clear ' )->once ();
17+
18+ $ this ->artisan (StacheClear::class);
19+ }
20+
21+ #[Test]
22+ public function it_adds_exclude ()
23+ {
24+ Stache::shouldReceive ('exclude ' )->once ()->with ('foo ' )->andReturn ()
25+ ->shouldReceive ('clear ' )->once ()->andReturn ();
26+
27+ $ this ->artisan (StacheClear::class, ['--exclude ' => 'foo ' ]);
28+ }
29+
30+ #[Test]
31+ public function it_adds_multiple_excludes ()
32+ {
33+ Stache::shouldReceive ('exclude ' )->once ()->with ('foo ' )->andReturn ()
34+ ->shouldReceive ('exclude ' )->once ()->with ('bar ' )->andReturn ()
35+ ->shouldReceive ('clear ' )->once ()->andReturn ();
36+
37+ $ this ->artisan (StacheClear::class, ['--exclude ' => 'foo,bar ' ]);
38+ }
39+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Tests \Console \Commands ;
4+
5+ use PHPUnit \Framework \Attributes \Test ;
6+ use Statamic \Console \Commands \StacheWarm ;
7+ use Statamic \Facades \Stache ;
8+ use Tests \TestCase ;
9+
10+ class StacheWarmTest extends TestCase
11+ {
12+ #[Test]
13+ public function it_doesnt_add_any_exclusion_if_no_parameter ()
14+ {
15+ Stache::shouldReceive ('exclude ' )->never ()
16+ ->shouldReceive ('warm ' )->once ();
17+
18+ $ this ->artisan (StacheWarm::class);
19+ }
20+
21+ #[Test]
22+ public function it_adds_exclude ()
23+ {
24+ Stache::shouldReceive ('exclude ' )->once ()->with ('foo ' )->andReturn ()
25+ ->shouldReceive ('warm ' )->once ()->andReturn ();
26+
27+ $ this ->artisan (StacheWarm::class, ['--exclude ' => 'foo ' ]);
28+ }
29+
30+ #[Test]
31+ public function it_adds_multiple_excludes ()
32+ {
33+ Stache::shouldReceive ('exclude ' )->once ()->with ('foo ' )->andReturn ()
34+ ->shouldReceive ('exclude ' )->once ()->with ('bar ' )->andReturn ()
35+ ->shouldReceive ('warm ' )->once ()->andReturn ();
36+
37+ $ this ->artisan (StacheWarm::class, ['--exclude ' => 'foo,bar ' ]);
38+ }
39+ }
You can’t perform that action at this time.
0 commit comments