Completed
Pull Request — master (#372)
by Mike
31:01 queued 16:07
created

CachePrefixingTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 45
Duplicated Lines 91.11 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testDatabaseKeyingEnabled() 21 21 1
A testDatabaseKeyingDisabled() 20 20 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\Traits;
2
3
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Author;
4
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedAuthor;
5
use GeneaLabs\LaravelModelCaching\Tests\IntegrationTestCase;
6
7
class CachePrefixingTest extends IntegrationTestCase
0 ignored issues
show
Bug introduced by
There is at least one abstract method in this class. Maybe declare it as abstract, or implement the remaining methods: artisan, be, call, seed
Loading history...
8
{
9 View Code Duplication
    public function testDatabaseKeyingEnabled()
10
    {
11
        $key = sha1("genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:authors:genealabslaravelmodelcachingtestsfixturesauthor-authors.deleted_at_null-first");
12
        $tags = [
13
            "genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesauthor",
14
        ];
15
16
        $author = (new Author)
17
            ->first();
18
        $cachedResults = $this->cache()
19
            ->tags($tags)
20
            ->get($key)['value'];
21
        $liveResults = (new UncachedAuthor)
22
            ->first();
23
24
        $this->assertEquals($liveResults->pluck("id"), $author->pluck("id"));
25
        $this->assertEquals($liveResults->pluck("id"), $cachedResults->pluck("id"));
26
        $this->assertNotEmpty($author);
27
        $this->assertNotEmpty($cachedResults);
28
        $this->assertNotEmpty($liveResults);
29
    }
30
31 View Code Duplication
    public function testDatabaseKeyingDisabled()
32
    {
33
        config(["laravel-model-caching.use-database-keying" => false]);
34
        $key = sha1("genealabs:laravel-model-caching:authors:genealabslaravelmodelcachingtestsfixturesauthor-authors.deleted_at_null-first");
35
        $tags = ["genealabs:laravel-model-caching:genealabslaravelmodelcachingtestsfixturesauthor"];
36
37
        $author = (new Author)
38
            ->first();
39
        $cachedResults = $this->cache()
40
            ->tags($tags)
41
            ->get($key)['value'];
42
        $liveResults = (new UncachedAuthor)
43
            ->first();
44
45
        $this->assertEquals($liveResults->pluck("id"), $author->pluck("id"));
46
        $this->assertEquals($liveResults->pluck("id"), $cachedResults->pluck("id"));
47
        $this->assertNotEmpty($author);
48
        $this->assertNotEmpty($cachedResults);
49
        $this->assertNotEmpty($liveResults);
50
    }
51
}
52