Skip to content

Commit cb52132

Browse files
authored
Add issueStatelessChannelToken test (#607)
`/oauth2/v3/token` requires only 3 parameters, but client requires 5 parameters. Our client must work even if some of arguments are passed `null` like `client.issueStatelessChannelToken("client_credentials", null, null, "1234", "clientSecret")`. This change adds a test to verify this.
1 parent c3d5e8c commit cb52132

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/**
3+
* Copyright 2024 LINE Corporation
4+
*
5+
* LINE Corporation licenses this file to you under the Apache License,
6+
* version 2.0 (the "License"); you may not use this file except in compliance
7+
* with the License. You may obtain a copy of the License at:
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
* License for the specific language governing permissions and limitations
15+
* under the License.
16+
*/
17+
18+
namespace LINE\Tests\Clients\ChannelAccessToken\Api;
19+
20+
use GuzzleHttp\ClientInterface;
21+
use GuzzleHttp\Psr7\Request;
22+
use GuzzleHttp\Psr7\Response;
23+
use LINE\Clients\ChannelAccessToken\Api\ChannelAccessTokenApi;
24+
use Mockery;
25+
use PHPUnit\Framework\TestCase;
26+
27+
class ChannelAccessTokenApiTest extends TestCase
28+
{
29+
protected function setUp(): void
30+
{
31+
parent::setUp();
32+
}
33+
34+
public function testIssueStatelessChannelToken(): void
35+
{
36+
$client = Mockery::mock(ClientInterface::class);
37+
$client->shouldReceive('send')
38+
->with(
39+
Mockery::on(function (Request $request) {
40+
$this->assertEquals('POST', $request->getMethod());
41+
$this->assertEquals('https://api.line.me/oauth2/v3/token', (string)$request->getUri());
42+
$this->assertEquals('grant_type=client_credentials&client_id=1234&client_secret=clientSecret', (string)$request->getBody());
43+
return true;
44+
}),
45+
[]
46+
)
47+
->once()
48+
->andReturn(new Response(
49+
status: 200,
50+
headers: [],
51+
body: json_encode(['access_token' => 'accessToken', 'expires_in' => 30, 'token_type' => 'Bearer',]),
52+
));
53+
$api = new ChannelAccessTokenApi($client);
54+
$response = $api->issueStatelessChannelToken(grantType: "client_credentials", clientId: "1234", clientSecret: "clientSecret");
55+
$this->assertEquals('accessToken', $response->getAccessToken());
56+
$this->assertEquals(30, $response->getExpiresIn());
57+
$this->assertEquals('Bearer', $response->getTokenType());
58+
}
59+
}

test/clients/messaging-api/Api/MessagingApiApiTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function testGetFollowers(): void
5050
body: json_encode(['userIds' => ["Uaaaaaaaa...", "Ubbbbbbbb...", "Ucccccccc..."], 'next' => "yANU9IA.."]),
5151
));
5252
$api = new MessagingApiApi($client);
53-
$followers = $api->getFollowers(limit: 99);
53+
$followers = $api->getFollowers(limit: 99);
5454
$this->assertEquals(["Uaaaaaaaa...", "Ubbbbbbbb...", "Ucccccccc..."], $followers->getUserIds());
5555
$this->assertEquals("yANU9IA..", $followers->getNext());
5656
}

0 commit comments

Comments
 (0)