66use GeneaLabs \LaravelModelCaching \Tests \Fixtures \Publisher ;
77use GeneaLabs \LaravelModelCaching \Tests \Fixtures \Store ;
88use GeneaLabs \LaravelModelCaching \Tests \Fixtures \UncachedAuthor ;
9+ use GeneaLabs \LaravelModelCaching \Tests \Fixtures \PrefixedAuthor ;
910use GeneaLabs \LaravelModelCaching \Tests \IntegrationTestCase ;
1011use Illuminate \Foundation \Testing \RefreshDatabase ;
1112
1213class FlushTest extends IntegrationTestCase
1314{
1415 use RefreshDatabase;
1516
16- public function setUp ()
17- {
18- parent ::setUp ();
19-
20- $ this ->cache ->flush ();
21- $ publishers = factory (Publisher::class, 10 )->create ();
22- factory (Author::class, 10 )->create ()
23- ->each (function ($ author ) use ($ publishers ) {
24- factory (Book::class, random_int (2 , 10 ))->make ()
25- ->each (function ($ book ) use ($ author , $ publishers ) {
26- $ book ->author ()->associate ($ author );
27- $ book ->publisher ()->associate ($ publishers [rand (0 , 9 )]);
28- $ book ->save ();
29- });
30- factory (Profile::class)->make ([
31- 'author_id ' => $ author ->id ,
32- ]);
33- });
34-
35- $ bookIds = (new Book )->all ()->pluck ('id ' );
36- factory (Store::class, 10 )->create ()
37- ->each (function ($ store ) use ($ bookIds ) {
38- $ store ->books ()->sync (rand ($ bookIds ->min (), $ bookIds ->max ()));
39- });
40- $ this ->cache ->flush ();
41- }
42-
4317 public function testGivenModelIsFlushed ()
4418 {
4519 $ authors = (new Author )->all ();
@@ -59,6 +33,29 @@ public function testGivenModelIsFlushed()
5933 $ this ->assertEquals ($ result , 0 );
6034 }
6135
36+ public function testExtendedModelIsFlushed ()
37+ {
38+ $ authors = (new PrefixedAuthor )
39+ ->get ();
40+
41+ $ key = sha1 ('genealabs:laravel-model-caching:test-prefix:genealabslaravelmodelcachingtestsfixturesprefixedauthor ' );
42+ $ tags = ['genealabs:laravel-model-caching:test-prefix:genealabslaravelmodelcachingtestsfixturesprefixedauthor ' ];
43+
44+ $ cachedResults = $ this
45+ ->cache
46+ ->tags ($ tags )
47+ ->get ($ key )['value ' ];
48+ $ result = $ this ->artisan ('modelCache:flush ' , ['--model ' => PrefixedAuthor::class]);
49+ $ flushedResults = $ this
50+ ->cache
51+ ->tags ($ tags )
52+ ->get ($ key )['value ' ];
53+
54+ $ this ->assertEquals ($ authors , $ cachedResults );
55+ $ this ->assertEmpty ($ flushedResults );
56+ $ this ->assertEquals ($ result , 0 );
57+ }
58+
6259 public function testGivenModelWithRelationshipIsFlushed ()
6360 {
6461 $ authors = (new Author )->with ('books ' )->get ();
0 commit comments