1
1
<?php namespace GeneaLabs \LaravelModelCaching \Tests \Integration \CachedBuilder ;
2
2
3
3
use GeneaLabs \LaravelModelCaching \Tests \Fixtures \Author ;
4
+ use GeneaLabs \LaravelModelCaching \Tests \Fixtures \Book ;
4
5
use GeneaLabs \LaravelModelCaching \Tests \Fixtures \UncachedAuthor ;
6
+ use GeneaLabs \LaravelModelCaching \Tests \Fixtures \UncachedBook ;
5
7
use GeneaLabs \LaravelModelCaching \Tests \IntegrationTestCase ;
6
8
7
9
class BooleanTest extends IntegrationTestCase
8
10
{
9
- public function testBooleanWhereCreatesCorrectCacheKey ()
11
+ public function testBooleanWhereTrueCreatesCorrectCacheKey ()
10
12
{
11
13
$ key = sha1 ("genealabs:laravel-model-caching:testing: {$ this ->testingSqlitePath }testing.sqlite:authors:genealabslaravelmodelcachingtestsfixturesauthor-is_famous_=_1-authors.deleted_at_null " );
12
14
$ tags = [
@@ -29,4 +31,61 @@ public function testBooleanWhereCreatesCorrectCacheKey()
29
31
$ this ->assertNotEmpty ($ cachedResults );
30
32
$ this ->assertNotEmpty ($ liveResults );
31
33
}
34
+
35
+ public function testBooleanWhereFalseCreatesCorrectCacheKey ()
36
+ {
37
+ $ key = sha1 ("genealabs:laravel-model-caching:testing: {$ this ->testingSqlitePath }testing.sqlite:authors:genealabslaravelmodelcachingtestsfixturesauthor-is_famous_=_-authors.deleted_at_null " );
38
+ $ tags = [
39
+ "genealabs:laravel-model-caching:testing: {$ this ->testingSqlitePath }testing.sqlite:genealabslaravelmodelcachingtestsfixturesauthor " ,
40
+ ];
41
+
42
+ $ authors = (new Author )
43
+ ->where ("is_famous " , false )
44
+ ->get ();
45
+ $ cachedResults = $ this ->cache ()
46
+ ->tags ($ tags )
47
+ ->get ($ key )['value ' ];
48
+ $ liveResults = (new UncachedAuthor )
49
+ ->where ("is_famous " , false )
50
+ ->get ();
51
+
52
+ $ this ->assertEquals ($ liveResults ->pluck ("id " ), $ authors ->pluck ("id " ));
53
+ $ this ->assertEquals ($ liveResults ->pluck ("id " ), $ cachedResults ->pluck ("id " ));
54
+ $ this ->assertNotEmpty ($ authors );
55
+ $ this ->assertNotEmpty ($ cachedResults );
56
+ $ this ->assertNotEmpty ($ liveResults );
57
+ }
58
+
59
+ public function testBooleanWhereHasRelationWithFalseConditionAndAdditionalParentRawCondition ()
60
+ {
61
+ $ key = sha1 ("genealabs:laravel-model-caching:testing: {$ this ->testingSqlitePath }testing.sqlite:books:genealabslaravelmodelcachingtestsfixturesbook-exists-and_books.author_id_=_authors.id-is_famous_=_-authors.deleted_at_null-_and_title_=_Mixed_Clause " );
62
+ $ tags = [
63
+ "genealabs:laravel-model-caching:testing: {$ this ->testingSqlitePath }testing.sqlite:genealabslaravelmodelcachingtestsfixturesbook " ,
64
+ ];
65
+
66
+ $ expectedAuthor = factory (Author::class)->create (['is_famous ' => false ]);
67
+ factory (Book::class)->create (['author_id ' => $ expectedAuthor ->getKey (), 'title ' => 'Mixed Clause ' ]);
68
+
69
+ $ books = (new Book )
70
+ ->whereHas ('author ' , function ($ query ) {
71
+ return $ query ->where ('is_famous ' , false );
72
+ })
73
+ ->whereRaw ("title = ? " , ['Mixed Clause ' ]) // Test ensures this binding is included in the key
74
+ ->get ();
75
+ $ cachedResults = $ this ->cache ()
76
+ ->tags ($ tags )
77
+ ->get ($ key )['value ' ];
78
+ $ liveResults = (new UncachedBook )
79
+ ->whereHas ('author ' , function ($ query ) {
80
+ return $ query ->where ('is_famous ' , false );
81
+ })
82
+ ->whereRaw ("title = ? " , ['Mixed Clause ' ])
83
+ ->get ();
84
+
85
+ $ this ->assertEquals ($ liveResults ->pluck ("id " ), $ books ->pluck ("id " ));
86
+ $ this ->assertEquals ($ liveResults ->pluck ("id " ), $ cachedResults ->pluck ("id " ));
87
+ $ this ->assertNotEmpty ($ books );
88
+ $ this ->assertNotEmpty ($ cachedResults );
89
+ $ this ->assertNotEmpty ($ liveResults );
90
+ }
32
91
}
0 commit comments