Skip to content

Commit

Permalink
Update test-tooling
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromegamez committed Nov 27, 2023
1 parent 1c8766b commit 060b36b
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 50 deletions.
33 changes: 19 additions & 14 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -31,7 +41,6 @@ jobs:
uses: shivammathur/cache-extensions@v1
with:
php-version: ${{ matrix.php }}
extensions: ${{ env.extensions }}
key: ${{ env.key }}

- name: Cache extensions
Expand All @@ -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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/.build/
/vendor/

/.phpunit.result.cache
/composer.lock
/phpstan.neon
/phpunit.xml
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ composer require beste/latlon-geohash
## Running tests

```shell
composer run tests
composer test
```
35 changes: 18 additions & 17 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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"
}
}
5 changes: 3 additions & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
parameters:
level: max
level: 9

paths:
- src/
- tests/

tmpDir: .build/phpstan/
includes:
- vendor/phpstan/phpstan/conf/bleedingEdge.neon
21 changes: 11 additions & 10 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheResultFile=".build/phpunit/phpunit.cache"
colors="true"
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
beStrictAboutOutputDuringTests="true"
colors="true"
>
<testsuites>
<testsuite name="Tests">
<directory>tests</directory>
</testsuite>
</testsuites>

<coverage processUncoveredFiles="true">
<coverage ignoreDeprecatedCodeUnits="true"/>

<source>
<include>
<directory suffix=".php">src</directory>
<directory>src</directory>
</include>
</coverage>

</source>
</phpunit>
10 changes: 5 additions & 5 deletions tests/GeohashTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function testItHasNeighbours(string $geohash): void
/**
* @return iterable<array<float|int|null>>
*/
public function provideEncodeParameters(): iterable
public static function provideEncodeParameters(): iterable
{
yield [52.51662414148685, 13.378843229770698, null];
yield [52.51662414148685, 13.378843229770698, 1];
Expand All @@ -91,7 +91,7 @@ public function provideEncodeParameters(): iterable
/**
* @return iterable<array<float|int|null>>
*/
public function provideInvalidEncodeParameters(): iterable
public static function provideInvalidEncodeParameters(): iterable
{
yield [-90.01, 0, null];
yield [90.01, 0, null];
Expand All @@ -104,7 +104,7 @@ public function provideInvalidEncodeParameters(): iterable
/**
* @return iterable<string[]>
*/
public function provideGeohashes(): iterable
public static function provideGeohashes(): iterable
{
yield ['u33db2q5t8k9'];
yield ['u33db2q5t8k'];
Expand All @@ -123,15 +123,15 @@ public function provideGeohashes(): iterable
/**
* @return iterable<string[]>
*/
public function provideInvalidGeohashes(): iterable
public static function provideInvalidGeohashes(): iterable
{
yield ['a'];
}

/**
* @return iterable<string, string[]>
*/
public function provideInvalidAdjacentParameters(): iterable
public static function provideInvalidAdjacentParameters(): iterable
{
yield 'invalid direction' => ['u', 'x'];
yield 'empty geohash' => ['', 'n'];
Expand Down

0 comments on commit 060b36b

Please sign in to comment.