Completed
Push — master ( 3f89d7...f790e9 )
by Mike
30:28 queued 29:00
created

testAllMethodCacheGetsInvalidated()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
dl 11
loc 11
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 0
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