SoundCloudTest   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 150
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
eloc 57
dl 0
loc 150
c 1
b 0
f 0
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A testParseAccessTokenResponseThrowsExceptionOnNulledResponse() 0 14 1
A testConstructCorrectInstanceWithoutCustomUri() 0 9 1
A testGetAccessTokenEndpoint() 0 9 1
A testParseAccessTokenResponseValidWithoutRefreshToken() 0 12 1
A testParseAccessTokenResponseValidWithRefreshToken() 0 12 1
A testConstructCorrectInstanceWithCustomUri() 0 11 1
A testConstructCorrectInterfaceWithoutCustomUri() 0 9 1
A testGetAuthorizationEndpoint() 0 9 1
A testParseAccessTokenResponseThrowsExceptionOnError() 0 14 1
1
<?php
2
3
namespace OAuthTest\Unit\OAuth2\Service;
4
5
use OAuth\OAuth2\Service\SoundCloud;
6
use PHPUnit\Framework\TestCase;
7
8
class SoundCloudTest extends TestCase
9
{
10
    /**
11
     * @covers \OAuth\OAuth2\Service\SoundCloud::__construct
12
     */
13
    public function testConstructCorrectInterfaceWithoutCustomUri(): void
14
    {
15
        $service = new SoundCloud(
16
            $this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
17
            $this->createMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
18
            $this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
19
        );
20
21
        self::assertInstanceOf('\\OAuth\\OAuth2\\Service\\ServiceInterface', $service);
22
    }
23
24
    /**
25
     * @covers \OAuth\OAuth2\Service\SoundCloud::__construct
26
     */
27
    public function testConstructCorrectInstanceWithoutCustomUri(): void
28
    {
29
        $service = new SoundCloud(
30
            $this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
31
            $this->createMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
32
            $this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
33
        );
34
35
        self::assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service);
36
    }
37
38
    /**
39
     * @covers \OAuth\OAuth2\Service\SoundCloud::__construct
40
     */
41
    public function testConstructCorrectInstanceWithCustomUri(): void
42
    {
43
        $service = new SoundCloud(
44
            $this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
45
            $this->createMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
46
            $this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'),
47
            [],
48
            $this->createMock('\\OAuth\\Common\\Http\\Uri\\UriInterface')
49
        );
50
51
        self::assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service);
52
    }
53
54
    /**
55
     * @covers \OAuth\OAuth2\Service\SoundCloud::__construct
56
     * @covers \OAuth\OAuth2\Service\SoundCloud::getAuthorizationEndpoint
57
     */
58
    public function testGetAuthorizationEndpoint(): void
59
    {
60
        $service = new SoundCloud(
61
            $this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
62
            $this->createMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
63
            $this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
64
        );
65
66
        self::assertSame('https://soundcloud.com/connect', $service->getAuthorizationEndpoint()->getAbsoluteUri());
67
    }
68
69
    /**
70
     * @covers \OAuth\OAuth2\Service\SoundCloud::__construct
71
     * @covers \OAuth\OAuth2\Service\SoundCloud::getAccessTokenEndpoint
72
     */
73
    public function testGetAccessTokenEndpoint(): void
74
    {
75
        $service = new SoundCloud(
76
            $this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
77
            $this->createMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
78
            $this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
79
        );
80
81
        self::assertSame('https://api.soundcloud.com/oauth2/token', $service->getAccessTokenEndpoint()->getAbsoluteUri());
82
    }
83
84
    /**
85
     * @covers \OAuth\OAuth2\Service\SoundCloud::__construct
86
     * @covers \OAuth\OAuth2\Service\SoundCloud::parseAccessTokenResponse
87
     */
88
    public function testParseAccessTokenResponseThrowsExceptionOnNulledResponse(): void
89
    {
90
        $client = $this->createMock('\\OAuth\\Common\\Http\\Client\\ClientInterface');
91
        $client->expects(self::once())->method('retrieveResponse')->willReturn(null);
92
93
        $service = new SoundCloud(
94
            $this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
95
            $client,
96
            $this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
97
        );
98
99
        $this->expectException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException');
100
101
        $service->requestAccessToken('foo');
102
    }
103
104
    /**
105
     * @covers \OAuth\OAuth2\Service\SoundCloud::__construct
106
     * @covers \OAuth\OAuth2\Service\SoundCloud::parseAccessTokenResponse
107
     */
108
    public function testParseAccessTokenResponseThrowsExceptionOnError(): void
109
    {
110
        $client = $this->createMock('\\OAuth\\Common\\Http\\Client\\ClientInterface');
111
        $client->expects(self::once())->method('retrieveResponse')->willReturn('error=some_error');
112
113
        $service = new SoundCloud(
114
            $this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
115
            $client,
116
            $this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
117
        );
118
119
        $this->expectException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException');
120
121
        $service->requestAccessToken('foo');
122
    }
123
124
    /**
125
     * @covers \OAuth\OAuth2\Service\SoundCloud::__construct
126
     * @covers \OAuth\OAuth2\Service\SoundCloud::parseAccessTokenResponse
127
     */
128
    public function testParseAccessTokenResponseValidWithoutRefreshToken(): void
129
    {
130
        $client = $this->createMock('\\OAuth\\Common\\Http\\Client\\ClientInterface');
131
        $client->expects(self::once())->method('retrieveResponse')->willReturn('{"access_token":"foo","expires_in":"bar"}');
132
133
        $service = new SoundCloud(
134
            $this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
135
            $client,
136
            $this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
137
        );
138
139
        self::assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo'));
140
    }
141
142
    /**
143
     * @covers \OAuth\OAuth2\Service\SoundCloud::__construct
144
     * @covers \OAuth\OAuth2\Service\SoundCloud::parseAccessTokenResponse
145
     */
146
    public function testParseAccessTokenResponseValidWithRefreshToken(): void
147
    {
148
        $client = $this->createMock('\\OAuth\\Common\\Http\\Client\\ClientInterface');
149
        $client->expects(self::once())->method('retrieveResponse')->willReturn('{"access_token":"foo","expires_in":"bar","refresh_token":"baz"}');
150
151
        $service = new SoundCloud(
152
            $this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
153
            $client,
154
            $this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
155
        );
156
157
        self::assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo'));
158
    }
159
}
160