Passed
Push — master ( ab8c84...f0f114 )
by Mike
02:39
created

CacheTest::testChangingModelClearsCache()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php namespace GeneaLabs\LaravelModelCaching\Tests\Unit;
2
3
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Author;
4
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Book;
5
use GeneaLabs\LaravelModelCaching\Tests\TestCase;
6
use Illuminate\Foundation\Testing\RefreshDatabase;
7
8
class CacheTest extends TestCase
9
{
10
    use RefreshDatabase;
11
12
    public function setUp()
13
    {
14
        parent::setUp();
15
16
        factory(Author::class, 10)->create()
17
            ->each(function($author) {
18
                factory(Book::class, random_int(2, 10))->make()
19
                    ->each(function ($book) use ($author) {
20
                        $book->author()->associate($author);
21
                        $book->save();
22
                    });
23
            });
24
    }
25
26
    public function testCacheIsEmptyBeforeLoadingModels()
27
    {
28
        $this->assertNull(cache()->get('genealabslaravelmodelcachingtestsfixturesauthor_1_2_3_4_5_6_7_8_9_10-genealabslaravelmodelcachingtestsfixturesbooks'));
29
    }
30
31
    public function testCacheIsNotEmptyAfterLoadingModels()
32
    {
33
        (new Author)->with('books')->get();
34
35
        $this->assertNotNull(cache()->get('genealabslaravelmodelcachingtestsfixturesauthor_1_2_3_4_5_6_7_8_9_10-genealabslaravelmodelcachingtestsfixturesbooks'));
36
    }
37
38
    public function testChangingModelClearsCache()
39
    {
40
        $author = (new Author)->with('books')->first();
41
        $author->name = "John Jinglheimer";
42
        $author->save();
43
44
        $this->assertNull(cache()->get('genealabslaravelmodelcachingtestsfixturesauthor_1_2_3_4_5_6_7_8_9_10-genealabslaravelmodelcachingtestsfixturesbooks'));
45
    }
46
}
47