|
1
|
|
|
<?php namespace GeneaLabs\LaravelModelCaching\Tests\Integration\CachedBuilder; |
|
2
|
|
|
|
|
3
|
|
|
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Author; |
|
4
|
|
|
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Book; |
|
5
|
|
|
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedAuthor; |
|
6
|
|
|
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedBook; |
|
7
|
|
|
use GeneaLabs\LaravelModelCaching\Tests\IntegrationTestCase; |
|
8
|
|
|
|
|
9
|
|
|
class WhereInTest extends IntegrationTestCase |
|
10
|
|
|
{ |
|
11
|
|
View Code Duplication |
public function testWhereInUsingCollectionQuery() |
|
12
|
|
|
{ |
|
13
|
|
|
$key = sha1("genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:books:genealabslaravelmodelcachingtestsfixturesbook-author_id_in_1_2_3_4"); |
|
14
|
|
|
$tags = [ |
|
15
|
|
|
"genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesbook", |
|
16
|
|
|
]; |
|
17
|
|
|
$authors = (new UncachedAuthor) |
|
18
|
|
|
->where("id", "<", 5) |
|
19
|
|
|
->get(["id"]); |
|
20
|
|
|
|
|
21
|
|
|
$books = (new Book) |
|
22
|
|
|
->whereIn("author_id", $authors) |
|
23
|
|
|
->get(); |
|
24
|
|
|
$cachedResults = $this |
|
25
|
|
|
->cache() |
|
26
|
|
|
->tags($tags) |
|
27
|
|
|
->get($key)['value']; |
|
28
|
|
|
$liveResults = (new UncachedBook) |
|
29
|
|
|
->whereIn("author_id", $authors) |
|
30
|
|
|
->get(); |
|
31
|
|
|
|
|
32
|
|
|
$this->assertEquals($liveResults->pluck("id"), $books->pluck("id")); |
|
33
|
|
|
$this->assertEquals($liveResults->pluck("id"), $cachedResults->pluck("id")); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function testWhereInWhenSetIsEmpty() |
|
37
|
|
|
{ |
|
38
|
|
|
$key = sha1("genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:authors:genealabslaravelmodelcachingtestsfixturesauthor-id_in_-authors.deleted_at_null"); |
|
39
|
|
|
$tags = [ |
|
40
|
|
|
"genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesauthor", |
|
41
|
|
|
]; |
|
42
|
|
|
$authors = (new Author) |
|
43
|
|
|
->whereIn("id", []) |
|
44
|
|
|
->get(); |
|
45
|
|
|
$cachedResults = $this |
|
46
|
|
|
->cache() |
|
47
|
|
|
->tags($tags) |
|
48
|
|
|
->get($key)['value']; |
|
49
|
|
|
$liveResults = (new UncachedAuthor) |
|
50
|
|
|
->whereIn("id", []) |
|
51
|
|
|
->get(); |
|
52
|
|
|
|
|
53
|
|
|
$this->assertEquals($liveResults->pluck("id"), $authors->pluck("id")); |
|
54
|
|
|
$this->assertEquals($liveResults->pluck("id"), $cachedResults->pluck("id")); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function testBindingsAreCorrectWithMultipleWhereInClauses() |
|
58
|
|
|
{ |
|
59
|
|
|
$key = sha1("genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:authors:genealabslaravelmodelcachingtestsfixturesauthor-name_in_John-id_in_-name_in_Mike-authors.deleted_at_null"); |
|
60
|
|
|
$tags = [ |
|
61
|
|
|
"genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesauthor", |
|
62
|
|
|
]; |
|
63
|
|
|
$authors = (new Author) |
|
64
|
|
|
->whereIn("name", ["John"]) |
|
65
|
|
|
->whereIn("id", []) |
|
66
|
|
|
->whereIn("name", ["Mike"]) |
|
67
|
|
|
->get(); |
|
68
|
|
|
$cachedResults = $this |
|
69
|
|
|
->cache() |
|
70
|
|
|
->tags($tags) |
|
71
|
|
|
->get($key)['value']; |
|
72
|
|
|
$liveResults = (new UncachedAuthor) |
|
73
|
|
|
->whereIn("name", ["Mike"]) |
|
74
|
|
|
->whereIn("id", []) |
|
75
|
|
|
->whereIn("name", ["John"]) |
|
76
|
|
|
->get(); |
|
77
|
|
|
|
|
78
|
|
|
$this->assertEquals($liveResults->pluck("id"), $authors->pluck("id")); |
|
79
|
|
|
$this->assertEquals($liveResults->pluck("id"), $cachedResults->pluck("id")); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function testWhereInUsesCorrectBindings() |
|
83
|
|
|
{ |
|
84
|
|
|
$key = sha1("genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:authors:genealabslaravelmodelcachingtestsfixturesauthor-id_in_1_2_3_4_5-id_between_1_99999-authors.deleted_at_null"); |
|
85
|
|
|
$tags = ["genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesauthor"]; |
|
86
|
|
|
|
|
87
|
|
|
$authors = (new Author) |
|
88
|
|
|
->whereIn('id', [1,2,3,4,5]) |
|
89
|
|
|
->whereBetween('id', [1, 99999]) |
|
90
|
|
|
->get(); |
|
91
|
|
|
$cachedResults = $this->cache() |
|
92
|
|
|
->tags($tags) |
|
93
|
|
|
->get($key)['value']; |
|
94
|
|
|
$liveResults = (new UncachedAuthor) |
|
95
|
|
|
->whereIn('id', [1,2,3,4,5]) |
|
96
|
|
|
->whereBetween('id', [1, 99999]) |
|
97
|
|
|
->get(); |
|
98
|
|
|
|
|
99
|
|
|
$this->assertEmpty($authors->diffKeys($cachedResults)); |
|
100
|
|
|
$this->assertEmpty($liveResults->diffKeys($cachedResults)); |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|