|
1
|
|
|
<?php namespace GeneaLabs\LaravelModelCaching\Tests\Integration\CachedBuilder; |
|
2
|
|
|
|
|
3
|
|
|
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Author; |
|
4
|
|
|
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedAuthor; |
|
5
|
|
|
use GeneaLabs\LaravelModelCaching\Tests\IntegrationTestCase; |
|
6
|
|
|
|
|
7
|
|
|
class GetTest extends IntegrationTestCase |
|
|
|
|
|
|
8
|
|
|
{ |
|
9
|
|
|
public function testGetModelResultsCreatesCache() |
|
10
|
|
|
{ |
|
11
|
|
|
$authors = (new Author) |
|
12
|
|
|
->with('books', 'profile') |
|
13
|
|
|
->get(); |
|
14
|
|
|
$key = sha1("genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:authors:genealabslaravelmodelcachingtestsfixturesauthor-authors.deleted_at_null-testing:{$this->testingSqlitePath}testing.sqlite:books-testing:{$this->testingSqlitePath}testing.sqlite:profile"); |
|
15
|
|
|
$tags = [ |
|
16
|
|
|
"genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesauthor", |
|
17
|
|
|
"genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesbook", |
|
18
|
|
|
"genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesprofile", |
|
19
|
|
|
]; |
|
20
|
|
|
|
|
21
|
|
|
$cachedResults = $this |
|
22
|
|
|
->cache() |
|
23
|
|
|
->tags($tags) |
|
24
|
|
|
->get($key)['value']; |
|
25
|
|
|
$liveResults = (new UncachedAuthor) |
|
26
|
|
|
->with('books', 'profile') |
|
27
|
|
|
->get(); |
|
28
|
|
|
|
|
29
|
|
|
$this->assertEquals($authors, $cachedResults); |
|
30
|
|
|
$this->assertEmpty($liveResults->diffKeys($cachedResults)); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function testAccessingGetResultsViaArrayIndexDoesNotError() |
|
34
|
|
|
{ |
|
35
|
|
|
$author = (new Author) |
|
36
|
|
|
->where('id', 1) |
|
37
|
|
|
->get()[0]; |
|
38
|
|
|
$cachedAuthor = (new Author) |
|
39
|
|
|
->where('id', 1) |
|
40
|
|
|
->get()[0]; |
|
41
|
|
|
$uncachedAuthor = (new UncachedAuthor) |
|
42
|
|
|
->where('id', 1) |
|
43
|
|
|
->get()[0]; |
|
44
|
|
|
|
|
45
|
|
|
$this->assertEquals(1, $author->id); |
|
46
|
|
|
$this->assertEquals($author, $cachedAuthor); |
|
47
|
|
|
$this->assertEquals($author->toArray(), $uncachedAuthor->toArray()); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
View Code Duplication |
public function testGetWithFieldArrayCachesResults() |
|
51
|
|
|
{ |
|
52
|
|
|
$key = sha1("genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:authors:genealabslaravelmodelcachingtestsfixturesauthor_id_name-authors.deleted_at_null"); |
|
53
|
|
|
$tags = [ |
|
54
|
|
|
"genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesauthor", |
|
55
|
|
|
]; |
|
56
|
|
|
|
|
57
|
|
|
$authors = (new Author) |
|
58
|
|
|
->get(["id", "name"]); |
|
59
|
|
|
$cachedResults = $this |
|
60
|
|
|
->cache() |
|
61
|
|
|
->tags($tags) |
|
62
|
|
|
->get($key)['value']; |
|
63
|
|
|
$liveResults = (new UncachedAuthor) |
|
64
|
|
|
->get(["id", "name"]); |
|
65
|
|
|
|
|
66
|
|
|
$this->assertEquals($liveResults->pluck("id"), $authors->pluck("id")); |
|
67
|
|
|
$this->assertEquals($liveResults->pluck("id"), $cachedResults->pluck("id")); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function testGetWithFieldStringCachesResults() |
|
71
|
|
|
{ |
|
72
|
|
|
$key = sha1("genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:authors:genealabslaravelmodelcachingtestsfixturesauthor_id-authors.deleted_at_null"); |
|
73
|
|
|
$tags = [ |
|
74
|
|
|
"genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesauthor", |
|
75
|
|
|
]; |
|
76
|
|
|
|
|
77
|
|
|
$authors = (new Author) |
|
78
|
|
|
->get("id"); |
|
79
|
|
|
$cachedResults = $this |
|
80
|
|
|
->cache() |
|
81
|
|
|
->tags($tags) |
|
82
|
|
|
->get($key)['value']; |
|
83
|
|
|
$liveResults = (new UncachedAuthor) |
|
84
|
|
|
->get("id"); |
|
85
|
|
|
|
|
86
|
|
|
$this->assertEquals($liveResults->pluck("id"), $authors->pluck("id")); |
|
87
|
|
|
$this->assertEquals($liveResults->pluck("id"), $cachedResults->pluck("id")); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|