15
15
16
16
class AlipayTest extends TestCase
17
17
{
18
- public function testAlipayProviderHasCorrectRedirectResponse ()
18
+ public function test_alipay_provider_has_correct_redirect_response ()
19
19
{
20
20
$ provider = new Alipay ([
21
21
'client_id ' => 'client_id ' ,
@@ -31,7 +31,7 @@ public function testAlipayProviderHasCorrectRedirectResponse()
31
31
$ this ->assertStringContainsString ('scope=auth_user ' , $ response );
32
32
}
33
33
34
- public function testAlipayProviderSandboxMode ()
34
+ public function test_alipay_provider_sandbox_mode ()
35
35
{
36
36
$ provider = new Alipay ([
37
37
'client_id ' => 'client_id ' ,
@@ -45,7 +45,7 @@ public function testAlipayProviderSandboxMode()
45
45
$ this ->assertStringStartsWith ('https://openauth.alipaydev.com/oauth2/publicAppAuthorize.htm ' , $ response );
46
46
}
47
47
48
- public function testAlipayProviderUrlsAndFields ()
48
+ public function test_alipay_provider_urls_and_fields ()
49
49
{
50
50
$ provider = new Alipay ([
51
51
'client_id ' => 'client_id ' ,
@@ -59,7 +59,7 @@ public function testAlipayProviderUrlsAndFields()
59
59
$ this ->assertSame ('https://openapi.alipay.com/gateway.do ' , $ getTokenUrl ->invoke ($ provider ));
60
60
}
61
61
62
- public function testGetPublicFields ()
62
+ public function test_get_public_fields ()
63
63
{
64
64
$ provider = new Alipay ([
65
65
'client_id ' => 'test_app_id ' ,
@@ -84,7 +84,7 @@ public function testGetPublicFields()
84
84
$ this ->assertSame ('1.0 ' , $ fields ['version ' ]);
85
85
}
86
86
87
- public function testGetCodeFieldsThrowsExceptionWhenNoRedirectUrl ()
87
+ public function test_get_code_fields_throws_exception_when_no_redirect_url ()
88
88
{
89
89
$ provider = new Alipay ([
90
90
'client_id ' => 'client_id ' ,
@@ -99,7 +99,7 @@ public function testGetCodeFieldsThrowsExceptionWhenNoRedirectUrl()
99
99
$ getCodeFields ->invoke ($ provider );
100
100
}
101
101
102
- public function testGetCodeFields ()
102
+ public function test_get_code_fields ()
103
103
{
104
104
$ provider = new Alipay ([
105
105
'app_id ' => 'test_app_id ' ,
@@ -119,7 +119,7 @@ public function testGetCodeFields()
119
119
$ this ->assertSame ('http://localhost/callback ' , $ fields ['redirect_uri ' ]);
120
120
}
121
121
122
- public function testSignWithSHA256RSAThrowsExceptionWhenNoPrivateKey ()
122
+ public function test_sign_with_sh_a256_rsa_throws_exception_when_no_private_key ()
123
123
{
124
124
$ provider = new Alipay ([
125
125
'client_id ' => 'client_id ' ,
@@ -134,7 +134,7 @@ public function testSignWithSHA256RSAThrowsExceptionWhenNoPrivateKey()
134
134
$ signWithSHA256RSA ->invoke ($ provider , 'test_content ' , '' );
135
135
}
136
136
137
- public function testBuildParams ()
137
+ public function test_build_params ()
138
138
{
139
139
$ params = [
140
140
'app_id ' => 'test_app_id ' ,
@@ -150,7 +150,7 @@ public function testBuildParams()
150
150
$ this ->assertStringContainsString ('timestamp=2024-01-01%2012%3A00%3A00 ' , $ resultWithUrlencode );
151
151
}
152
152
153
- public function testTokenFromCodeSuccess ()
153
+ public function test_token_from_code_success ()
154
154
{
155
155
$ provider = new Alipay ([
156
156
'client_id ' => 'client_id ' ,
@@ -163,27 +163,27 @@ public function testTokenFromCodeSuccess()
163
163
new Response (200 , [], json_encode ([
164
164
'alipay_system_oauth_token_response ' => [
165
165
'access_token ' => 'token123 ' ,
166
- 'user_id ' => 'user123 '
167
- ]
168
- ]))
166
+ 'user_id ' => 'user123 ' ,
167
+ ],
168
+ ])),
169
169
]);
170
170
171
171
$ handler = HandlerStack::create ($ mock );
172
172
$ client = new Client (['handler ' => $ handler ]);
173
-
173
+
174
174
// Use reflection to set the HTTP client
175
175
$ reflection = new \ReflectionObject ($ provider );
176
176
$ httpClientProperty = $ reflection ->getProperty ('httpClient ' );
177
177
$ httpClientProperty ->setAccessible (true );
178
178
$ httpClientProperty ->setValue ($ provider , $ client );
179
179
180
180
$ token = $ provider ->tokenFromCode ('test_code ' );
181
-
181
+
182
182
$ this ->assertArrayHasKey ('access_token ' , $ token );
183
183
$ this ->assertSame ('token123 ' , $ token ['access_token ' ]);
184
184
}
185
185
186
- public function testThrowsExceptionWhenTokenResponseMissing ()
186
+ public function test_throws_exception_when_token_response_missing ()
187
187
{
188
188
$ provider = new Alipay ([
189
189
'client_id ' => 'client_id ' ,
@@ -194,13 +194,13 @@ public function testThrowsExceptionWhenTokenResponseMissing()
194
194
// Mock HTTP response without alipay_system_oauth_token_response
195
195
$ mock = new MockHandler ([
196
196
new Response (200 , [], json_encode ([
197
- 'some_other_field ' => 'value '
198
- ]))
197
+ 'some_other_field ' => 'value ' ,
198
+ ])),
199
199
]);
200
200
201
201
$ handler = HandlerStack::create ($ mock );
202
202
$ client = new Client (['handler ' => $ handler ]);
203
-
203
+
204
204
// Use reflection to set the HTTP client
205
205
$ reflection = new \ReflectionObject ($ provider );
206
206
$ httpClientProperty = $ reflection ->getProperty ('httpClient ' );
@@ -209,11 +209,11 @@ public function testThrowsExceptionWhenTokenResponseMissing()
209
209
210
210
$ this ->expectException (AuthorizeFailedException::class);
211
211
$ this ->expectExceptionMessage ('Authorization failed: missing alipay_system_oauth_token_response in response ' );
212
-
212
+
213
213
$ provider ->tokenFromCode ('test_code ' );
214
214
}
215
215
216
- public function testThrowsExceptionWhenErrorResponse ()
216
+ public function test_throws_exception_when_error_response ()
217
217
{
218
218
$ provider = new Alipay ([
219
219
'client_id ' => 'client_id ' ,
@@ -226,14 +226,14 @@ public function testThrowsExceptionWhenErrorResponse()
226
226
new Response (200 , [], json_encode ([
227
227
'error_response ' => [
228
228
'code ' => '20001 ' ,
229
- 'msg ' => 'Invalid parameters '
230
- ]
231
- ]))
229
+ 'msg ' => 'Invalid parameters ' ,
230
+ ],
231
+ ])),
232
232
]);
233
233
234
234
$ handler = HandlerStack::create ($ mock );
235
235
$ client = new Client (['handler ' => $ handler ]);
236
-
236
+
237
237
// Use reflection to set the HTTP client
238
238
$ reflection = new \ReflectionObject ($ provider );
239
239
$ httpClientProperty = $ reflection ->getProperty ('httpClient ' );
@@ -245,7 +245,7 @@ public function testThrowsExceptionWhenErrorResponse()
245
245
$ provider ->tokenFromCode ('test_code ' );
246
246
}
247
247
248
- public function testGetUserByTokenSuccess ()
248
+ public function test_get_user_by_token_success ()
249
249
{
250
250
$ provider = new Alipay ([
251
251
'client_id ' => 'client_id ' ,
@@ -258,14 +258,14 @@ public function testGetUserByTokenSuccess()
258
258
new Response (200 , [], json_encode ([
259
259
'alipay_user_info_share_response ' => [
260
260
'user_id ' => 'user123 ' ,
261
- 'nick_name ' => 'Test User '
262
- ]
263
- ]))
261
+ 'nick_name ' => 'Test User ' ,
262
+ ],
263
+ ])),
264
264
]);
265
265
266
266
$ handler = HandlerStack::create ($ mock );
267
267
$ client = new Client (['handler ' => $ handler ]);
268
-
268
+
269
269
// Use reflection to set the HTTP client
270
270
$ reflection = new \ReflectionObject ($ provider );
271
271
$ httpClientProperty = $ reflection ->getProperty ('httpClient ' );
@@ -282,7 +282,7 @@ public function testGetUserByTokenSuccess()
282
282
$ this ->assertSame ('Test User ' , $ result ['nick_name ' ]);
283
283
}
284
284
285
- public function testGetUserByTokenThrowsExceptionWhenErrorResponse ()
285
+ public function test_get_user_by_token_throws_exception_when_error_response ()
286
286
{
287
287
$ provider = new Alipay ([
288
288
'client_id ' => 'client_id ' ,
@@ -295,14 +295,14 @@ public function testGetUserByTokenThrowsExceptionWhenErrorResponse()
295
295
new Response (200 , [], json_encode ([
296
296
'error_response ' => [
297
297
'code ' => '20001 ' ,
298
- 'msg ' => 'Invalid token '
299
- ]
300
- ]))
298
+ 'msg ' => 'Invalid token ' ,
299
+ ],
300
+ ])),
301
301
]);
302
302
303
303
$ handler = HandlerStack::create ($ mock );
304
304
$ client = new Client (['handler ' => $ handler ]);
305
-
305
+
306
306
// Use reflection to set the HTTP client
307
307
$ reflection = new \ReflectionObject ($ provider );
308
308
$ httpClientProperty = $ reflection ->getProperty ('httpClient ' );
@@ -316,7 +316,7 @@ public function testGetUserByTokenThrowsExceptionWhenErrorResponse()
316
316
$ getUserByToken ->invoke ($ provider , 'test_token ' );
317
317
}
318
318
319
- public function testMapUserToObject ()
319
+ public function test_map_user_to_object ()
320
320
{
321
321
$ provider = new Alipay ([
322
322
'client_id ' => 'client_id ' ,
@@ -341,4 +341,4 @@ public function testMapUserToObject()
341
341
$ this ->assertSame ('http://avatar.url ' , $ result ->getAvatar ());
342
342
$ this ->
assertSame (
'[email protected] ' ,
$ result->
getEmail ());
343
343
}
344
- }
344
+ }
0 commit comments