1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OAuthTest\Unit\OAuth2\Service; |
4
|
|
|
|
5
|
|
|
use OAuth\OAuth2\Service\Strava; |
6
|
|
|
use OAuth\Common\Token\TokenInterface; |
7
|
|
|
|
8
|
|
|
class StravaTest extends \PHPUnit_Framework_TestCase |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @covers OAuth\OAuth2\Service\Strava::__construct |
12
|
|
|
*/ |
13
|
|
|
public function testConstructCorrectInterfaceWithoutCustomUri() |
14
|
|
|
{ |
15
|
|
|
$service = new Strava( |
16
|
|
|
$this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), |
17
|
|
|
$this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), |
18
|
|
|
$this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') |
19
|
|
|
); |
20
|
|
|
|
21
|
|
|
$this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\ServiceInterface', $service); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @covers OAuth\OAuth2\Service\Strava::__construct |
26
|
|
|
*/ |
27
|
|
|
public function testConstructCorrectInstanceWithoutCustomUri() |
28
|
|
|
{ |
29
|
|
|
$service = new Strava( |
30
|
|
|
$this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), |
31
|
|
|
$this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), |
32
|
|
|
$this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') |
33
|
|
|
); |
34
|
|
|
|
35
|
|
|
$this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @covers OAuth\OAuth2\Service\Strava::__construct |
40
|
|
|
*/ |
41
|
|
|
public function testConstructCorrectInstanceWithCustomUri() |
42
|
|
|
{ |
43
|
|
|
$service = new Strava( |
44
|
|
|
$this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), |
45
|
|
|
$this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), |
46
|
|
|
$this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'), |
47
|
|
|
array(), |
48
|
|
|
$this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') |
49
|
|
|
); |
50
|
|
|
|
51
|
|
|
$this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @covers OAuth\OAuth2\Service\Strava::__construct |
56
|
|
|
* @covers OAuth\OAuth2\Service\Strava::getAuthorizationEndpoint |
57
|
|
|
*/ |
58
|
|
|
public function testGetAuthorizationEndpoint() |
59
|
|
|
{ |
60
|
|
|
$service = new Strava( |
61
|
|
|
$this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), |
62
|
|
|
$this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), |
63
|
|
|
$this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') |
64
|
|
|
); |
65
|
|
|
|
66
|
|
|
$this->assertSame( |
67
|
|
|
'https://www.strava.com/oauth/authorize?approval_prompt=auto', |
68
|
|
|
$service->getAuthorizationEndpoint()->getAbsoluteUri() |
69
|
|
|
); |
70
|
|
|
|
71
|
|
|
// Verify that 'offine' works |
72
|
|
|
$service->setApprouvalPrompt('force'); |
73
|
|
|
$this->assertSame( |
74
|
|
|
'https://www.strava.com/oauth/authorize?approval_prompt=force', |
75
|
|
|
$service->getAuthorizationEndpoint()->getAbsoluteUri() |
76
|
|
|
); |
77
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @covers OAuth\OAuth2\Service\Strava::__construct |
82
|
|
|
* @covers OAuth\OAuth2\Service\Strava::getAuthorizationEndpoint |
83
|
|
|
*/ |
84
|
|
|
public function testGetAuthorizationEndpointException() |
85
|
|
|
{ |
86
|
|
|
$service = new Strava( |
87
|
|
|
$this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), |
88
|
|
|
$this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), |
89
|
|
|
$this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') |
90
|
|
|
); |
91
|
|
|
|
92
|
|
|
$this->setExpectedException('OAuth\OAuth2\Service\Exception\InvalidAccessTypeException'); |
93
|
|
|
|
94
|
|
|
try { |
95
|
|
|
$service->setApprouvalPrompt('invalid'); |
96
|
|
|
} catch (InvalidAccessTypeException $e) { |
|
|
|
|
97
|
|
|
return; |
98
|
|
|
} |
99
|
|
|
$this->fail('Expected InvalidAccessTypeException not thrown'); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @covers OAuth\OAuth2\Service\Strava::__construct |
104
|
|
|
* @covers OAuth\OAuth2\Service\Strava::getAccessTokenEndpoint |
105
|
|
|
*/ |
106
|
|
|
public function testGetAccessTokenEndpoint() |
107
|
|
|
{ |
108
|
|
|
$service = new Strava( |
109
|
|
|
$this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), |
110
|
|
|
$this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), |
111
|
|
|
$this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') |
112
|
|
|
); |
113
|
|
|
|
114
|
|
|
$this->assertSame( |
115
|
|
|
'https://www.strava.com/oauth/token', |
116
|
|
|
$service->getAccessTokenEndpoint()->getAbsoluteUri() |
117
|
|
|
); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @covers OAuth\OAuth2\Service\Strava::__construct |
122
|
|
|
* @covers OAuth\OAuth2\Service\Strava::parseAccessTokenResponse |
123
|
|
|
*/ |
124
|
|
|
public function testParseAccessTokenResponseThrowsExceptionOnNulledResponse() |
125
|
|
|
{ |
126
|
|
|
$client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); |
127
|
|
|
$client->expects($this->once())->method('retrieveResponse')->will($this->returnValue(null)); |
128
|
|
|
|
129
|
|
|
$service = new Strava( |
130
|
|
|
$this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), |
131
|
|
|
$client, |
132
|
|
|
$this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') |
133
|
|
|
); |
134
|
|
|
|
135
|
|
|
$this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); |
136
|
|
|
|
137
|
|
|
$service->requestAccessToken('foo'); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @covers OAuth\OAuth2\Service\Strava::__construct |
142
|
|
|
* @covers OAuth\OAuth2\Service\Strava::parseAccessTokenResponse |
143
|
|
|
*/ |
144
|
|
|
public function testParseAccessTokenResponseThrowsExceptionOnError() |
145
|
|
|
{ |
146
|
|
|
$client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); |
147
|
|
|
$client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('error=some_error')); |
148
|
|
|
|
149
|
|
|
$service = new Strava( |
150
|
|
|
$this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), |
151
|
|
|
$client, |
152
|
|
|
$this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') |
153
|
|
|
); |
154
|
|
|
|
155
|
|
|
$this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); |
156
|
|
|
|
157
|
|
|
$service->requestAccessToken('foo'); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @covers OAuth\OAuth2\Service\Strava::__construct |
162
|
|
|
* @covers OAuth\OAuth2\Service\Strava::parseAccessTokenResponse |
163
|
|
|
*/ |
164
|
|
|
public function testParseAccessTokenResponseValid() |
165
|
|
|
{ |
166
|
|
|
$client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); |
167
|
|
|
$client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo","expires_in":"bar"}')); |
168
|
|
|
|
169
|
|
|
$service = new Strava( |
170
|
|
|
$this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), |
171
|
|
|
$client, |
172
|
|
|
$this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') |
173
|
|
|
); |
174
|
|
|
|
175
|
|
|
$this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); |
176
|
|
|
} |
177
|
|
|
} |
178
|
|
|
|
Scrutinizer analyzes your
composer.json
/composer.lock
file if available to determine the classes, and functions that are defined by your dependencies.It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.