From 060b36b8a4436643009c8ff9f5fbc7ede674b7ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Gamez?= Date: Mon, 27 Nov 2023 12:45:43 +0100 Subject: [PATCH] Update test-tooling --- .github/workflows/tests.yml | 33 +++++++++++++++++++-------------- .gitignore | 2 +- README.md | 2 +- composer.json | 35 ++++++++++++++++++----------------- phpstan.neon.dist | 5 +++-- phpunit.xml.dist | 21 +++++++++++---------- tests/GeohashTest.php | 10 +++++----- 7 files changed, 58 insertions(+), 50 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 87b7130..399e20e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -2,14 +2,24 @@ name: Tests on: pull_request: + paths: + - 'src/**' + - 'tests/**' + - '.github/workflows/tests.yml' + - 'composer.json' push: - branches: - - 'main' + branches: ['main'] + paths: + - 'src/**' + - 'tests/**' + - '.github/workflows/tests.yml' + - 'composer.json' + workflow_dispatch: jobs: tests: name: PHP ${{ matrix.php }} - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest strategy: matrix: @@ -31,7 +41,6 @@ jobs: uses: shivammathur/cache-extensions@v1 with: php-version: ${{ matrix.php }} - extensions: ${{ env.extensions }} key: ${{ env.key }} - name: Cache extensions @@ -45,22 +54,18 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} - extensions: ${{ env.extensions }} tools: composer, pecl coverage: xdebug - env: - COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} - uses: "ramsey/composer-install@v2" - - name: Setup problem matchers for PHP - run: echo "::add-matcher::${{ runner.tool_cache }}/php.json" + - name: Setup Problem Matchers + run: | + echo "::add-matcher::${{ runner.tool_cache }}/php.json" + echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - name: Run PHPStan - run: vendor/bin/phpstan analyse - - - name: Setup Problem Matchers for PHPUnit - run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + run: vendor/bin/phpstan - name: Run PHPUnit - run: vendor/bin/phpunit --testdox --coverage-text + run: XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-text diff --git a/.gitignore b/.gitignore index 9fdd15b..7ee4684 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ -/.build/ /vendor/ +/.phpunit.result.cache /composer.lock /phpstan.neon /phpunit.xml diff --git a/README.md b/README.md index 64faa20..3475550 100644 --- a/README.md +++ b/README.md @@ -44,5 +44,5 @@ composer require beste/latlon-geohash ## Running tests ```shell -composer run tests +composer test ``` diff --git a/composer.json b/composer.json index abe89bf..eca634a 100644 --- a/composer.json +++ b/composer.json @@ -14,11 +14,11 @@ "php": "~8.1.0 || ~8.2.0 || ~8.3.0" }, "require-dev": { - "phpstan/extension-installer": "^1.1", - "phpstan/phpstan": "^1.4", - "phpstan/phpstan-phpunit": "^1.0", - "phpstan/phpstan-strict-rules": "^1.1", - "phpunit/phpunit": "^9.5.11" + "phpstan/extension-installer": "^1.3.1", + "phpstan/phpstan": "^1.10.44", + "phpstan/phpstan-phpunit": "^1.3.15", + "phpstan/phpstan-strict-rules": "^1.5.2", + "phpunit/phpunit": "^10.4.2" }, "autoload": { "files": ["src/Geohash.php"] @@ -35,18 +35,19 @@ } }, "scripts": { - "clean": "rm -rf .build && mkdir .build", - "phpstan": "vendor/bin/phpstan analyse", - "phpunit": "vendor/bin/phpunit", - "tests": [ - "@phpstan", - "@phpunit" + "analyse": [ + "XDEBUG_MODE=off vendor/bin/phpstan" + ], + "analyze": "@analyse", + "test": [ + "@analyse", + "@test-units" + ], + "test-units": [ + "vendor/bin/phpunit" + ], + "test-coverage": [ + "XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-text" ] - }, - "scripts-descriptions": { - "clean": "Recreates ", - "phpstan": "Runs static analysis with PHPStan", - "phpunit": "Runs tests with PHPUnit", - "tests": "Runs static analysis and test suites" } } diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 74bf1cb..ff2e0e4 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,8 +1,9 @@ parameters: - level: max + level: 9 paths: - src/ - tests/ - tmpDir: .build/phpstan/ +includes: + - vendor/phpstan/phpstan/conf/bleedingEdge.neon diff --git a/phpunit.xml.dist b/phpunit.xml.dist index b8b599e..d1b608b 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,9 +1,9 @@ - - + @@ -11,10 +11,11 @@ - + + + - src + src - - + diff --git a/tests/GeohashTest.php b/tests/GeohashTest.php index e957104..d9520fd 100644 --- a/tests/GeohashTest.php +++ b/tests/GeohashTest.php @@ -68,7 +68,7 @@ public function testItHasNeighbours(string $geohash): void /** * @return iterable> */ - public function provideEncodeParameters(): iterable + public static function provideEncodeParameters(): iterable { yield [52.51662414148685, 13.378843229770698, null]; yield [52.51662414148685, 13.378843229770698, 1]; @@ -91,7 +91,7 @@ public function provideEncodeParameters(): iterable /** * @return iterable> */ - public function provideInvalidEncodeParameters(): iterable + public static function provideInvalidEncodeParameters(): iterable { yield [-90.01, 0, null]; yield [90.01, 0, null]; @@ -104,7 +104,7 @@ public function provideInvalidEncodeParameters(): iterable /** * @return iterable */ - public function provideGeohashes(): iterable + public static function provideGeohashes(): iterable { yield ['u33db2q5t8k9']; yield ['u33db2q5t8k']; @@ -123,7 +123,7 @@ public function provideGeohashes(): iterable /** * @return iterable */ - public function provideInvalidGeohashes(): iterable + public static function provideInvalidGeohashes(): iterable { yield ['a']; } @@ -131,7 +131,7 @@ public function provideInvalidGeohashes(): iterable /** * @return iterable */ - public function provideInvalidAdjacentParameters(): iterable + public static function provideInvalidAdjacentParameters(): iterable { yield 'invalid direction' => ['u', 'x']; yield 'empty geohash' => ['', 'n'];