File tree Expand file tree Collapse file tree 3 files changed +40
-1
lines changed
tests/Unit/Console/Commands Expand file tree Collapse file tree 3 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44The format is based on [ Keep a Changelog] ( http://keepachangelog.com/en/1.0.0/ )
55and this project adheres to [ Semantic Versioning] ( http://semver.org/spec/v2.0.0.html ) .
66
7+ ## [ 0.2.15] - 30 Dec 2017
8+ ### Added
9+ - sanity checks for artisan command with feedback as to what needs to be fixed.
10+
711## [ 0.2.14] - 30 Dec 2017
812### Added
913- ability to flush cache for a given model via Artisan command.
Original file line number Diff line number Diff line change 11<?php namespace GeneaLabs \LaravelModelCaching \Console \Commands ;
22
33use Illuminate \Console \Command ;
4+ use GeneaLabs \LaravelModelCaching \CachedModel ;
45
56class Flush extends Command
67{
@@ -10,8 +11,24 @@ class Flush extends Command
1011 public function handle ()
1112 {
1213 $ option = $ this ->option ('model ' );
14+
15+ if (! $ option ) {
16+ $ this ->error ("You must specify a model to flush a model's cache: " );
17+ $ this ->line ("modelCache:flush --model=App \\Model " );
18+
19+ return 1 ;
20+ }
21+
1322 $ model = new $ option ;
23+
24+ if (! $ model instanceof CachedModel) {
25+ $ this ->error ("' {$ option }' is not an instance of CachedModel. " );
26+ $ this ->line ("Only CachedModel instances can be flushed. " );
27+
28+ return 1 ;
29+ }
30+
1431 $ model ->flushCache ();
15- $ this ->info ("Cache for model ' {$ option }' flushed. " );
32+ $ this ->info ("✔︎ Cache for model ' {$ option }' has been flushed. " );
1633 }
1734}
Original file line number Diff line number Diff line change 55use GeneaLabs \LaravelModelCaching \Tests \Fixtures \Profile ;
66use GeneaLabs \LaravelModelCaching \Tests \Fixtures \Publisher ;
77use GeneaLabs \LaravelModelCaching \Tests \Fixtures \Store ;
8+ use GeneaLabs \LaravelModelCaching \Tests \Fixtures \UncachedAuthor ;
89use GeneaLabs \LaravelModelCaching \Tests \TestCase ;
910use Illuminate \Foundation \Testing \RefreshDatabase ;
1011
@@ -82,4 +83,21 @@ public function testGivenModelWithRelationshipIsFlushed()
8283 $ this ->assertEmpty ($ flushedResults );
8384 $ this ->assertEquals ($ result , 0 );
8485 }
86+
87+ public function testNonCachedModelsCannotBeFlushed ()
88+ {
89+ $ result = $ this ->artisan (
90+ 'modelCache:flush ' ,
91+ ['--model ' => UncachedAuthor::class]
92+ );
93+
94+ $ this ->assertEquals ($ result , 1 );
95+ }
96+
97+ public function testModelOptionIsSpecified ()
98+ {
99+ $ result = $ this ->artisan ('modelCache:flush ' , []);
100+
101+ $ this ->assertEquals ($ result , 1 );
102+ }
85103}
You can’t perform that action at this time.
0 commit comments