diff --git a/.github/workflows/php-checks.yml b/.github/workflows/php-checks.yml index bbfea1ad..b74a7223 100644 --- a/.github/workflows/php-checks.yml +++ b/.github/workflows/php-checks.yml @@ -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 @@ -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 diff --git a/HACKING.md b/HACKING.md index 13fe36da..9060f1d3 100644 --- a/HACKING.md +++ b/HACKING.md @@ -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 -- diff --git a/phpunit.xml b/phpunit.xml index 1f61c451..f8beef29 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -11,5 +11,8 @@ ./src/parser/ + + ./test/ + diff --git a/test/clients/messaging-api/Api/MessagingApiApiTest.php b/test/clients/messaging-api/Api/MessagingApiApiTest.php new file mode 100644 index 00000000..435d6864 --- /dev/null +++ b/test/clients/messaging-api/Api/MessagingApiApiTest.php @@ -0,0 +1,57 @@ +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()); + } +}