6
6
use GeneaLabs \LaravelModelCaching \Tests \Fixtures \Publisher ;
7
7
use GeneaLabs \LaravelModelCaching \Tests \Fixtures \Store ;
8
8
use GeneaLabs \LaravelModelCaching \Tests \Fixtures \UncachedAuthor ;
9
+ use GeneaLabs \LaravelModelCaching \Tests \Fixtures \PrefixedAuthor ;
9
10
use GeneaLabs \LaravelModelCaching \Tests \IntegrationTestCase ;
10
11
use Illuminate \Foundation \Testing \RefreshDatabase ;
11
12
12
13
class FlushTest extends IntegrationTestCase
13
14
{
14
15
use RefreshDatabase;
15
16
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
-
43
17
public function testGivenModelIsFlushed ()
44
18
{
45
19
$ authors = (new Author )->all ();
@@ -59,6 +33,29 @@ public function testGivenModelIsFlushed()
59
33
$ this ->assertEquals ($ result , 0 );
60
34
}
61
35
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
+
62
59
public function testGivenModelWithRelationshipIsFlushed ()
63
60
{
64
61
$ authors = (new Author )->with ('books ' )->get ();
0 commit comments