Skip to content

Commit de5e04c

Browse files
MatanYadaevMatan Yadaev
andauthored
Migrate testing framework to PestPHP (#44)
* Pest installation * Refactor SpatialBuilderTest * Refactor PointTest * Remove PhpInsights * add test coverage check to CI * fix ci * Refactor GeometryTest * Refactor SpatialBuilderTest * Implement `Geometry@toWkb` method * fix ci * fix ci * Refactor PointTest * fix Co-authored-by: Matan Yadaev <[email protected]>
1 parent 6641e9f commit de5e04c

File tree

13 files changed

+420
-594
lines changed

13 files changed

+420
-594
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Tests coverage
2+
3+
on: [ push, pull_request ]
4+
5+
jobs:
6+
test:
7+
name: Pest - coverage
8+
9+
runs-on: ubuntu-latest
10+
11+
services:
12+
mysql:
13+
image: mysql:8.0
14+
env:
15+
MYSQL_ALLOW_EMPTY_PASSWORD: yes
16+
MYSQL_DATABASE: laravel_eloquent_spatial_test
17+
ports:
18+
- 3306
19+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
20+
21+
steps:
22+
- name: Checkout code
23+
uses: actions/checkout@v2
24+
25+
- name: Setup PHP
26+
uses: shivammathur/setup-php@v2
27+
with:
28+
php-version: 8.1
29+
coverage: xdebug
30+
31+
- name: Install dependencies
32+
run: composer install --prefer-dist --no-interaction
33+
34+
- name: Execute tests
35+
env:
36+
DB_PORT: ${{ job.services.mysql.ports['3306'] }}
37+
run: XDEBUG_MODE=coverage ./vendor/bin/pest --coverage --min=100

.github/workflows/phpunit.yml renamed to .github/workflows/pest.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on: [ push, pull_request ]
44

55
jobs:
66
test:
7-
name: PHPUnit - PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - ${{ matrix.dependency-version }}
7+
name: Pest - PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - ${{ matrix.dependency-version }}
88

99
runs-on: ubuntu-latest
1010

@@ -49,4 +49,4 @@ jobs:
4949
- name: Execute tests
5050
env:
5151
DB_PORT: ${{ job.services.mysql.ports['3306'] }}
52-
run: vendor/bin/phpunit
52+
run: vendor/bin/pest

.github/workflows/phpinsights.yml

Lines changed: 0 additions & 26 deletions
This file was deleted.

composer.json

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@
1818
"require-dev": {
1919
"friendsofphp/php-cs-fixer": "^3.0",
2020
"jubeki/laravel-code-style": "^1.0",
21-
"nunomaduro/phpinsights": "^1.0|^2.0",
2221
"nunomaduro/larastan": "^1.0|^2.0",
2322
"orchestra/testbench": "^6.23|^7.0",
24-
"phpunit/phpunit": "^9.3"
23+
"pestphp/pest": "^1.21",
24+
"pestphp/pest-plugin-laravel": "^1.2"
2525
},
2626
"autoload": {
2727
"psr-4": {
28-
"MatanYadaev\\EloquentSpatial\\": "src",
29-
"MatanYadaev\\EloquentSpatial\\Database\\Factories\\": "database/factories"
28+
"MatanYadaev\\EloquentSpatial\\": "src"
3029
}
3130
},
3231
"autoload-dev": {
@@ -37,15 +36,14 @@
3736
"scripts": {
3837
"php-cs-fixer": "./vendor/bin/php-cs-fixer fix --allow-risky=yes",
3938
"phpstan": "./vendor/bin/phpstan analyse --memory-limit=2G",
40-
"phpunit": "./vendor/bin/phpunit --colors=always",
41-
"phpunit-coverage": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-html coverage",
42-
"phpinsights": "./vendor/bin/phpinsights",
43-
"phpinsights-fix": "./vendor/bin/phpinsights fix"
39+
"pest": "./vendor/bin/pest",
40+
"pest-coverage": "XDEBUG_MODE=coverage ./vendor/bin/pest --coverage --min=100"
4441
},
4542
"config": {
4643
"sort-packages": true,
4744
"allow-plugins": {
48-
"dealerdirect/phpcodesniffer-composer-installer": false
45+
"dealerdirect/phpcodesniffer-composer-installer": false,
46+
"pestphp/pest-plugin": true
4947
}
5048
},
5149
"minimum-stability": "dev",

phpinsights.php

Lines changed: 0 additions & 157 deletions
This file was deleted.

phpstan.neon

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,16 @@ parameters:
66
- tests
77
level: max
88
ignoreErrors:
9+
-
10+
message: '#^Undefined variable\: \$this$#'
11+
path: tests/*.php
12+
-
13+
message: '#^Call to an undefined method Pest\\Expectation\|Pest\\Support\\Extendable\:\:.+\(\)\.$#'
14+
path: tests/*.php
15+
-
16+
message: '#^Access to an undefined property Pest\\Expectation\|Pest\\Support\\Extendable\:\:\$.+\.$#'
17+
path: tests/*.php
918
excludePaths:
1019
- ./src/Factory.php
1120
checkMissingIterableValueType: true
1221
checkGenericClassInNonGenericObjectType: false
13-

src/Objects/Geometry.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace MatanYadaev\EloquentSpatial\Objects;
66

7+
use geoPHP;
78
use Illuminate\Contracts\Database\Eloquent\Castable;
89
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
910
use Illuminate\Contracts\Support\Arrayable;
@@ -13,6 +14,7 @@
1314
use JsonSerializable;
1415
use MatanYadaev\EloquentSpatial\Factory;
1516
use MatanYadaev\EloquentSpatial\GeometryCast;
17+
use WKB as geoPHPWkb;
1618

1719
abstract class Geometry implements Castable, Arrayable, Jsonable, JsonSerializable
1820
{
@@ -29,6 +31,14 @@ public function toJson($options = 0): string
2931
return json_encode($this, $options | JSON_THROW_ON_ERROR);
3032
}
3133

34+
public function toWkb(): string
35+
{
36+
$geoPHPGeometry = geoPHP::load($this->toWkt());
37+
38+
// @phpstan-ignore-next-line
39+
return (new geoPHPWkb)->write($geoPHPGeometry, true);
40+
}
41+
3242
/**
3343
* @param string $wkb
3444
* @return static

tests/GeometryTest.php

Lines changed: 0 additions & 59 deletions
This file was deleted.

0 commit comments

Comments
 (0)