Skip to content

Commit

Permalink
Add get followers test (#604)
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
eucyt authored Aug 9, 2024
1 parent e160927 commit c3d5e8c
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 4 deletions.
54 changes: 53 additions & 1 deletion .github/workflows/php-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,58 @@ on:
merge_group:

jobs:
diff-check:
name: Diff check
runs-on: ubuntu-latest

steps:
# Setup
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Update submodules
run: git submodule update --remote --recursive
- uses: actions/setup-node@v4
id: setup_node_id
with:
node-version: 18
- uses: shivammathur/setup-php@v2
with:
php-version: 8.2

# Install openapi-generator-cli
- run: echo "OPENAPI_GENERATOR_VERSION=6.6.0" >> $GITHUB_ENV
- uses: actions/cache@v4
id: openapi-generator-cache
env:
cache-name: openapi-generator-cache
with:
path: ~/bin/openapitools
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ env.OPENAPI_GENERATOR_VERSION }}
- if: steps.openapi-generator-cache.outputs.cache-hit != 'true'
run: |
mkdir -p ~/bin/openapitools
curl https://raw.githubusercontent.com/OpenAPITools/openapi-generator/master/bin/utils/openapi-generator-cli.sh > ~/bin/openapitools/openapi-generator-cli
chmod u+x ~/bin/openapitools/openapi-generator-cli
export PATH=$PATH:~/bin/openapitools/
OPENAPI_GENERATOR_VERSION=${{ env.OPENAPI_GENERATOR_VERSION }} openapi-generator-cli version
- name: Generate codes
run: |
export PATH=$PATH:~/bin/openapitools/
bash tools/gen-oas-client.sh
- name: Update document
run: |
wget https://github.com/phpDocumentor/phpDocumentor/releases/download/v3.3.1/phpDocumentor.phar
php phpDocumentor.phar run -d src -t docs
- run: |
diff=$(git --no-pager diff --name-only HEAD)
echo "DIFF_IS_EMPTY=$([[ -z "$diff" ]] && echo 'true' || echo 'false')" >> $GITHUB_ENV
echo "CURRENT_DATETIME=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV
- if: ${{ env.DIFF_IS_EMPTY != 'true' }}
run: |
echo "There are changes from the auto-generated files by OAS. Please run diff-check.yml and merge the PR generated by it first."
exit 1
tests:
name: Run checks on PHP ${{ matrix.php }}
runs-on: ubuntu-latest
Expand Down Expand Up @@ -86,4 +138,4 @@ jobs:

- name: Run unit tests
if: matrix.analysis
run: ./vendor/bin/phpunit --test-suffix=Test.php
run: ./vendor/bin/phpunit --test-suffix=Test.php --testdox
6 changes: 3 additions & 3 deletions HACKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ Run `make` or `make check` to check comprehensively. Following tests will run.

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

Pull request policy
--
Expand Down
3 changes: 3 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@
<testsuite name="Parser">
<directory suffix="Test.php">./src/parser/</directory>
</testsuite>
<testsuite name="Test">
<directory suffix="Test.php">./test/</directory>
</testsuite>
</testsuites>
</phpunit>
57 changes: 57 additions & 0 deletions test/clients/messaging-api/Api/MessagingApiApiTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
/**
* Copyright 2024 LINE Corporation
*
* LINE Corporation licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

namespace LINE\Tests\Clients\MessagingApi\Api;

use GuzzleHttp\ClientInterface;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use LINE\Clients\MessagingApi\Api\MessagingApiApi;
use Mockery;
use PHPUnit\Framework\TestCase;

class MessagingApiApiTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
}

public function testGetFollowers(): void
{
$client = Mockery::mock(ClientInterface::class);
$client->shouldReceive('send')
->with(
Mockery::on(function (Request $request) {
$this->assertEquals('GET', $request->getMethod());
$this->assertEquals('https://api.line.me/v2/bot/followers/ids?limit=99', (string)$request->getUri());
return true;
}),
[]
)
->once()
->andReturn(new Response(
status: 200,
headers: [],
body: json_encode(['userIds' => ["Uaaaaaaaa...", "Ubbbbbbbb...", "Ucccccccc..."], 'next' => "yANU9IA.."]),
));
$api = new MessagingApiApi($client);
$followers = $api->getFollowers(limit: 99);
$this->assertEquals(["Uaaaaaaaa...", "Ubbbbbbbb...", "Ucccccccc..."], $followers->getUserIds());
$this->assertEquals("yANU9IA..", $followers->getNext());
}
}

0 comments on commit c3d5e8c

Please sign in to comment.