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

HasManyTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 52
Duplicated Lines 44.23 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 23
loc 52
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testEagerloadedHasMany() 0 25 1
A testLazyloadedHasMany() 23 23 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php namespace GeneaLabs\LaravelModelCaching\Tests\Integration\CachedBuilder;
2
3
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Author;
4
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedAuthor;
5
use GeneaLabs\LaravelModelCaching\Tests\IntegrationTestCase;
6
7
class HasManyTest extends IntegrationTestCase
8
{
9
    public function testEagerloadedHasMany()
10
    {
11
        $key = sha1("genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:books:genealabslaravelmodelcachingtestsfixturesbook-books.author_id_inraw_1");
12
        $tags = [
13
            "genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesbook",
14
        ];
15
16
        $books = (new Author)
17
            ->with("books")
18
            ->find(1)
19
            ->books;
20
        $cachedResults = $this->cache()
21
            ->tags($tags)
22
            ->get($key)['value'];
23
        $liveResults = (new UncachedAuthor)
24
            ->with("books")
25
            ->find(1)
26
            ->books;
27
28
        $this->assertEquals($liveResults->pluck("id"), $books->pluck("id"));
29
        $this->assertEquals($liveResults->pluck("id"), $cachedResults->pluck("id"));
30
        $this->assertNotEmpty($books);
31
        $this->assertNotEmpty($cachedResults);
32
        $this->assertNotEmpty($liveResults);
33
    }
34
35 View Code Duplication
    public function testLazyloadedHasMany()
36
    {
37
        $key = sha1("genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:books:genealabslaravelmodelcachingtestsfixturesbook-books.author_id_=_1-books.author_id_notnull");
38
        $tags = [
39
            "genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesbook",
40
        ];
41
42
        $books = (new Author)
43
            ->find(1)
44
            ->books;
45
        $cachedResults = $this->cache()
46
            ->tags($tags)
47
            ->get($key)['value'];
48
        $liveResults = (new UncachedAuthor)
49
            ->find(1)
50
            ->books;
51
52
        $this->assertEquals($liveResults->pluck("id"), $books->pluck("id"));
53
        $this->assertEquals($liveResults->pluck("id"), $cachedResults->pluck("id"));
54
        $this->assertNotEmpty($books);
55
        $this->assertNotEmpty($cachedResults);
56
        $this->assertNotEmpty($liveResults);
57
    }
58
}
59