@@ -13,11 +13,15 @@ class FlushTest extends UnitTestCase
13
13
{
14
14
use RefreshDatabase;
15
15
16
+ protected $ cache ;
17
+
16
18
public function setUp ()
17
19
{
18
20
parent ::setUp ();
19
21
20
- cache ()->flush ();
22
+ $ this ->cache = cache ()->store (config ('laravel-model-caching:store ' ));
23
+
24
+ $ this ->cache ->flush ();
21
25
$ publishers = factory (Publisher::class, 10 )->create ();
22
26
factory (Author::class, 10 )->create ()
23
27
->each (function ($ author ) use ($ publishers ) {
@@ -37,7 +41,7 @@ public function setUp()
37
41
->each (function ($ store ) use ($ bookIds ) {
38
42
$ store ->books ()->sync (rand ($ bookIds ->min (), $ bookIds ->max ()));
39
43
});
40
- cache () ->flush ();
44
+ $ this -> cache ->flush ();
41
45
}
42
46
43
47
public function testGivenModelIsFlushed ()
@@ -46,11 +50,11 @@ public function testGivenModelIsFlushed()
46
50
$ key = sha1 ('genealabs:laravel-model-caching:genealabslaravelmodelcachingtestsfixturesauthor ' );
47
51
$ tags = ['genealabs:laravel-model-caching:genealabslaravelmodelcachingtestsfixturesauthor ' ];
48
52
49
- $ cachedResults = cache ()
53
+ $ cachedResults = $ this -> cache
50
54
->tags ($ tags )
51
55
->get ($ key )['value ' ];
52
56
$ result = $ this ->artisan ('modelCache:flush ' , ['--model ' => Author::class]);
53
- $ flushedResults = cache ()
57
+ $ flushedResults = $ this -> cache
54
58
->tags ($ tags )
55
59
->get ($ key )['value ' ];
56
60
@@ -68,14 +72,14 @@ public function testGivenModelWithRelationshipIsFlushed()
68
72
'genealabs:laravel-model-caching:genealabslaravelmodelcachingtestsfixturesbook ' ,
69
73
];
70
74
71
- $ cachedResults = cache ()
75
+ $ cachedResults = $ this -> cache
72
76
->tags ($ tags )
73
77
->get ($ key )['value ' ];
74
78
$ result = $ this ->artisan (
75
79
'modelCache:flush ' ,
76
80
['--model ' => Author::class]
77
81
);
78
- $ flushedResults = cache ()
82
+ $ flushedResults = $ this -> cache
79
83
->tags ($ tags )
80
84
->get ($ key )['value ' ];
81
85
@@ -94,10 +98,52 @@ public function testNonCachedModelsCannotBeFlushed()
94
98
$ this ->assertEquals ($ result , 1 );
95
99
}
96
100
97
- public function testModelOptionIsSpecified ()
101
+ public function testAllModelsAreFlushed ()
98
102
{
99
- $ result = $ this ->artisan ('modelCache:flush ' , []);
103
+ (new Author )->all ();
104
+ (new Book )->all ();
105
+ (new Store )->all ();
100
106
101
- $ this ->assertEquals ($ result , 1 );
107
+ $ key = sha1 ('genealabs:laravel-model-caching:genealabslaravelmodelcachingtestsfixturesauthor ' );
108
+ $ tags = ['genealabs:laravel-model-caching:genealabslaravelmodelcachingtestsfixturesauthor ' ];
109
+ $ cachedAuthors = $ this ->cache
110
+ ->tags ($ tags )
111
+ ->get ($ key )['value ' ];
112
+ $ key = sha1 ('genealabs:laravel-model-caching:genealabslaravelmodelcachingtestsfixturesbook ' );
113
+ $ tags = ['genealabs:laravel-model-caching:genealabslaravelmodelcachingtestsfixturesbook ' ];
114
+ $ cachedBooks = $ this ->cache
115
+ ->tags ($ tags )
116
+ ->get ($ key )['value ' ];
117
+ $ key = sha1 ('genealabs:laravel-model-caching:genealabslaravelmodelcachingtestsfixturesstore ' );
118
+ $ tags = ['genealabs:laravel-model-caching:genealabslaravelmodelcachingtestsfixturesstore ' ];
119
+ $ cachedStores = $ this ->cache
120
+ ->tags ($ tags )
121
+ ->get ($ key )['value ' ];
122
+
123
+ $ this ->assertNotEmpty ($ cachedAuthors );
124
+ $ this ->assertNotEmpty ($ cachedBooks );
125
+ $ this ->assertNotEmpty ($ cachedStores );
126
+
127
+ $ this ->artisan ('modelCache:flush ' , []);
128
+
129
+ $ key = sha1 ('genealabs:laravel-model-caching:genealabslaravelmodelcachingtestsfixturesauthor ' );
130
+ $ tags = ['genealabs:laravel-model-caching:genealabslaravelmodelcachingtestsfixturesauthor ' ];
131
+ $ cachedAuthors = $ this ->cache
132
+ ->tags ($ tags )
133
+ ->get ($ key )['value ' ];
134
+ $ key = sha1 ('genealabs:laravel-model-caching:genealabslaravelmodelcachingtestsfixturesbook ' );
135
+ $ tags = ['genealabs:laravel-model-caching:genealabslaravelmodelcachingtestsfixturesbook ' ];
136
+ $ cachedBooks = $ this ->cache
137
+ ->tags ($ tags )
138
+ ->get ($ key )['value ' ];
139
+ $ key = sha1 ('genealabs:laravel-model-caching:genealabslaravelmodelcachingtestsfixturesstore ' );
140
+ $ tags = ['genealabs:laravel-model-caching:genealabslaravelmodelcachingtestsfixturesstore ' ];
141
+ $ cachedStores = $ this ->cache
142
+ ->tags ($ tags )
143
+ ->get ($ key )['value ' ];
144
+
145
+ $ this ->assertEmpty ($ cachedAuthors );
146
+ $ this ->assertEmpty ($ cachedBooks );
147
+ $ this ->assertEmpty ($ cachedStores );
102
148
}
103
149
}
0 commit comments