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

CacheTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
dl 0
loc 37
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 10 1
A testCacheIsEmptyBeforeLoadingModels() 0 3 1
A testCacheIsNotEmptyAfterLoadingModels() 0 5 1
A testChangingModelClearsCache() 0 7 1
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