AbstractServiceTest   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 163
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 9
eloc 63
dl 0
loc 163
c 2
b 0
f 0
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A testService() 0 9 1
A testDetermineRequestUriFromPathUsingHttpPath() 0 12 1
A testDetermineRequestUriFromPathUsingUriObject() 0 11 1
A testDetermineRequestUriFromPathUsingHttpsPath() 0 12 1
A testConstructCorrectInterface() 0 12 1
A testDetermineRequestUriFromPathWithQueryString() 0 15 1
A testDetermineRequestUriFromPathThrowsExceptionOnInvalidUri() 0 11 1
A testDetermineRequestUriFromPathWithLeadingSlashInPath() 0 15 1
A testGetStorage() 0 12 1
1
<?php
2
3
namespace OAuthTest\Unit\Common\Service;
4
5
use OAuthTest\Mocks\Common\Service\Mock;
6
use PHPUnit\Framework\TestCase;
7
8
class AbstractServiceTest extends TestCase
9
{
10
    /**
11
     * @covers \AbstractService::__construct
12
     */
13
    public function testConstructCorrectInterface(): void
14
    {
15
        $service = $this->getMockForAbstractClass(
16
            '\\OAuth\\Common\\Service\\AbstractService',
17
            [
18
                $this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
19
                $this->createMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
20
                $this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'),
21
            ]
22
        );
23
24
        self::assertInstanceOf('\\OAuth\\Common\\Service\\ServiceInterface', $service);
25
    }
26
27
    /**
28
     * @covers \AbstractService::__construct
29
     * @covers \AbstractService::getStorage
30
     */
31
    public function testGetStorage(): void
32
    {
33
        $service = $this->getMockForAbstractClass(
34
            '\\OAuth\\Common\\Service\\AbstractService',
35
            [
36
                $this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
37
                $this->createMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
38
                $this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'),
39
            ]
40
        );
41
42
        self::assertInstanceOf('\\OAuth\\Common\\Storage\\TokenStorageInterface', $service->getStorage());
43
    }
44
45
    /**
46
     * @covers \AbstractService::__construct
47
     * @covers \AbstractService::service
48
     */
49
    public function testService(): void
50
    {
51
        $service = new Mock(
52
            $this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
53
            $this->createMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
54
            $this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
55
        );
56
57
        self::assertSame('Mock', $service->service());
58
    }
59
60
    /**
61
     * @covers \AbstractService::__construct
62
     * @covers \AbstractService::determineRequestUriFromPath
63
     */
64
    public function testDetermineRequestUriFromPathUsingUriObject(): void
65
    {
66
        $service = new Mock(
67
            $this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
68
            $this->createMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
69
            $this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
70
        );
71
72
        self::assertInstanceOf(
73
            '\\OAuth\\Common\\Http\\Uri\\UriInterface',
74
            $service->testDetermineRequestUriFromPath($this->createMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'))
75
        );
76
    }
77
78
    /**
79
     * @covers \AbstractService::__construct
80
     * @covers \AbstractService::determineRequestUriFromPath
81
     */
82
    public function testDetermineRequestUriFromPathUsingHttpPath(): void
83
    {
84
        $service = new Mock(
85
            $this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
86
            $this->createMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
87
            $this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
88
        );
89
90
        $uri = $service->testDetermineRequestUriFromPath('http://example.com');
91
92
        self::assertInstanceOf('\\OAuth\\Common\\Http\\Uri\\UriInterface', $uri);
93
        self::assertSame('http://example.com', $uri->getAbsoluteUri());
94
    }
95
96
    /**
97
     * @covers \AbstractService::__construct
98
     * @covers \AbstractService::determineRequestUriFromPath
99
     */
100
    public function testDetermineRequestUriFromPathUsingHttpsPath(): void
101
    {
102
        $service = new Mock(
103
            $this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
104
            $this->createMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
105
            $this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
106
        );
107
108
        $uri = $service->testDetermineRequestUriFromPath('https://example.com');
109
110
        self::assertInstanceOf('\\OAuth\\Common\\Http\\Uri\\UriInterface', $uri);
111
        self::assertSame('https://example.com', $uri->getAbsoluteUri());
112
    }
113
114
    /**
115
     * @covers \AbstractService::__construct
116
     * @covers \AbstractService::determineRequestUriFromPath
117
     */
118
    public function testDetermineRequestUriFromPathThrowsExceptionOnInvalidUri(): void
119
    {
120
        $this->expectException('\\OAuth\\Common\\Exception\\Exception');
121
122
        $service = new Mock(
123
            $this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
124
            $this->createMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
125
            $this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
126
        );
127
128
        $uri = $service->testDetermineRequestUriFromPath('example.com');
0 ignored issues
show
Unused Code introduced by
The assignment to $uri is dead and can be removed.
Loading history...
129
    }
130
131
    /**
132
     * @covers \AbstractService::__construct
133
     * @covers \AbstractService::determineRequestUriFromPath
134
     */
135
    public function testDetermineRequestUriFromPathWithQueryString(): void
136
    {
137
        $service = new Mock(
138
            $this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
139
            $this->createMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
140
            $this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
141
        );
142
143
        $uri = $service->testDetermineRequestUriFromPath(
144
            'path?param1=value1',
145
            new \OAuth\Common\Http\Uri\Uri('https://example.com')
146
        );
147
148
        self::assertInstanceOf('\\OAuth\\Common\\Http\\Uri\\UriInterface', $uri);
149
        self::assertSame('https://example.com/path?param1=value1', $uri->getAbsoluteUri());
150
    }
151
152
    /**
153
     * @covers \AbstractService::__construct
154
     * @covers \AbstractService::determineRequestUriFromPath
155
     */
156
    public function testDetermineRequestUriFromPathWithLeadingSlashInPath(): void
157
    {
158
        $service = new Mock(
159
            $this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
160
            $this->createMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
161
            $this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
162
        );
163
164
        $uri = $service->testDetermineRequestUriFromPath(
165
            '/path',
166
            new \OAuth\Common\Http\Uri\Uri('https://example.com')
167
        );
168
169
        self::assertInstanceOf('\\OAuth\\Common\\Http\\Uri\\UriInterface', $uri);
170
        self::assertSame('https://example.com/path', $uri->getAbsoluteUri());
171
    }
172
}
173