Completed
Pull Request — master (#20)
by Harry
03:45 queued 17s
created

testKeySecretAndUserKeyIsPassedToParams()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 22

Duplication

Lines 28
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 28
loc 28
rs 8.8571
cc 1
eloc 22
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\CredentialsAuth;
17
use Graze\Gigya\Auth\GigyaAuthInterface;
18
use Graze\Gigya\Test\TestCase;
19
use GuzzleHttp\Collection;
20
use GuzzleHttp\Event\BeforeEvent;
21
use GuzzleHttp\Event\RequestEvents;
22
use GuzzleHttp\Event\SubscriberInterface;
23
use GuzzleHttp\Message\RequestInterface;
24
use GuzzleHttp\Query;
25
use Mockery as m;
26
27
class CredentialsAuthTest extends TestCase
28
{
29
    public function testInstanceOf()
30
    {
31
        $auth = new CredentialsAuth('key', 'client_secret');
32
        static::assertInstanceOf(SubscriberInterface::class, $auth);
33
    }
34
35 View Code Duplication
    public function testGetEventsHandlesBeforeAndSignsRequest()
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...
36
    {
37
        $auth = new CredentialsAuth('key', 'client_secret');
38
        static::assertEquals(
39
            ['before' => ['sign', RequestEvents::SIGN_REQUEST]],
40
            $auth->getEvents()
41
        );
42
    }
43
44 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...
45
    {
46
        $request = m::mock(RequestInterface::class);
47
        $event = m::mock(BeforeEvent::class);
48
        $event->shouldReceive('getRequest')
49
              ->andReturn($request);
50
51
        $query = m::mock(Query::class);
52
        $config = m::mock(Collection::class);
53
54
        $request->shouldReceive('getScheme')
55
                ->andReturn('https');
56
        $request->shouldReceive('getConfig')
57
                ->andReturn($config);
58
        $request->shouldReceive('getQuery')
59
                ->andReturn($query);
60
61
        $query->shouldReceive('offsetSet')
62
              ->with('client_id', 'key');
63
        $query->shouldReceive('offsetSet')
64
              ->with('client_secret', 'client_secret');
65
        $config->shouldReceive('get')
66
               ->with('auth')
67
               ->andReturn('credentials');
68
69
        $auth = new CredentialsAuth('key', 'client_secret');
70
        $auth->sign($event);
71
    }
72
73 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...
74
    {
75
        $request = m::mock(RequestInterface::class);
76
        $event = m::mock(BeforeEvent::class);
77
        $event->shouldReceive('getRequest')
78
              ->andReturn($request);
79
80
        $query = m::mock(Query::class);
81
        $config = m::mock(Collection::class);
82
83
        $request->shouldReceive('getScheme')
84
                ->andReturn('https');
85
        $request->shouldReceive('getConfig')
86
                ->andReturn($config);
87
        $request->shouldReceive('getQuery')
88
                ->andReturn($query);
89
90
        $query->shouldReceive('offsetSet')
91
              ->with('client_id', 'user');
92
        $query->shouldReceive('offsetSet')
93
              ->with('client_secret', 'client_secret');
94
        $config->shouldReceive('get')
95
               ->with('auth')
96
               ->andReturn('credentials');
97
98
        $auth = new CredentialsAuth('key', 'client_secret', 'user');
99
        $auth->sign($event);
100
    }
101
102 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...
103
    {
104
        $auth = new CredentialsAuth('key', 'client_secret', 'user');
105
        static::assertEquals('key', $auth->getApiKey());
106
        static::assertEquals('client_secret', $auth->getSecret());
107
        static::assertEquals('user', $auth->getUserKey());
108
    }
109
110 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...
111
    {
112
        $request = m::mock(RequestInterface::class);
113
        $event = m::mock(BeforeEvent::class);
114
        $event->shouldReceive('getRequest')
115
              ->andReturn($request);
116
117
        $request->shouldReceive('getScheme')
118
                ->andReturn('http');
119
120
        $auth = new CredentialsAuth('key', 'client_secret', 'user');
121
        $auth->sign($event);
122
    }
123
124 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...
125
    {
126
        $request = m::mock(RequestInterface::class);
127
        $event = m::mock(BeforeEvent::class);
128
        $event->shouldReceive('getRequest')
129
              ->andReturn($request);
130
131
        $config = m::mock(Collection::class);
132
        $request->shouldReceive('getScheme')
133
                ->andReturn('https');
134
        $request->shouldReceive('getConfig')
135
                ->andReturn($config);
136
137
        $config->shouldReceive('get')
138
               ->with('auth')
139
               ->andReturn('oauth');
140
141
        $auth = new CredentialsAuth('key', 'client_secret', 'user');
142
        $auth->sign($event);
143
    }
144
}
145