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 HasManyTest extends IntegrationTestCase |
8
|
|
|
{ |
9
|
|
|
public function testEagerloadedHasMany() |
10
|
|
|
{ |
11
|
|
|
$key = sha1("genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:books:genealabslaravelmodelcachingtestsfixturesbook-books.author_id_inraw_1"); |
12
|
|
|
$tags = [ |
13
|
|
|
"genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesbook", |
14
|
|
|
]; |
15
|
|
|
|
16
|
|
|
$books = (new Author) |
17
|
|
|
->with("books") |
18
|
|
|
->find(1) |
19
|
|
|
->books; |
20
|
|
|
$cachedResults = $this->cache() |
21
|
|
|
->tags($tags) |
22
|
|
|
->get($key)['value']; |
23
|
|
|
$liveResults = (new UncachedAuthor) |
24
|
|
|
->with("books") |
25
|
|
|
->find(1) |
26
|
|
|
->books; |
27
|
|
|
|
28
|
|
|
$this->assertEquals($liveResults->pluck("id"), $books->pluck("id")); |
29
|
|
|
$this->assertEquals($liveResults->pluck("id"), $cachedResults->pluck("id")); |
30
|
|
|
$this->assertNotEmpty($books); |
31
|
|
|
$this->assertNotEmpty($cachedResults); |
32
|
|
|
$this->assertNotEmpty($liveResults); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
View Code Duplication |
public function testLazyloadedHasMany() |
36
|
|
|
{ |
37
|
|
|
$key = sha1("genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:books:genealabslaravelmodelcachingtestsfixturesbook-books.author_id_=_1-books.author_id_notnull"); |
38
|
|
|
$tags = [ |
39
|
|
|
"genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesbook", |
40
|
|
|
]; |
41
|
|
|
|
42
|
|
|
$books = (new Author) |
43
|
|
|
->find(1) |
44
|
|
|
->books; |
45
|
|
|
$cachedResults = $this->cache() |
46
|
|
|
->tags($tags) |
47
|
|
|
->get($key)['value']; |
48
|
|
|
$liveResults = (new UncachedAuthor) |
49
|
|
|
->find(1) |
50
|
|
|
->books; |
51
|
|
|
|
52
|
|
|
$this->assertEquals($liveResults->pluck("id"), $books->pluck("id")); |
53
|
|
|
$this->assertEquals($liveResults->pluck("id"), $cachedResults->pluck("id")); |
54
|
|
|
$this->assertNotEmpty($books); |
55
|
|
|
$this->assertNotEmpty($cachedResults); |
56
|
|
|
$this->assertNotEmpty($liveResults); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|