|
4 | 4 |
|
5 | 5 | use OAuth\OAuth2\Service\Stripe; |
6 | 6 | use OAuth\Common\Token\TokenInterface; |
| 7 | +use PHPUnit\Framework\TestCase; |
7 | 8 |
|
8 | | -class StripeTest extends \PHPUnit_Framework_TestCase |
| 9 | +class StripeTest extends TestCase |
9 | 10 | { |
10 | 11 | /** |
11 | | - * @covers OAuth\OAuth2\Service\Stripe::__construct |
| 12 | + * @covers \OAuth\OAuth2\Service\Stripe::__construct |
12 | 13 | */ |
13 | | - public function testConstructCorrectInterfaceWithoutCustomUri() |
| 14 | + public function testConstructCorrectInterfaceWithoutCustomUri(): void |
14 | 15 | { |
15 | 16 | $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') |
19 | 20 | ); |
20 | 21 |
|
21 | | - $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\ServiceInterface', $service); |
| 22 | + self::assertInstanceOf('\\OAuth\\OAuth2\\Service\\ServiceInterface', $service); |
22 | 23 | } |
23 | 24 |
|
24 | 25 | /** |
25 | | - * @covers OAuth\OAuth2\Service\Stripe::__construct |
| 26 | + * @covers \OAuth\OAuth2\Service\Stripe::__construct |
26 | 27 | */ |
27 | | - public function testConstructCorrectInstanceWithoutCustomUri() |
| 28 | + public function testConstructCorrectInstanceWithoutCustomUri(): void |
28 | 29 | { |
29 | 30 | $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') |
33 | 34 | ); |
34 | 35 |
|
35 | | - $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); |
| 36 | + self::assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); |
36 | 37 | } |
37 | 38 |
|
38 | 39 | /** |
39 | | - * @covers OAuth\OAuth2\Service\Stripe::__construct |
| 40 | + * @covers \OAuth\OAuth2\Service\Stripe::__construct |
40 | 41 | */ |
41 | | - public function testConstructCorrectInstanceWithCustomUri() |
| 42 | + public function testConstructCorrectInstanceWithCustomUri(): void |
42 | 43 | { |
43 | 44 | $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'), |
47 | 48 | array(), |
48 | | - $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') |
| 49 | + $this->createMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') |
49 | 50 | ); |
50 | 51 |
|
51 | | - $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); |
| 52 | + self::assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); |
52 | 53 | } |
53 | 54 |
|
54 | 55 | /** |
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 |
57 | 58 | */ |
58 | | - public function testGetAuthorizationEndpoint() |
| 59 | + public function testGetAuthorizationEndpoint(): void |
59 | 60 | { |
60 | 61 | $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') |
64 | 65 | ); |
65 | 66 |
|
66 | | - $this->assertSame( |
| 67 | + self::assertSame( |
67 | 68 | 'https://connect.stripe.com/oauth/authorize', |
68 | 69 | $service->getAuthorizationEndpoint()->getAbsoluteUri() |
69 | 70 | ); |
70 | 71 | } |
71 | 72 |
|
72 | 73 | /** |
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 |
75 | 76 | */ |
76 | | - public function testGetAccessTokenEndpoint() |
| 77 | + public function testGetAccessTokenEndpoint(): void |
77 | 78 | { |
78 | 79 | $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') |
82 | 83 | ); |
83 | 84 |
|
84 | | - $this->assertSame( |
| 85 | + self::assertSame( |
85 | 86 | 'https://connect.stripe.com/oauth/token', |
86 | 87 | $service->getAccessTokenEndpoint()->getAbsoluteUri() |
87 | 88 | ); |
88 | 89 | } |
89 | 90 |
|
90 | 91 | /** |
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 |
93 | 94 | */ |
94 | | - public function testGetAuthorizationMethod() |
| 95 | + public function testGetAuthorizationMethod(): void |
95 | 96 | { |
96 | | - $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); |
| 97 | + $client = $this->createMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); |
97 | 98 | $client->expects($this->once())->method('retrieveResponse')->will($this->returnArgument(0)); |
98 | 99 |
|
99 | | - $token = $this->getMock('\\OAuth\\OAuth2\\Token\\TokenInterface'); |
| 100 | + $token = $this->createMock('\\OAuth\\OAuth2\\Token\\TokenInterface'); |
100 | 101 | $token->expects($this->once())->method('getEndOfLife')->will($this->returnValue(TokenInterface::EOL_NEVER_EXPIRES)); |
101 | 102 | $token->expects($this->once())->method('getAccessToken')->will($this->returnValue('foo')); |
102 | 103 |
|
103 | | - $storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'); |
| 104 | + $storage = $this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'); |
104 | 105 | $storage->expects($this->once())->method('retrieveAccessToken')->will($this->returnValue($token)); |
105 | 106 |
|
106 | 107 | $service = new Stripe( |
107 | | - $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), |
| 108 | + $this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), |
108 | 109 | $client, |
109 | 110 | $storage |
110 | 111 | ); |
111 | 112 |
|
112 | 113 | $uri = $service->request('https://luisrpalanca.com/my/awesome/path'); |
113 | 114 | $absoluteUri = parse_url($uri->getAbsoluteUri()); |
114 | 115 |
|
115 | | - $this->assertSame('access_token=foo', $absoluteUri['query']); |
| 116 | + self::assertSame('access_token=foo', $absoluteUri['query']); |
116 | 117 | } |
117 | 118 |
|
118 | 119 | /** |
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 |
121 | 122 | */ |
122 | | - public function testParseAccessTokenResponseThrowsExceptionOnNulledResponse() |
| 123 | + public function testParseAccessTokenResponseThrowsExceptionOnNulledResponse(): void |
123 | 124 | { |
124 | | - $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); |
| 125 | + $client = $this->createMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); |
125 | 126 | $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue(null)); |
126 | 127 |
|
127 | 128 | $service = new Stripe( |
128 | | - $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), |
| 129 | + $this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), |
129 | 130 | $client, |
130 | | - $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') |
| 131 | + $this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') |
131 | 132 | ); |
132 | 133 |
|
133 | | - $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); |
| 134 | + $this->expectException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); |
134 | 135 |
|
135 | 136 | $service->requestAccessToken('foo'); |
136 | 137 | } |
137 | 138 |
|
138 | 139 | /** |
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 |
141 | 142 | */ |
142 | 143 | public function testParseAccessTokenResponseThrowsExceptionOnError() |
143 | 144 | { |
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'); |
146 | 148 |
|
147 | 149 | $service = new Stripe( |
148 | | - $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), |
| 150 | + $this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), |
149 | 151 | $client, |
150 | | - $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') |
| 152 | + $this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') |
151 | 153 | ); |
152 | 154 |
|
153 | | - $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); |
| 155 | + $this->expectException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); |
154 | 156 |
|
155 | 157 | $service->requestAccessToken('foo'); |
156 | 158 | } |
157 | 159 |
|
158 | 160 | /** |
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 |
161 | 163 | */ |
162 | 164 | public function testParseAccessTokenResponseValidWithoutRefreshToken() |
163 | 165 | { |
164 | | - $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); |
| 166 | + $client = $this->createMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); |
165 | 167 | $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo","expires_in":"bar"}')); |
166 | 168 |
|
167 | 169 | $service = new Stripe( |
168 | | - $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), |
| 170 | + $this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), |
169 | 171 | $client, |
170 | | - $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') |
| 172 | + $this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') |
171 | 173 | ); |
172 | 174 |
|
173 | | - $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); |
| 175 | + self::assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); |
174 | 176 | } |
175 | 177 |
|
176 | 178 | /** |
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 |
179 | 181 | */ |
180 | 182 | public function testParseAccessTokenResponseValidWithRefreshToken() |
181 | 183 | { |
182 | | - $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); |
| 184 | + $client = $this->createMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); |
183 | 185 | $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo","expires_in":"bar","refresh_token":"baz"}')); |
184 | 186 |
|
185 | 187 | $service = new Stripe( |
186 | | - $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), |
| 188 | + $this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), |
187 | 189 | $client, |
188 | | - $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') |
| 190 | + $this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') |
189 | 191 | ); |
190 | 192 |
|
191 | | - $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); |
| 193 | + self::assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); |
192 | 194 | } |
193 | 195 | } |
194 | 196 |
|
0 commit comments