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

HasManyThroughTest::testLazyloadedHasManyThrough()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 27

Duplication

Lines 27
Ratio 100 %

Importance

Changes 0
Metric Value
dl 27
loc 27
rs 9.488
c 0
b 0
f 0
cc 1
nc 1
nop 0
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 View Code Duplication
class HasManyThroughTest 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...
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
8
{
9
    public function testEagerloadedHasManyThrough()
10
    {
11
        $key = sha1("genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:authors:genealabslaravelmodelcachingtestsfixturesauthor-authors.deleted_at_null-testing:{$this->testingSqlitePath}testing.sqlite:printers-first");
12
        $tags = [
13
            "genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesauthor",
14
            "genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesprinter",
15
        ];
16
17
        $printers = (new Author)
18
            ->with("printers")
19
            ->first()
20
            ->printers;
21
        $cachedResults = $this->cache()
22
            ->tags($tags)
23
            ->get($key)['value']
24
            ->first()
25
            ->printers;
26
        $liveResults = (new UncachedAuthor)
27
            ->with("printers")
28
            ->first()
29
            ->printers;
30
31
        $this->assertEquals($liveResults->pluck("id")->toArray(), $printers->pluck("id")->toArray());
32
        $this->assertEquals($liveResults->pluck("id")->toArray(), $cachedResults->pluck("id")->toArray());
33
        $this->assertNotEmpty($printers);
34
        $this->assertNotEmpty($cachedResults);
35
        $this->assertNotEmpty($liveResults);
36
    }
37
38
    public function testLazyloadedHasManyThrough()
39
    {
40
        $key = sha1("genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:authors:genealabslaravelmodelcachingtestsfixturesauthor-authors.deleted_at_null-authors.id_=_1-testing:{$this->testingSqlitePath}testing.sqlite:printers-limit_1");
0 ignored issues
show
Unused Code introduced by
$key is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
41
        $tags = [
0 ignored issues
show
Unused Code introduced by
$tags is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
42
            "genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesauthor",
43
            "genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesprinter",
44
        ];
45
46
        // $printers = (new Author)
47
        //     ->find(1)
48
        //     ->printers;
49
        // $cachedResults = $this->cache()
50
        //     ->tags($tags)
51
        //     ->get($key)['value']
52
        //     ->first()
53
        //     ->printers;
54
        // $liveResults = (new UncachedAuthor)
55
        //     ->find(1)
56
        //     ->printers;
57
58
        // $this->assertEquals($liveResults->pluck("id")->toArray(), $printers->pluck("id")->toArray());
59
        // $this->assertEquals($liveResults->pluck("id")->toArray(), $cachedResults->pluck("id")->toArray());
60
        // $this->assertNotEmpty($printers);
61
        // $this->assertNotEmpty($cachedResults);
62
        // $this->assertNotEmpty($liveResults);
63
        $this->markTestSkipped();
64
    }
65
}
66