|
1
|
|
|
<?php namespace GeneaLabs\LaravelModelCaching\Tests\Integration\Traits; |
|
2
|
|
|
|
|
3
|
|
|
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Author; |
|
4
|
|
|
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedAuthor; |
|
5
|
|
|
use GeneaLabs\LaravelModelCaching\Tests\IntegrationTestCase; |
|
6
|
|
|
|
|
7
|
|
|
class CachePrefixingTest extends IntegrationTestCase |
|
|
|
|
|
|
8
|
|
|
{ |
|
9
|
|
View Code Duplication |
public function testDatabaseKeyingEnabled() |
|
10
|
|
|
{ |
|
11
|
|
|
$key = sha1("genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:authors:genealabslaravelmodelcachingtestsfixturesauthor-authors.deleted_at_null-first"); |
|
12
|
|
|
$tags = [ |
|
13
|
|
|
"genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesauthor", |
|
14
|
|
|
]; |
|
15
|
|
|
|
|
16
|
|
|
$author = (new Author) |
|
17
|
|
|
->first(); |
|
18
|
|
|
$cachedResults = $this->cache() |
|
19
|
|
|
->tags($tags) |
|
20
|
|
|
->get($key)['value']; |
|
21
|
|
|
$liveResults = (new UncachedAuthor) |
|
22
|
|
|
->first(); |
|
23
|
|
|
|
|
24
|
|
|
$this->assertEquals($liveResults->pluck("id"), $author->pluck("id")); |
|
25
|
|
|
$this->assertEquals($liveResults->pluck("id"), $cachedResults->pluck("id")); |
|
26
|
|
|
$this->assertNotEmpty($author); |
|
27
|
|
|
$this->assertNotEmpty($cachedResults); |
|
28
|
|
|
$this->assertNotEmpty($liveResults); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
View Code Duplication |
public function testDatabaseKeyingDisabled() |
|
32
|
|
|
{ |
|
33
|
|
|
config(["laravel-model-caching.use-database-keying" => false]); |
|
34
|
|
|
$key = sha1("genealabs:laravel-model-caching:authors:genealabslaravelmodelcachingtestsfixturesauthor-authors.deleted_at_null-first"); |
|
35
|
|
|
$tags = ["genealabs:laravel-model-caching:genealabslaravelmodelcachingtestsfixturesauthor"]; |
|
36
|
|
|
|
|
37
|
|
|
$author = (new Author) |
|
38
|
|
|
->first(); |
|
39
|
|
|
$cachedResults = $this->cache() |
|
40
|
|
|
->tags($tags) |
|
41
|
|
|
->get($key)['value']; |
|
42
|
|
|
$liveResults = (new UncachedAuthor) |
|
43
|
|
|
->first(); |
|
44
|
|
|
|
|
45
|
|
|
$this->assertEquals($liveResults->pluck("id"), $author->pluck("id")); |
|
46
|
|
|
$this->assertEquals($liveResults->pluck("id"), $cachedResults->pluck("id")); |
|
47
|
|
|
$this->assertNotEmpty($author); |
|
48
|
|
|
$this->assertNotEmpty($cachedResults); |
|
49
|
|
|
$this->assertNotEmpty($liveResults); |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|