File tree 3 files changed +40
-1
lines changed
tests/Unit/Console/Commands
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.
4
4
The format is based on [ Keep a Changelog] ( http://keepachangelog.com/en/1.0.0/ )
5
5
and this project adheres to [ Semantic Versioning] ( http://semver.org/spec/v2.0.0.html ) .
6
6
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
+
7
11
## [ 0.2.14] - 30 Dec 2017
8
12
### Added
9
13
- ability to flush cache for a given model via Artisan command.
Original file line number Diff line number Diff line change 1
1
<?php namespace GeneaLabs \LaravelModelCaching \Console \Commands ;
2
2
3
3
use Illuminate \Console \Command ;
4
+ use GeneaLabs \LaravelModelCaching \CachedModel ;
4
5
5
6
class Flush extends Command
6
7
{
@@ -10,8 +11,24 @@ class Flush extends Command
10
11
public function handle ()
11
12
{
12
13
$ 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
+
13
22
$ 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
+
14
31
$ model ->flushCache ();
15
- $ this ->info ("Cache for model ' {$ option }' flushed. " );
32
+ $ this ->info ("✔︎ Cache for model ' {$ option }' has been flushed. " );
16
33
}
17
34
}
Original file line number Diff line number Diff line change 5
5
use GeneaLabs \LaravelModelCaching \Tests \Fixtures \Profile ;
6
6
use GeneaLabs \LaravelModelCaching \Tests \Fixtures \Publisher ;
7
7
use GeneaLabs \LaravelModelCaching \Tests \Fixtures \Store ;
8
+ use GeneaLabs \LaravelModelCaching \Tests \Fixtures \UncachedAuthor ;
8
9
use GeneaLabs \LaravelModelCaching \Tests \TestCase ;
9
10
use Illuminate \Foundation \Testing \RefreshDatabase ;
10
11
@@ -82,4 +83,21 @@ public function testGivenModelWithRelationshipIsFlushed()
82
83
$ this ->assertEmpty ($ flushedResults );
83
84
$ this ->assertEquals ($ result , 0 );
84
85
}
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
+ }
85
103
}
You can’t perform that action at this time.
0 commit comments