Skip to content

Commit 9ac68f3

Browse files
author
Георгий Южаков
committed
fix StripeTest
1 parent e791309 commit 9ac68f3

File tree

1 file changed

+70
-68
lines changed

1 file changed

+70
-68
lines changed

tests/Unit/OAuth2/Service/StripeTest.php

Lines changed: 70 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -4,191 +4,193 @@
44

55
use OAuth\OAuth2\Service\Stripe;
66
use OAuth\Common\Token\TokenInterface;
7+
use PHPUnit\Framework\TestCase;
78

8-
class StripeTest extends \PHPUnit_Framework_TestCase
9+
class StripeTest extends TestCase
910
{
1011
/**
11-
* @covers OAuth\OAuth2\Service\Stripe::__construct
12+
* @covers \OAuth\OAuth2\Service\Stripe::__construct
1213
*/
13-
public function testConstructCorrectInterfaceWithoutCustomUri()
14+
public function testConstructCorrectInterfaceWithoutCustomUri(): void
1415
{
1516
$service = new Stripe(
16-
$this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
17-
$this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
18-
$this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
17+
$this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
18+
$this->createMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
19+
$this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
1920
);
2021

21-
$this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\ServiceInterface', $service);
22+
self::assertInstanceOf('\\OAuth\\OAuth2\\Service\\ServiceInterface', $service);
2223
}
2324

2425
/**
25-
* @covers OAuth\OAuth2\Service\Stripe::__construct
26+
* @covers \OAuth\OAuth2\Service\Stripe::__construct
2627
*/
27-
public function testConstructCorrectInstanceWithoutCustomUri()
28+
public function testConstructCorrectInstanceWithoutCustomUri(): void
2829
{
2930
$service = new Stripe(
30-
$this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
31-
$this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
32-
$this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
31+
$this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
32+
$this->createMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
33+
$this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
3334
);
3435

35-
$this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service);
36+
self::assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service);
3637
}
3738

3839
/**
39-
* @covers OAuth\OAuth2\Service\Stripe::__construct
40+
* @covers \OAuth\OAuth2\Service\Stripe::__construct
4041
*/
41-
public function testConstructCorrectInstanceWithCustomUri()
42+
public function testConstructCorrectInstanceWithCustomUri(): void
4243
{
4344
$service = new Stripe(
44-
$this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
45-
$this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
46-
$this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'),
45+
$this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
46+
$this->createMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
47+
$this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'),
4748
array(),
48-
$this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface')
49+
$this->createMock('\\OAuth\\Common\\Http\\Uri\\UriInterface')
4950
);
5051

51-
$this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service);
52+
self::assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service);
5253
}
5354

