Completed
Push — master ( 8e987d...ff1c4b )
by Harry
04:10
created

testKeyAndSecretIsPassedToParams()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 12

Duplication

Lines 19
Ratio 100 %

Importance

Changes 0
Metric Value
dl 19
loc 19
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 12
nc 1
nop 0
1
<?php
2
/**
3
 * This file is part of graze/gigya-client
4
 *
5
 * Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license https://github.com/graze/gigya-client/blob/master/LICENSE.md
11
 * @link    https://github.com/graze/gigya-client
12
 */
13
14
namespace Graze\Gigya\Test\Unit\Auth;
15
16
use Graze\Gigya\Auth\HttpsAuthMiddleware;
17
use Graze\Gigya\Test\TestCase;
18
use GuzzleHttp\Handler\MockHandler;
19
use GuzzleHttp\HandlerStack;
20
use GuzzleHttp\Promise\PromiseInterface;
21
use GuzzleHttp\Psr7\Request;
22
use GuzzleHttp\Psr7\Response;
23
use Mockery as m;
24
use Psr\Http\Message\RequestInterface;
25
26
class HttpsAuthMiddlewareTest extends TestCase
27
{
28 View Code Duplication
    public function testKeyAndSecretIsPassedToParams()
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...
29
    {
30
        $handler = new MockHandler([
31
            function (RequestInterface $request) {
32
                $query = $request->getUri()->getQuery();
33
                $this->assertRegExp('/apiKey=key/', $query);
34
                $this->assertRegExp('/secret=secret/', $query);
35
                return new Response(200);
36
            },
37
        ]);
38
39
        $stack = new HandlerStack($handler);
40
        $stack->push(HttpsAuthMiddleware::middleware('key', 'secret'));
41
42
        $comp = $stack->resolve();
43
44
        $promise = $comp(new Request('GET', 'https://example.com'), ['auth' => 'gigya']);
45
        $this->assertInstanceOf(PromiseInterface::class, $promise);
46
    }
47
48 View Code Duplication
    public function testKeySecretAndUserKeyIsPassedToParams()
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...
49
    {
50
        $handler = new MockHandler([
51
            function (RequestInterface $request) {
52
                $query = $request->getUri()->getQuery();
53
                $this->assertRegExp('/apiKey=key/', $query);
54
                $this->assertRegExp('/secret=secret/', $query);
55
                $this->assertRegExp('/userKey=user/', $query);
56
                return new Response(200);
57
            },
58
        ]);
59
60
        $stack = new HandlerStack($handler);
61
        $stack->push(HttpsAuthMiddleware::middleware('key', 'secret', 'user'));
62
63
        $comp = $stack->resolve();
64
65
        $promise = $comp(new Request('GET', 'https://example.com'), ['auth' => 'gigya']);
66
        $this->assertInstanceOf(PromiseInterface::class, $promise);
67
    }
68
69 View Code Duplication
    public function testAccessors()
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...
70
    {
71
        $auth = new HttpsAuthMiddleware(function () {
72
        }, 'key', 'secret', 'user');
73
        static::assertEquals('key', $auth->getApiKey());
74
        static::assertEquals('secret', $auth->getSecret());
75
        static::assertEquals('user', $auth->getUserKey());
76
    }
77
78 View Code Duplication
    public function testSubscriberDoesNotDoAnythingForNonHttpsRequests()
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...
79
    {
80
        $handler = new MockHandler([
81
            function (RequestInterface $request) {
82
                $query = $request->getUri()->getQuery();
83
                $this->assertNotRegExp('/apiKey=/', $query);
84
                $this->assertNotRegExp('/secret=/', $query);
85
                $this->assertNotRegExp('/userKey=/', $query);
86
                return new Response(200);
87
            },
88
        ]);
89
90
        $stack = new HandlerStack($handler);
91
        $stack->push(HttpsAuthMiddleware::middleware('key', 'secret', 'user'));
92
93
        $comp = $stack->resolve();
94
95
        $promise = $comp(new Request('GET', 'http://example.com'), ['auth' => 'gigya']);
96
        $this->assertInstanceOf(PromiseInterface::class, $promise);
97
    }
98
99 View Code Duplication
    public function testSubscriberDoesNotDoAnythingForNonGigyaAuthRequests()
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...
100
    {
101
        $handler = new MockHandler([
102
            function (RequestInterface $request, array $options) {
0 ignored issues
show
Unused Code introduced by
The parameter $options is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
103
                $query = $request->getUri()->getQuery();
104
                $this->assertNotRegExp('/apiKey=/', $query);
105
                $this->assertNotRegExp('/secret=/', $query);
106
                $this->assertNotRegExp('/userKey=/', $query);
107
                return new Response(200);
108
            },
109
        ]);
110
111
        $stack = new HandlerStack($handler);
112
        $stack->push(HttpsAuthMiddleware::middleware('key', 'secret', 'user'));
113
114
        $comp = $stack->resolve();
115
116
        $promise = $comp(new Request('GET', 'http://example.com'), ['auth' => 'oauth']);
117
        $this->assertInstanceOf(PromiseInterface::class, $promise);
118
    }
119
}
120