Completed
Pull Request — master (#483)
by
unknown
03:10
created

AbstractServiceTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 165
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 4
dl 0
loc 165
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A testConstructCorrectInterface() 0 13 1
A testGetStorage() 0 13 1
A testService() 0 10 1
A testDetermineRequestUriFromPathUsingUriObject() 0 13 1
A testDetermineRequestUriFromPathUsingHttpPath() 0 13 1
A testDetermineRequestUriFromPathUsingHttpsPath() 0 13 1
A testDetermineRequestUriFromPathThrowsExceptionOnInvalidUri() 0 12 1
A testDetermineRequestUriFromPathWithQueryString() 0 16 1
A testDetermineRequestUriFromPathWithLeadingSlashInPath() 0 16 1
1
<?php
2
3
namespace OAuthTest\Unit\Common\Service;
4
5
use OAuthTest\Mocks\Common\Service\Mock;
6
7
class AbstractServiceTest extends \PHPUnit_Framework_TestCase
8
{
9
    /**
10
     * @covers OAuth\Common\Service\AbstractService::__construct
11
     */
12
    public function testConstructCorrectInterface()
13
    {
14
        $service = $this->getMockForAbstractClass(
15
            '\\OAuth\\Common\\Service\\AbstractService',
16
            array(
17
                $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
18
                $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
19
                $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
20
            )
21
        );
22
23
        $this->assertInstanceOf('\\OAuth\\Common\\Service\\ServiceInterface', $service);
24
    }
25
26
    /**
27
     * @covers OAuth\Common\Service\AbstractService::__construct
28
     * @covers OAuth\Common\Service\AbstractService::getStorage
29
     */
30
    public function testGetStorage()
31
    {
32
        $service = $this->getMockForAbstractClass(
33
            '\\OAuth\\Common\\Service\\AbstractService',
34
            array(
35
                $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
36
                $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
37
                $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
38
            )
39
        );
40
41
        $this->assertInstanceOf('\\OAuth\\Common\\Storage\\TokenStorageInterface', $service->getStorage());
42
    }
43
44
    /**
45
     * @covers OAuth\Common\Service\AbstractService::__construct
46
     * @covers OAuth\Common\Service\AbstractService::service
47
     */
48
    public function testService()
49
    {
50
        $service = new Mock(
51
            $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
52
            $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
53
            $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
54
        );
55
56
        $this->assertSame('Mock', $service->service());
57
    }
58
59
    /**
60
     * @covers OAuth\Common\Service\AbstractService::__construct
61
     * @covers OAuth\Common\Service\AbstractService::determineRequestUriFromPath
62
     */
63
    public function testDetermineRequestUriFromPathUsingUriObject()
64
    {
65
        $service = new Mock(
66
            $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
67
            $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
68
            $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
69
        );
70
71
        $this->assertInstanceOf(
72
            '\\OAuth\\Common\\Http\\Uri\\UriInterface',
73
            $service->testDetermineRequestUriFromPath($this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'))
74
        );
75
    }
76
77
    /**
78
     * @covers OAuth\Common\Service\AbstractService::__construct
79
     * @covers OAuth\Common\Service\AbstractService::determineRequestUriFromPath
80
     */
81
    public function testDetermineRequestUriFromPathUsingHttpPath()
82
    {
83
        $service = new Mock(
84
            $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
85
            $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
86
            $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
87
        );
88
89
        $uri = $service->testDetermineRequestUriFromPath('http://example.com');
90
91
        $this->assertInstanceOf('\\OAuth\\Common\\Http\\Uri\\UriInterface', $uri);
92
        $this->assertSame('http://example.com', $uri->getAbsoluteUri());
93
    }
94
95
    /**
96
     * @covers OAuth\Common\Service\AbstractService::__construct
97
     * @covers OAuth\Common\Service\AbstractService::determineRequestUriFromPath
98
     */
99
    public function testDetermineRequestUriFromPathUsingHttpsPath()
100
    {
101
        $service = new Mock(
102
            $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
103
            $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
104
            $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
105
        );
106
107
        $uri = $service->testDetermineRequestUriFromPath('https://example.com');
108
109
        $this->assertInstanceOf('\\OAuth\\Common\\Http\\Uri\\UriInterface', $uri);
110
        $this->assertSame('https://example.com', $uri->getAbsoluteUri());
111
    }
112
113
    /**
114
     * @covers OAuth\Common\Service\AbstractService::__construct
115
     * @covers OAuth\Common\Service\AbstractService::determineRequestUriFromPath
116
     */
117
    public function testDetermineRequestUriFromPathThrowsExceptionOnInvalidUri()
118
    {
119
        $this->setExpectedException('\\OAuth\\Common\\Exception\\Exception');
120
121
        $service = new Mock(
122
            $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
123
            $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
124
            $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
125
        );
126
127
        $uri = $service->testDetermineRequestUriFromPath('example.com');
0 ignored issues
show
Unused Code introduced by
$uri is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
128
    }
129
130
    /**
131
     * @covers OAuth\Common\Service\AbstractService::__construct
132
     * @covers OAuth\Common\Service\AbstractService::determineRequestUriFromPath
133
     */
134
    public function testDetermineRequestUriFromPathWithQueryString()
135
    {
136
        $service = new Mock(
137
            $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
138
            $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
139
            $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
140
        );
141
142
        $uri = $service->testDetermineRequestUriFromPath(
143
            'path?param1=value1',
144
            new \OAuth\Common\Http\Uri\Uri('https://example.com')
145
        );
146
147
        $this->assertInstanceOf('\\OAuth\\Common\\Http\\Uri\\UriInterface', $uri);
148
        $this->assertSame('https://example.com/path?param1=value1', $uri->getAbsoluteUri());
149
    }
150
151
    /**
152
     * @covers OAuth\Common\Service\AbstractService::__construct
153
     * @covers OAuth\Common\Service\AbstractService::determineRequestUriFromPath
154
     */
155
    public function testDetermineRequestUriFromPathWithLeadingSlashInPath()
156
    {
157
        $service = new Mock(
158
            $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
159
            $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
160
            $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
161
        );
162
163
        $uri = $service->testDetermineRequestUriFromPath(
164
            '/path',
165
            new \OAuth\Common\Http\Uri\Uri('https://example.com')
166
        );
167
168
        $this->assertInstanceOf('\\OAuth\\Common\\Http\\Uri\\UriInterface', $uri);
169
        $this->assertSame('https://example.com/path', $uri->getAbsoluteUri());
170
    }
171
}
172