Completed
Push — master ( 3411ce...0ebdbd )
by Mike
13s
created

CaffeineTest::testSuccessfulDrip()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 14
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 14
loc 14
rs 9.4285
cc 1
eloc 9
nc 1
nop 0
1
<?php namespace GeneaLabs\LaravelCaffeine\Tests\Feature;
2
3
use GeneaLabs\LaravelCaffeine\Tests\TestCase;
4
5
class CaffeineTest extends TestCase
6
{
7
    public function testBootstrap3TestPageCanLoad()
8
    {
9
        $dripRoute = config('genealabs-laravel-caffeine.route', 'genealabs/laravel-caffeine/drip');
10
        $response = $this->get($dripRoute);
11
12
        $response->assertStatus(204);
13
    }
14
15
    public function testMiddlewareInjectsDripScript()
16
    {
17
        $expectedResult = file_get_contents(__DIR__ . '/../Fixtures/expired_script.txt');
18
19
        $response = $this->get(route('genealabs-laravel-caffeine.tests.form'));
20
21
        $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

21
        $response->assertSee(/** @scrutinizer ignore-type */ $expectedResult);
Loading history...
22
    }
23
24 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...
25
    {
26
        $dripRoute = config('genealabs-laravel-caffeine.route', 'genealabs/laravel-caffeine/drip');
27
        $html = $this->get(route('genealabs-laravel-caffeine.tests.form'))
28
            ->getContent();
29
        $matches = [];
30
        preg_match('/<meta name="csrf-token" content="(.*?)">/', $html, $matches);
31
        $csrfToken = $matches[1];
32
33
        $response = $this->get($dripRoute, [
34
            '_token' => $csrfToken,
35
        ]);
36
37
        $response->assertStatus(204);
38
    }
39
40 View Code Duplication
    public function testExpiredDrip()
0 ignored issues
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...
41
    {
42
        $dripRoute = config('genealabs-laravel-caffeine.dripInterval', 'genealabs/laravel-caffeine/drip');
43
        $html = $this->get(route('genealabs-laravel-caffeine.tests.form'))
44
            ->getContent();
45
        $matches = [];
46
        preg_match('/<meta name="csrf-token" content="(.*?)">/', $html, $matches);
47
        $csrfToken = $matches[1];
48
49
        app('session')->flush();
50
        $response = $this->get($dripRoute, [
51
            '_token' => $csrfToken,
52
        ]);
53
54
        $response->assertStatus(404);
55
    }
56
}
57