Completed
Push — master ( 0ebdbd...75c9f6 )
by Mike
14s
created

CaffeineTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 84
Duplicated Lines 36.9 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 6
dl 31
loc 84
rs 10
c 4
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testDisabledCaffeination() 0 17 1
A testMiddlewareInjectsDripScript() 0 7 1
A testExpiredDrip() 16 22 1
A testSuccessfulDrip() 14 14 1
A testDripEndpoint() 0 7 1
A testNonStringReturnContent() 0 5 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\LaravelCaffeine\Tests\Feature;
2
3
use GeneaLabs\LaravelCaffeine\Tests\TestCase;
4
5
class CaffeineTest extends TestCase
6
{
7
    public function testDripEndpoint()
8
    {
9
        $dripRoute = config('genealabs-laravel-caffeine.route', 'genealabs/laravel-caffeine/drip');
10
11
        $response = $this->get($dripRoute);
12
13
        $response->assertStatus(204);
14
    }
15
16
    public function testMiddlewareInjectsDripScript()
17
    {
18
        $expectedResult = file_get_contents(__DIR__ . '/../Fixtures/expired_script.txt');
19
20
        $response = $this->get(route('genealabs-laravel-caffeine.tests.form'));
21
22
        $response->assertSee($expectedResult);
1 ignored issue
show
Bug introduced by
It seems like $expectedResult can also be of type false; however, parameter $value of Illuminate\Foundation\Te...stResponse::assertSee() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

22
        $response->assertSee(/** @scrutinizer ignore-type */ $expectedResult);
Loading history...
23
    }
24
25 View Code Duplication
    public function testSuccessfulDrip()
1 ignored issue
show
Duplication introduced by
This method 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...
26
    {
27
        $dripRoute = config('genealabs-laravel-caffeine.route', 'genealabs/laravel-caffeine/drip');
28
        $html = $this->get(route('genealabs-laravel-caffeine.tests.form'))
29
            ->getContent();
30
        $matches = [];
31
        preg_match('/<meta name="csrf-token" content="(.*?)">/', $html, $matches);
32
        $csrfToken = $matches[1];
33
34
        $response = $this->get($dripRoute, [
35
            '_token' => $csrfToken,
36
        ]);
37
38
        $response->assertStatus(204);
39
    }
40
41 View Code Duplication
    public function testExpiredDrip()
1 ignored issue
show
Duplication introduced by
This method 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...
42
    {
43
        $dripRoute = config(
44
            'genealabs-laravel-caffeine.dripInterval',
45
            'genealabs/laravel-caffeine/drip'
46
        );
47
        $html = $this->get(route('genealabs-laravel-caffeine.tests.form'))
48
            ->getContent();
49
        $matches = [];
50
        preg_match(
51
            '/<meta name="csrf-token" content="(.*?)">/',
52
            $html,
53
            $matches
54
        );
55
        $csrfToken = $matches[1];
56
57
        app('session')->flush();
58
        $response = $this->get($dripRoute, [
59
            '_token' => $csrfToken,
60
        ]);
61
62
        $response->assertStatus(404);
63
    }
64
65
    public function testDisabledCaffeination()
66
    {
67
        $html = $this
68
            ->get(route('genealabs-laravel-caffeine.tests.disabled-page'))
69
            ->getContent();
70
71
        $isDisabled = (bool) preg_match(
72
            '/<meta name="caffeinated" content="false">/',
73
            $html
74
        );
75
        $hasDripper = (bool) preg_match(
76
            '/\bconst caffeineSendDrip\b/',
77
            $html
78
        );
79
80
        $this->assertTrue($isDisabled);
81
        $this->assertFalse($hasDripper);
82
    }
83
84
    public function testNonStringReturnContent()
85
    {
86
        $response = $this->get(route('genealabs-laravel-caffeine.tests.null-response'));
87
88
        $response->assertDontSee('const caffeineSendDrip');
89
    }
90
}
91