itAddsAHeaderWhenAuthenticationHeaderIsNotSet()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 7

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
dl 13
loc 13
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
namespace Bunq\Tests\Middleware;
4
5
use Bunq\Middleware\RequestAuthenticationMiddleware;
6
use Bunq\Token\DefaultToken;
7
use Bunq\Token\Token;
8
use GuzzleHttp\Psr7\Request;
9
use PHPUnit\Framework\TestCase;
10
11
final class RequestAuthenticationMiddlewareTest extends TestCase
12
{
13
    /**
14
     * @var Token
15
     */
16
    private $sessionToken;
17
18
    /**
19
     * @var RequestAuthenticationMiddleware
20
     */
21
    private $middleware;
22
23
    public function setUp()
24
    {
25
        $this->sessionToken = DefaultToken::fromString('session-token');
26
        $this->middleware   = new RequestAuthenticationMiddleware($this->sessionToken);
27
    }
28
29
    /**
30
     * @test
31
     */
32 View Code Duplication
    public function itAddsAHeaderWhenAuthenticationHeaderIsNotSet()
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...
33
    {
34
        $request = new Request('GET', 'uri', []);
35
36
        $request = $this->middleware->__invoke($request);
37
38
        $headers         = [
39
            'X-Bunq-Client-Authentication' => 'session-token',
40
        ];
41
        $expectedRequest = new Request('GET', 'uri', $headers, $request->getBody());
42
43
        $this->assertEquals($expectedRequest, $request);
44
    }
45
46
    /**
47
     * @test
48
     */
49 View Code Duplication
    public function itDoesNotAddAHeaderWhenAuthenticationHeaderIsAlreadySet()
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...
50
    {
51
        $request = new Request(
52
            'GET',
53
                'uri',
54
                [
55
                    'X-Bunq-Client-Authentication' => 'own-session-token',
56
                ]
57
        );
58
59
        $request = $this->middleware->__invoke($request);
60
61
        $headers         = [
62
            'X-Bunq-Client-Authentication' => 'own-session-token',
63
        ];
64
        $expectedRequest = new Request('GET', 'uri', $headers, $request->getBody());
65
66
        $this->assertEquals($expectedRequest, $request);
67
    }
68
}
69
70