1
|
|
|
<?php namespace GeneaLabs\LaravelModelCaching\Tests\Integration; |
2
|
|
|
|
3
|
|
|
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Author; |
4
|
|
|
use GeneaLabs\LaravelModelCaching\Tests\IntegrationTestCase; |
5
|
|
|
use Illuminate\Support\Collection; |
6
|
|
|
|
7
|
|
|
class CachedBuilderMultipleQueryTest extends IntegrationTestCase |
8
|
|
|
{ |
9
|
|
View Code Duplication |
public function testCallingAllThenFirstQueriesReturnsDifferingResults() |
10
|
|
|
{ |
11
|
|
|
$allAuthors = (new Author)->all(); |
12
|
|
|
$firstAuthor = (new Author)->first(); |
13
|
|
|
|
14
|
|
|
$this->assertNotEquals($allAuthors, $firstAuthor); |
15
|
|
|
$this->assertInstanceOf(Author::class, $firstAuthor); |
16
|
|
|
$this->assertInstanceOf(Collection::class, $allAuthors); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
View Code Duplication |
public function testCallingGetThenFirstQueriesReturnsDifferingResults() |
20
|
|
|
{ |
21
|
|
|
$allAuthors = (new Author)->get(); |
22
|
|
|
$firstAuthor = (new Author)->first(); |
23
|
|
|
|
24
|
|
|
$this->assertNotEquals($allAuthors, $firstAuthor); |
25
|
|
|
$this->assertInstanceOf(Author::class, $firstAuthor); |
26
|
|
|
$this->assertInstanceOf(Collection::class, $allAuthors); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
View Code Duplication |
public function testUsingDestroyInvalidatesCache() |
30
|
|
|
{ |
31
|
|
|
$allAuthors = (new Author)->get(); |
32
|
|
|
$firstAuthor = $allAuthors->first(); |
33
|
|
|
(new Author)->destroy($firstAuthor->id); |
34
|
|
|
$updatedAuthors = (new Author)->get()->keyBy("id"); |
35
|
|
|
|
36
|
|
|
$this->assertNotEquals($allAuthors, $updatedAuthors); |
37
|
|
|
$this->assertTrue($allAuthors->contains($firstAuthor)); |
38
|
|
|
$this->assertFalse($updatedAuthors->contains($firstAuthor)); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
View Code Duplication |
public function testAllMethodCacheGetsInvalidated() |
42
|
|
|
{ |
43
|
|
|
$allAuthors = (new Author)->all(); |
44
|
|
|
$firstAuthor = $allAuthors->first(); |
45
|
|
|
$firstAuthor->delete(); |
46
|
|
|
$updatedAuthors = (new Author)->all(); |
47
|
|
|
|
48
|
|
|
$this->assertNotEquals($allAuthors, $updatedAuthors); |
49
|
|
|
$this->assertTrue($allAuthors->contains($firstAuthor)); |
50
|
|
|
$this->assertFalse($updatedAuthors->contains($firstAuthor)); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|