Skip to content

Commit da7f595

Browse files
committed
Add tests for regenerated clients and openapi-generator 7.22.0 changes
1 parent e746dd5 commit da7f595

8 files changed

Lines changed: 1361 additions & 0 deletions

File tree

test/clients/channel-access-token/Api/ChannelAccessTokenApiTest.php

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Copyright 2024 LINE Corporation
45
*
@@ -334,4 +335,161 @@ public function testIssueStatelessChannelTokenByClientSecretAsyncWithHttpInfo():
334335
$this->assertEquals('Bearer', $response->getTokenType());
335336
$this->assertEquals(200, $statusCode);
336337
}
338+
339+
public function testIssueChannelToken(): void
340+
{
341+
$client = Mockery::mock(ClientInterface::class);
342+
$client->shouldReceive('send')
343+
->with(
344+
Mockery::on(function (Request $request) {
345+
$this->assertEquals('POST', $request->getMethod());
346+
$this->assertEquals('https://api.line.me/v2/oauth/accessToken', (string)$request->getUri());
347+
$body = (string)$request->getBody();
348+
parse_str($body, $params);
349+
// Must use snake_case keys from the OpenAPI spec
350+
$this->assertEquals('client_credentials', $params['grant_type']);
351+
$this->assertEquals('1234', $params['client_id']);
352+
$this->assertEquals('clientSecret', $params['client_secret']);
353+
// Must NOT use camelCase keys
354+
$this->assertArrayNotHasKey('grantType', $params);
355+
$this->assertArrayNotHasKey('clientId', $params);
356+
$this->assertArrayNotHasKey('clientSecret', $params);
357+
return true;
358+
}),
359+
[]
360+
)
361+
->once()
362+
->andReturn(new Response(
363+
status: 200,
364+
headers: [],
365+
body: json_encode(['access_token' => 'accessToken', 'expires_in' => 2592000, 'token_type' => 'Bearer']),
366+
));
367+
$api = new ChannelAccessTokenApi($client);
368+
$response = $api->issueChannelToken(grantType: 'client_credentials', clientId: '1234', clientSecret: 'clientSecret');
369+
$this->assertEquals('accessToken', $response->getAccessToken());
370+
$this->assertEquals(2592000, $response->getExpiresIn());
371+
$this->assertEquals('Bearer', $response->getTokenType());
372+
}
373+
374+
public function testIssueChannelTokenByJWT(): void
375+
{
376+
$client = Mockery::mock(ClientInterface::class);
377+
$client->shouldReceive('send')
378+
->with(
379+
Mockery::on(function (Request $request) {
380+
$this->assertEquals('POST', $request->getMethod());
381+
$this->assertEquals('https://api.line.me/oauth2/v2.1/token', (string)$request->getUri());
382+
$body = (string)$request->getBody();
383+
parse_str($body, $params);
384+
// Must use snake_case keys from the OpenAPI spec
385+
$this->assertEquals('client_credentials', $params['grant_type']);
386+
$this->assertEquals('urn:ietf:params:oauth:client-assertion-type:jwt-bearer', $params['client_assertion_type']);
387+
$this->assertEquals('jwtAssertionToken', $params['client_assertion']);
388+
// Must NOT use camelCase keys
389+
$this->assertArrayNotHasKey('grantType', $params);
390+
$this->assertArrayNotHasKey('clientAssertionType', $params);
391+
$this->assertArrayNotHasKey('clientAssertion', $params);
392+
return true;
393+
}),
394+
[]
395+
)
396+
->once()
397+
->andReturn(new Response(
398+
status: 200,
399+
headers: [],
400+
body: json_encode(['access_token' => 'accessToken', 'expires_in' => 2592000, 'token_type' => 'Bearer', 'key_id' => 'keyId']),
401+
));
402+
$api = new ChannelAccessTokenApi($client);
403+
$response = $api->issueChannelTokenByJWT(
404+
grantType: 'client_credentials',
405+
clientAssertionType: 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer',
406+
clientAssertion: 'jwtAssertionToken',
407+
);
408+
$this->assertEquals('accessToken', $response->getAccessToken());
409+
$this->assertEquals(2592000, $response->getExpiresIn());
410+
$this->assertEquals('Bearer', $response->getTokenType());
411+
}
412+
413+
public function testRevokeChannelToken(): void
414+
{
415+
$client = Mockery::mock(ClientInterface::class);
416+
$client->shouldReceive('send')
417+
->with(
418+
Mockery::on(function (Request $request) {
419+
$this->assertEquals('POST', $request->getMethod());
420+
$this->assertEquals('https://api.line.me/v2/oauth/revoke', (string)$request->getUri());
421+
$body = (string)$request->getBody();
422+
parse_str($body, $params);
423+
// Must use snake_case key from the OpenAPI spec
424+
$this->assertEquals('myAccessToken', $params['access_token']);
425+
// Must NOT use camelCase key
426+
$this->assertArrayNotHasKey('accessToken', $params);
427+
return true;
428+
}),
429+
[]
430+
)
431+
->once()
432+
->andReturn(new Response(status: 200, headers: [], body: ''));
433+
$api = new ChannelAccessTokenApi($client);
434+
$api->revokeChannelToken(accessToken: 'myAccessToken');
435+
}
436+
437+
public function testRevokeChannelTokenByJWT(): void
438+
{
439+
$client = Mockery::mock(ClientInterface::class);
440+
$client->shouldReceive('send')
441+
->with(
442+
Mockery::on(function (Request $request) {
443+
$this->assertEquals('POST', $request->getMethod());
444+
$this->assertEquals('https://api.line.me/oauth2/v2.1/revoke', (string)$request->getUri());
445+
$body = (string)$request->getBody();
446+
parse_str($body, $params);
447+
// Must use snake_case keys from the OpenAPI spec
448+
$this->assertEquals('1234', $params['client_id']);
449+
$this->assertEquals('clientSecret', $params['client_secret']);
450+
$this->assertEquals('myAccessToken', $params['access_token']);
451+
// Must NOT use camelCase keys
452+
$this->assertArrayNotHasKey('clientId', $params);
453+
$this->assertArrayNotHasKey('clientSecret', $params);
454+
$this->assertArrayNotHasKey('accessToken', $params);
455+
return true;
456+
}),
457+
[]
458+
)
459+
->once()
460+
->andReturn(new Response(status: 200, headers: [], body: ''));
461+
$api = new ChannelAccessTokenApi($client);
462+
$api->revokeChannelTokenByJWT(clientId: '1234', clientSecret: 'clientSecret', accessToken: 'myAccessToken');
463+
}
464+
465+
public function testVerifyChannelToken(): void
466+
{
467+
$client = Mockery::mock(ClientInterface::class);
468+
$client->shouldReceive('send')
469+
->with(
470+
Mockery::on(function (Request $request) {
471+
$this->assertEquals('POST', $request->getMethod());
472+
$this->assertEquals('https://api.line.me/v2/oauth/verify', (string)$request->getUri());
473+
$body = (string)$request->getBody();
474+
parse_str($body, $params);
475+
// Must use snake_case key from the OpenAPI spec
476+
$this->assertEquals('myAccessToken', $params['access_token']);
477+
// Must NOT use camelCase key
478+
$this->assertArrayNotHasKey('accessToken', $params);
479+
return true;
480+
}),
481+
[]
482+
)
483+
->once()
484+
->andReturn(new Response(
485+
status: 200,
486+
headers: [],
487+
body: json_encode(['client_id' => '1234', 'expires_in' => 2592000, 'scope' => 'profile']),
488+
));
489+
$api = new ChannelAccessTokenApi($client);
490+
$response = $api->verifyChannelToken(accessToken: 'myAccessToken');
491+
$this->assertInstanceOf(VerifyChannelAccessTokenResponse::class, $response);
492+
$this->assertEquals('1234', $response->getClientId());
493+
$this->assertEquals(2592000, $response->getExpiresIn());
494+
}
337495
}

0 commit comments

Comments
 (0)