|
| 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 | +} |
0 commit comments