Skip to content

Commit c3d5e8c

Browse files
authored
Add get followers test (#604)
`client.getFollowers(null, 99)` must issue a request url like `/v2/bot/followers/ids?limit=99`. There must not be start as request parameter. This change adds a test to verify this.
1 parent e160927 commit c3d5e8c

File tree

4 files changed

+116
-4
lines changed

4 files changed

+116
-4
lines changed

.github/workflows/php-checks.yml

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,58 @@ on:
66
merge_group:
77

88
jobs:
9+
diff-check:
10+
name: Diff check
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
# Setup
15+
- uses: actions/checkout@v4
16+
with:
17+
submodules: recursive
18+
- name: Update submodules
19+
run: git submodule update --remote --recursive
20+
- uses: actions/setup-node@v4
21+
id: setup_node_id
22+
with:
23+
node-version: 18
24+
- uses: shivammathur/setup-php@v2
25+
with:
26+
php-version: 8.2
27+
28+
# Install openapi-generator-cli
29+
- run: echo "OPENAPI_GENERATOR_VERSION=6.6.0" >> $GITHUB_ENV
30+
- uses: actions/cache@v4
31+
id: openapi-generator-cache
32+
env:
33+
cache-name: openapi-generator-cache
34+
with:
35+
path: ~/bin/openapitools
36+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ env.OPENAPI_GENERATOR_VERSION }}
37+
- if: steps.openapi-generator-cache.outputs.cache-hit != 'true'
38+
run: |
39+
mkdir -p ~/bin/openapitools
40+
curl https://raw.githubusercontent.com/OpenAPITools/openapi-generator/master/bin/utils/openapi-generator-cli.sh > ~/bin/openapitools/openapi-generator-cli
41+
chmod u+x ~/bin/openapitools/openapi-generator-cli
42+
export PATH=$PATH:~/bin/openapitools/
43+
OPENAPI_GENERATOR_VERSION=${{ env.OPENAPI_GENERATOR_VERSION }} openapi-generator-cli version
44+
45+
- name: Generate codes
46+
run: |
47+
export PATH=$PATH:~/bin/openapitools/
48+
bash tools/gen-oas-client.sh
49+
- name: Update document
50+
run: |
51+
wget https://github.com/phpDocumentor/phpDocumentor/releases/download/v3.3.1/phpDocumentor.phar
52+
php phpDocumentor.phar run -d src -t docs
53+
- run: |
54+
diff=$(git --no-pager diff --name-only HEAD)
55+
echo "DIFF_IS_EMPTY=$([[ -z "$diff" ]] && echo 'true' || echo 'false')" >> $GITHUB_ENV
56+
echo "CURRENT_DATETIME=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV
57+
- if: ${{ env.DIFF_IS_EMPTY != 'true' }}
58+
run: |
59+
echo "There are changes from the auto-generated files by OAS. Please run diff-check.yml and merge the PR generated by it first."
60+
exit 1
961
tests:
1062
name: Run checks on PHP ${{ matrix.php }}
1163
runs-on: ubuntu-latest
@@ -86,4 +138,4 @@ jobs:
86138

87139
- name: Run unit tests
88140
if: matrix.analysis
89-
run: ./vendor/bin/phpunit --test-suffix=Test.php
141+
run: ./vendor/bin/phpunit --test-suffix=Test.php --testdox

HACKING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ Run `make` or `make check` to check comprehensively. Following tests will run.
88

99
- [PHPUnit](https://github.com/sebastianbergmann/phpunit) `make test`
1010
- Copyright check `make copyright`
11-
- [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) `make cs`
12-
- [PHPMD](https://phpmd.org/) `make md`
13-
- [PHPStan](https://phpstan.org/) `make stan`
11+
- [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) `make phpcs`
12+
- [PHPMD](https://phpmd.org/) `make phpmd`
13+
- [PHPStan](https://phpstan.org/) `make phpstan`
1414

1515
Pull request policy
1616
--

phpunit.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@
1111
<testsuite name="Parser">
1212
<directory suffix="Test.php">./src/parser/</directory>
1313
</testsuite>
14+
<testsuite name="Test">
15+
<directory suffix="Test.php">./test/</directory>
16+
</testsuite>
1417
</testsuites>
1518
</phpunit>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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\MessagingApi\Api;
19+
20+
use GuzzleHttp\ClientInterface;
21+
use GuzzleHttp\Psr7\Request;
22+
use GuzzleHttp\Psr7\Response;
23+
use LINE\Clients\MessagingApi\Api\MessagingApiApi;
24+
use Mockery;
25+
use PHPUnit\Framework\TestCase;
26+
27+
class MessagingApiApiTest extends TestCase
28+
{
29+
protected function setUp(): void
30+
{
31+
parent::setUp();
32+
}
33+
34+
public function testGetFollowers(): void
35+
{
36+
$client = Mockery::mock(ClientInterface::class);
37+
$client->shouldReceive('send')
38+
->with(
39+
Mockery::on(function (Request $request) {
40+
$this->assertEquals('GET', $request->getMethod());
41+
$this->assertEquals('https://api.line.me/v2/bot/followers/ids?limit=99', (string)$request->getUri());
42+
return true;
43+
}),
44+
[]
45+
)
46+
->once()
47+
->andReturn(new Response(
48+
status: 200,
49+
headers: [],
50+
body: json_encode(['userIds' => ["Uaaaaaaaa...", "Ubbbbbbbb...", "Ucccccccc..."], 'next' => "yANU9IA.."]),
51+
));
52+
$api = new MessagingApiApi($client);
53+
$followers = $api->getFollowers(limit: 99);
54+
$this->assertEquals(["Uaaaaaaaa...", "Ubbbbbbbb...", "Ucccccccc..."], $followers->getUserIds());
55+
$this->assertEquals("yANU9IA..", $followers->getNext());
56+
}
57+
}

0 commit comments

Comments
 (0)