5455
/**
55-
* @covers OAuth\OAuth2\Service\Stripe::__construct
56-
* @covers OAuth\OAuth2\Service\Stripe::getAuthorizationEndpoint
56+
* @covers \OAuth\OAuth2\Service\Stripe::__construct
57+
* @covers \OAuth\OAuth2\Service\Stripe::getAuthorizationEndpoint
5758
*/
58-
public function testGetAuthorizationEndpoint()
59+
public function testGetAuthorizationEndpoint(): void
5960
{
6061
$service = new Stripe(
61-
$this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
62-
$this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
63-
$this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
62+
$this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
63+
$this->createMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
64+
$this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
6465
);
6566

66-
$this->assertSame(
67+
self::assertSame(
6768
'https://connect.stripe.com/oauth/authorize',
6869
$service->getAuthorizationEndpoint()->getAbsoluteUri()
6970
);
7071
}
7172

7273
/**
73-
* @covers OAuth\OAuth2\Service\Stripe::__construct
74-
* @covers OAuth\OAuth2\Service\Stripe::getAccessTokenEndpoint
74+
* @covers \OAuth\OAuth2\Service\Stripe::__construct
75+
* @covers \OAuth\OAuth2\Service\Stripe::getAccessTokenEndpoint
7576
*/
76-
public function testGetAccessTokenEndpoint()
77+
public function testGetAccessTokenEndpoint(): void
7778
{
7879
$service = new Stripe(
79-
$this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
80-
$this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
81-
$this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
80+
$this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
81+
$this->createMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
82+
$this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
8283
);
8384

84-
$this->assertSame(
85+
self::assertSame(
8586
'https://connect.stripe.com/oauth/token',
8687
$service->getAccessTokenEndpoint()->getAbsoluteUri()
8788
);
8889
}
8990

9091
/**
91-
* @covers OAuth\OAuth2\Service\Stripe::__construct
92-
* @covers OAuth\OAuth2\Service\Stripe::getAuthorizationMethod
92+
* @covers \OAuth\OAuth2\Service\Stripe::__construct
93+
* @covers \OAuth\OAuth2\Service\Stripe::getAuthorizationMethod
9394
*/
94-
public function testGetAuthorizationMethod()
95+
public function testGetAuthorizationMethod(): void
9596
{
96-
$client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface');
97+
$client = $this->createMock('\\OAuth\\Common\\Http\\Client\\ClientInterface');
9798
$client->expects($this->once())->method('retrieveResponse')->will($this->returnArgument(0));
9899

99-
$token = $this->getMock('\\OAuth\\OAuth2\\Token\\TokenInterface');
100+
$token = $this->createMock('\\OAuth\\OAuth2\\Token\\TokenInterface');
100101
$token->expects($this->once())->method('getEndOfLife')->will($this->returnValue(TokenInterface::EOL_NEVER_EXPIRES));
101102
$token->expects($this->once())->method('getAccessToken')->will($this->returnValue('foo'));
102103

103-
$storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface');
104+
$storage = $this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface');
104105
$storage->expects($this->once())->method('retrieveAccessToken')->will($this->returnValue($token));
105106

106107
$service = new Stripe(
107-
$this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
108+
$this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
108109
$client,
109110
$storage
110111
);
111112

112113
$uri = $service->request('https://luisrpalanca.com/my/awesome/path');
113114
$absoluteUri = parse_url($uri->getAbsoluteUri());
114115

115-
$this->assertSame('access_token=foo', $absoluteUri['query']);
116+
self::assertSame('access_token=foo', $absoluteUri['query']);
116117
}
117118

118119
/**
119-
* @covers OAuth\OAuth2\Service\Stripe::__construct
120-
* @covers OAuth\OAuth2\Service\Stripe::parseAccessTokenResponse
120+
* @covers \OAuth\OAuth2\Service\Stripe::__construct
121+
* @covers \OAuth\OAuth2\Service\Stripe::parseAccessTokenResponse
121122
*/
122-
public function testParseAccessTokenResponseThrowsExceptionOnNulledResponse()
123+
public function testParseAccessTokenResponseThrowsExceptionOnNulledResponse(): void
123124
{
124-
$client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface');
125+
$client = $this->createMock('\\OAuth\\Common\\Http\\Client\\ClientInterface');
125126
$client->expects($this->once())->method('retrieveResponse')->will($this->returnValue(null));
126127

127128
$service = new Stripe(
128-
$this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
129+
$this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
129130
$client,
130-
$this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
131+
$this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
131132
);
132133

133-
$this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException');
134+
$this->expectException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException');
134135

135136
$service->requestAccessToken('foo');
136137
}
137138

138139
/**
139-
* @covers OAuth\OAuth2\Service\Stripe::__construct
140-
* @covers OAuth\OAuth2\Service\Stripe::parseAccessTokenResponse
140+
* @covers \OAuth\OAuth2\Service\Stripe::__construct
141+
* @covers \OAuth\OAuth2\Service\Stripe::parseAccessTokenResponse
141142
*/
142143
public function testParseAccessTokenResponseThrowsExceptionOnError()
143144
{
144-
$client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface');
145-
$client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('error=some_error'));
145+
$client = $this->createMock('\\OAuth\\Common\\Http\\Client\\ClientInterface');
146+
$client->expects($this->once())
147+
->method('retrieveResponse')->willReturn('error=some_error');
146148

147149
$service = new Stripe(
148-
$this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
150+
$this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
149151
$client,
150-
$this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
152+
$this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
151153
);
152154

153-
$this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException');
155+
$this->expectException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException');
154156

155157
$service->requestAccessToken('foo');
156158
}
157159

158160
/**
159-
* @covers OAuth\OAuth2\Service\Stripe::__construct
160-
* @covers OAuth\OAuth2\Service\Stripe::parseAccessTokenResponse
161+
* @covers \OAuth\OAuth2\Service\Stripe::__construct
162+
* @covers \OAuth\OAuth2\Service\Stripe::parseAccessTokenResponse
161163
*/
162164
public function testParseAccessTokenResponseValidWithoutRefreshToken()
163165
{
164-
$client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface');
166+
$client = $this->createMock('\\OAuth\\Common\\Http\\Client\\ClientInterface');
165167
$client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo","expires_in":"bar"}'));
166168

167169
$service = new Stripe(
168-
$this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
170+
$this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
169171
$client,
170-
$this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
172+
$this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
171173
);
172174

173-
$this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo'));
175+
self::assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo'));
174176
}
175177

176178
/**
177-
* @covers OAuth\OAuth2\Service\Stripe::__construct
178-
* @covers OAuth\OAuth2\Service\Stripe::parseAccessTokenResponse
179+
* @covers \OAuth\OAuth2\Service\Stripe::__construct
180+
* @covers \OAuth\OAuth2\Service\Stripe::parseAccessTokenResponse
179181
*/
180182
public function testParseAccessTokenResponseValidWithRefreshToken()
181183
{
182-
$client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface');
184+
$client = $this->createMock('\\OAuth\\Common\\Http\\Client\\ClientInterface');
183185
$client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo","expires_in":"bar","refresh_token":"baz"}'));
184186

185187
$service = new Stripe(
186-
$this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
188+
$this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
187189
$client,
188-
$this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
190+
$this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
189191
);
190192

191-
$this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo'));
193+
self::assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo'));
192194
}
193195
}
194196

0 commit comments

Comments
 (0)