Skip to content

Commit e840f42

Browse files
authoredMar 13, 2024··
Support Laravel 11 (#113)
* add laravel 11 to the ci * add version-specific migrations * ignore doctrine on laravel 11 * support testing mariadb locally * update readme * use DatabaseTransactions * change files to 4 spaces * ci fixes * ci fixes * ci fixes * ci fixes * ci fixes * ci fixes * ci fixes * ci fixes * ci fixes * ci fixes * ci fixes * ci fixes * ci fixes
1 parent ce5c27f commit e840f42

20 files changed

+399
-328
lines changed
 

‎.github/workflows/pest-coverage.yml

+37-36
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,42 @@
11
name: Tests coverage
22

33
on:
4-
push:
5-
branches:
6-
- master
7-
pull_request:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
88

99
jobs:
10-
test:
11-
name: Pest - coverage
12-
13-
runs-on: ubuntu-latest
14-
15-
services:
16-
db:
17-
image: mysql:8.0
18-
env:
19-
MYSQL_ALLOW_EMPTY_PASSWORD: yes
20-
MYSQL_DATABASE: laravel_eloquent_spatial_test
21-
ports:
22-
- 3306
23-
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
24-
25-
steps:
26-
- name: Checkout code
27-
uses: actions/checkout@v2
28-
29-
- name: Setup PHP
30-
uses: shivammathur/setup-php@v2
31-
with:
32-
php-version: 8.3
33-
coverage: xdebug
34-
35-
- name: Install dependencies
36-
run: composer install --prefer-dist --no-interaction
37-
38-
- name: Execute tests
39-
env:
40-
DB_PORT: ${{ job.services.db.ports['3306'] }}
41-
run: XDEBUG_MODE=coverage ./vendor/bin/pest --coverage --min=100
10+
test:
11+
name: Pest - coverage
12+
13+
runs-on: ubuntu-latest
14+
15+
services:
16+
db:
17+
image: mysql:8.0
18+
env:
19+
MYSQL_ALLOW_EMPTY_PASSWORD: yes
20+
MYSQL_DATABASE: laravel_eloquent_spatial_test
21+
ports:
22+
- 3306
23+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
24+
25+
steps:
26+
- name: Checkout code
27+
uses: actions/checkout@v2
28+
29+
- name: Setup PHP
30+
uses: shivammathur/setup-php@v2
31+
with:
32+
php-version: 8.3
33+
coverage: xdebug
34+
35+
- name: Install dependencies
36+
run: composer install --prefer-dist --no-interaction
37+
38+
- name: Execute tests
39+
env:
40+
DB_PORT: ${{ job.services.db.ports['3306'] }}
41+
DB_CONNECTION: mysql
42+
run: XDEBUG_MODE=coverage ./vendor/bin/pest --coverage --min=100

‎.github/workflows/pest.yml

+75-55
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,80 @@
11
name: Tests
22

33
on:
4-
push:
5-
branches:
6-
- master
7-
pull_request:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
88

99
jobs:
10-
test:
11-
name: Pest - PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - DB ${{ matrix.db }} ${{ matrix.dependency-version }}
12-
13-
runs-on: ubuntu-latest
14-
15-
strategy:
16-
fail-fast: false
17-
matrix:
18-
php: [ 8.3, 8.2, 8.1 ]
19-
laravel: [ 10.* ]
20-
db: [ 'mysql:8.0', 'mysql:5.7', 'mariadb:10.11', 'postgis/postgis:16-3.4', 'postgis/postgis:15-3.4', 'postgis/postgis:14-3.4', 'postgis/postgis:13-3.4', 'postgis/postgis:12-3.4' ]
21-
dependency-version: [ prefer-stable, prefer-lowest ]
22-
include:
23-
- laravel: 10.*
24-
testbench: ^8.0
25-
26-
services:
27-
db:
28-
image: ${{ matrix.db }}
29-
env:
30-
MYSQL_ALLOW_EMPTY_PASSWORD: yes
31-
MYSQL_DATABASE: laravel_eloquent_spatial_test
32-
POSTGRES_DB: laravel_eloquent_spatial_test
33-
POSTGRES_USER: root
34-
POSTGRES_HOST_AUTH_METHOD: trust
35-
ports:
36-
- ${{ contains(matrix.db, 'postgis') && '5432' || '3306' }}
37-
options: >-
38-
${{ (contains(matrix.db, 'postgis') && '--health-cmd="pg_isready"') || '--health-cmd="mysqladmin ping"' }}
39-
--health-interval=10s --health-timeout=5s --health-retries=3
40-
41-
steps:
42-
- name: Checkout code
43-
uses: actions/checkout@v2
44-
45-
- name: Setup PHP
46-
uses: shivammathur/setup-php@v2
47-
with:
48-
php-version: ${{ matrix.php }}
49-
coverage: none
50-
51-
- name: Install dependencies
52-
run: |
53-
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
54-
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
55-
56-
- name: Execute tests
57-
env:
58-
DB_PORT: ${{ job.services.db.ports[contains(matrix.db, 'postgis') && '5432' || '3306'] }}
59-
DB_CONNECTION: ${{ contains(matrix.db, 'postgis') && 'pgsql' || 'mysql' }}
60-
run: vendor/bin/pest
10+
test:
11+
name: Pest - PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - DB ${{ matrix.db }} ${{ matrix.dependency-version }}
12+
13+
runs-on: ubuntu-latest
14+
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
php: [ 8.3, 8.2, 8.1 ]
19+
laravel: [ 11.*, 10.* ]
20+
db: [ 'mysql:8.0', 'mysql:5.7', 'mariadb:10.11', 'postgis/postgis:16-3.4', 'postgis/postgis:15-3.4', 'postgis/postgis:14-3.4', 'postgis/postgis:13-3.4', 'postgis/postgis:12-3.4' ]
21+
dependency-version: [ prefer-stable ]
22+
include:
23+
- laravel: 10.*
24+
testbench: ^8.0
25+
- laravel: 11.*
26+
testbench: ^9.0
27+
exclude:
28+
- laravel: 11.*
29+
php: 8.1
30+
31+
services:
32+
db:
33+
image: ${{ matrix.db }}
34+
env:
35+
MYSQL_ALLOW_EMPTY_PASSWORD: yes
36+
MYSQL_DATABASE: laravel_eloquent_spatial_test
37+
POSTGRES_DB: laravel_eloquent_spatial_test
38+
POSTGRES_USER: root
39+
POSTGRES_HOST_AUTH_METHOD: trust
40+
ports:
41+
- ${{ contains(matrix.db, 'postgis') && '5432' || '3306' }}
42+
options: >-
43+
${{ (contains(matrix.db, 'postgis') && '--health-cmd="pg_isready"') || '--health-cmd="mysqladmin ping"' }}
44+
--health-interval=10s --health-timeout=5s --health-retries=3
45+
46+
steps:
47+
- name: Checkout code
48+
uses: actions/checkout@v2
49+
50+
- name: Setup PHP
51+
uses: shivammathur/setup-php@v2
52+
with:
53+
php-version: ${{ matrix.php }}
54+
coverage: none
55+
56+
- name: Install dependencies
57+
run: |
58+
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
59+
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
60+
61+
- name: Set DB_CONNECTION env variable (PostGIS)
62+
if: contains(matrix.db, 'postgis')
63+
run: |
64+
echo "DB_CONNECTION=pgsql" >> "$GITHUB_ENV"
65+
66+
- name: Set DB_CONNECTION env variable (MariaDB & Laravel 11)
67+
if: contains(matrix.laravel, '11') && contains(matrix.db, 'mariadb')
68+
run: |
69+
echo "DB_CONNECTION=mariadb" >> "$GITHUB_ENV"
70+
71+
- name: Set DB_COLLATION env variable (Mysql 5.7 & Laravel 11)
72+
if: contains(matrix.laravel, '11') && contains(matrix.db, 'mysql:5.7')
73+
run: |
74+
echo "DB_COLLATION=utf8mb4_unicode_ci" >> "$GITHUB_ENV"
75+
76+
- name: Execute tests
77+
env:
78+
DB_PORT: ${{ job.services.db.ports[contains(matrix.db, 'postgis') && '5432' || '3306'] }}
79+
DB_CONNECTION: ${{ env.DB_CONNECTION || 'mysql' }}
80+
run: vendor/bin/pest

‎.github/workflows/phpstan.yml

+23-23
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
name: Static code analysis
22

33
on:
4-
push:
5-
branches:
6-
- master
7-
pull_request:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
88

99
jobs:
10-
phpstan:
11-
name: PHPStan
10+
phpstan:
11+
name: PHPStan
1212

13-
runs-on: ubuntu-latest
13+
runs-on: ubuntu-latest
1414

15-
strategy:
16-
fail-fast: false
17-
matrix:
18-
php: [ 8.3, 8.2, 8.1 ]
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
php: [ 8.3, 8.2 ]
1919

20-
steps:
21-
- name: Checkout code
22-
uses: actions/checkout@v2
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v2
2323

24-
- name: Setup PHP
25-
uses: shivammathur/setup-php@v2
26-
with:
27-
php-version: ${{ matrix.php }}
28-
coverage: none
24+
- name: Setup PHP
25+
uses: shivammathur/setup-php@v2
26+
with:
27+
php-version: ${{ matrix.php }}
28+
coverage: none
2929

30-
- name: Install dependencies
31-
run: composer install --prefer-dist --no-interaction
30+
- name: Install dependencies
31+
run: composer install --prefer-dist --no-interaction
3232

33-
- name: Run PHPStan
34-
run: ./vendor/bin/phpstan analyse --memory-limit=2G --error-format=github
33+
- name: Run PHPStan
34+
run: ./vendor/bin/phpstan analyse --memory-limit=2G --error-format=github

‎.github/workflows/pint.yml

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
name: Lint
22

33
on:
4-
push:
5-
branches:
6-
- master
7-
pull_request:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
88

99
jobs:
10-
php-cs-fixer:
11-
name: Pint
10+
php-cs-fixer:
11+
name: Pint
1212

13-
runs-on: ubuntu-latest
13+
runs-on: ubuntu-latest
1414

15-
steps:
16-
- name: Checkout code
17-
uses: actions/checkout@v2
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v2
1818

19-
- name: Setup PHP
20-
uses: shivammathur/setup-php@v2
21-
with:
22-
php-version: 8.3
23-
coverage: none
19+
- name: Setup PHP
20+
uses: shivammathur/setup-php@v2
21+
with:
22+
php-version: 8.3
23+
coverage: none
2424

25-
- name: Install dependencies
26-
run: composer install --prefer-dist --no-interaction
25+
- name: Install dependencies
26+
run: composer install --prefer-dist --no-interaction
2727

28-
- name: Run PHP CS Fixer
29-
run: ./vendor/bin/pint --test
28+
- name: Run PHP CS Fixer
29+
run: ./vendor/bin/pint --test
+20-20
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
name: Update Changelog
22

33
on:
4-
release:
5-
types: [ released ]
4+
release:
5+
types: [ released ]
66

77
jobs:
8-
update:
9-
runs-on: ubuntu-latest
8+
update:
9+
runs-on: ubuntu-latest
1010

11-
steps:
12-
- name: Checkout code
13-
uses: actions/checkout@v2
14-
with:
15-
ref: master
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v2
14+
with:
15+
ref: master
1616

17-
- name: Update Changelog
18-
uses: stefanzweifel/changelog-updater-action@v1
19-
with:
20-
latest-version: ${{ github.event.release.name }}
21-
release-notes: ${{ github.event.release.body }}
17+
- name: Update Changelog
18+
uses: stefanzweifel/changelog-updater-action@v1
19+
with:
20+
latest-version: ${{ github.event.release.name }}
21+
release-notes: ${{ github.event.release.body }}
2222

23-
- name: Commit updated CHANGELOG
24-
uses: stefanzweifel/git-auto-commit-action@v4
25-
with:
26-
branch: master
27-
commit_message: Update CHANGELOG
28-
file_pattern: CHANGELOG.md
23+
- name: Commit updated CHANGELOG
24+
uses: stefanzweifel/git-auto-commit-action@v4
25+
with:
26+
branch: master
27+
commit_message: Update CHANGELOG
28+
file_pattern: CHANGELOG.md

‎.run/Fix formatting.run.xml

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<component name="ProjectRunConfigurationManager">
2-
<configuration default="false" name="Fix formatting" type="ComposerRunConfigurationType" factoryName="Composer Script">
3-
<option name="commandLineParameters" value="" />
4-
<option name="pathToComposerJson" value="$PROJECT_DIR$/composer.json" />
5-
<option name="script" value="php-cs-fixer" />
6-
<method v="2" />
7-
</configuration>
8-
</component>
2+
<configuration default="false" name="Fix formatting" type="ComposerRunConfigurationType"
3+
factoryName="Composer Script">
4+
<option name="commandLineParameters" value=""/>
5+
<option name="pathToComposerJson" value="$PROJECT_DIR$/composer.json"/>
6+
<option name="script" value="php-cs-fixer"/>
7+
<method v="2"/>
8+
</configuration>
9+
</component>

‎.run/Static code analysis.run.xml

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<component name="ProjectRunConfigurationManager">
2-
<configuration default="false" name="Static code analysis" type="ComposerRunConfigurationType" factoryName="Composer Script">
3-
<option name="commandLineParameters" value="" />
4-
<option name="pathToComposerJson" value="$PROJECT_DIR$/composer.json" />
5-
<option name="script" value="phpstan" />
6-
<method v="2" />
7-
</configuration>
8-
</component>
2+
<configuration default="false" name="Static code analysis" type="ComposerRunConfigurationType"
3+
factoryName="Composer Script">
4+
<option name="commandLineParameters" value=""/>
5+
<option name="pathToComposerJson" value="$PROJECT_DIR$/composer.json"/>
6+
<option name="script" value="phpstan"/>
7+
<method v="2"/>
8+
</configuration>
9+
</component>

‎.run/Test - MySQL 8.0.run.xml

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<component name="ProjectRunConfigurationManager">
2-
<configuration default="false" name="Test - MySQL 8.0" type="PestRunConfigurationType">
3-
<CommandLine>
4-
<envs>
5-
<env name="DB_PORT" value="3307" />
6-
</envs>
7-
</CommandLine>
8-
<option name="pestRunnerSettings">
9-
<PestRunner method="" scope="ConfigurationFile" />
10-
</option>
11-
<option name="runnerSettings">
12-
<PhpTestRunnerSettings method="" scope="ConfigurationFile" />
13-
</option>
14-
<method v="2" />
15-
</configuration>
16-
</component>
2+
<configuration default="false" name="Test - MySQL 8.0" type="PestRunConfigurationType">
3+
<CommandLine>
4+
<envs>
5+
<env name="DB_PORT" value="3307"/>
6+
</envs>
7+
</CommandLine>
8+
<option name="pestRunnerSettings">
9+
<PestRunner method="" scope="ConfigurationFile"/>
10+
</option>
11+
<option name="runnerSettings">
12+
<PhpTestRunnerSettings method="" scope="ConfigurationFile"/>
13+
</option>
14+
<method v="2"/>
15+
</configuration>
16+
</component>

‎.run/Test - Postgres.run.xml

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<component name="ProjectRunConfigurationManager">
2-
<configuration default="false" name="Test - Postgres" type="PestRunConfigurationType">
3-
<CommandLine>
4-
<envs>
5-
<env name="DB_CONNECTION" value="pgsql" />
6-
<env name="DB_PORT" value="5433" />
7-
</envs>
8-
</CommandLine>
9-
<option name="pestRunnerSettings">
10-
<PestRunner method="" scope="ConfigurationFile" />
11-
</option>
12-
<option name="runnerSettings">
13-
<PhpTestRunnerSettings method="" scope="ConfigurationFile" />
14-
</option>
15-
<method v="2" />
16-
</configuration>
17-
</component>
2+
<configuration default="false" name="Test - Postgres" type="PestRunConfigurationType">
3+
<CommandLine>
4+
<envs>
5+
<env name="DB_CONNECTION" value="pgsql"/>
6+
<env name="DB_PORT" value="5433"/>
7+
</envs>
8+
</CommandLine>
9+
<option name="pestRunnerSettings">
10+
<PestRunner method="" scope="ConfigurationFile"/>
11+
</option>
12+
<option name="runnerSettings">
13+
<PhpTestRunnerSettings method="" scope="ConfigurationFile"/>
14+
</option>
15+
<method v="2"/>
16+
</configuration>
17+
</component>

‎README.md

+5-18
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
**This Laravel package allows you to easily work with spatial data types and functions.**
1010

1111
Supported databases:
12+
1213
- MySQL 5.7/8
1314
- MariaDB 10
1415
- Postgres 12/13/14/15/16 with PostGIS 3.4
@@ -44,8 +45,8 @@ composer require matanyadaev/laravel-eloquent-spatial
4445
Schema::create('places', static function (Blueprint $table) {
4546
$table->id();
4647
$table->string('name')->unique();
47-
$table->point('location')->nullable();
48-
$table->polygon('area')->nullable();
48+
$table->geometry('location', subtype: 'point')->nullable();
49+
$table->geometry('area', subtype: 'polygon')->nullable();
4950
$table->timestamps();
5051
});
5152
}
@@ -57,20 +58,6 @@ composer require matanyadaev/laravel-eloquent-spatial
5758
}
5859
```
5960

60-
* On Postgres, Laravel create spatial columns as `geography` type by default. If you want to use `geometry` type, you can use the `->isGeometry()` method:
61-
62-
```php
63-
$table->point('location')->isGeometry()->nullable();
64-
$table->polygon('area')->isGeometry()->nullable();
65-
```
66-
67-
You can also use the `->projection()` method to set the SRID:
68-
69-
```php
70-
$table->point('location')->projection(Srid::WGS84->value)->nullable(); // 4326 is the default of `geography` type
71-
$table->polygon('area')->isGeometry()->projection(0)->nullable(); // 0 is the default of `geometry` type
72-
```
73-
7461
3. Run the migration:
7562

7663
```bash
@@ -194,10 +181,10 @@ echo $londonEyePoint->getName(); // Point
194181

195182
Here are some useful commands for development:
196183

197-
* Run tests: `composer pest:mysql` or `composer pest:postgres`
184+
* Run tests: `composer pest:mysql`, `composer pest:mariadb`, `composer pest:postgres`
198185
* Run tests with coverage: `composer pest-coverage:mysql`
199186
* Perform type checking: `composer phpstan`
200-
* Format your code: `composer php-cs-fixer`
187+
* Perform code formatting: `composer pint`
201188

202189
Before running tests, make sure to run `docker-compose up` to start the database container.
203190

‎composer.json

+57-57
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,60 @@
11
{
2-
"name": "matanyadaev/laravel-eloquent-spatial",
3-
"description": "Spatial library for Laravel",
4-
"homepage": "https://github.com/matanyadaev/laravel-eloquent-spatial",
5-
"license": "MIT",
6-
"authors": [
7-
{
8-
"name": "Matan Yadaev",
9-
"email": "matan.yed@gmail.com"
2+
"name": "matanyadaev/laravel-eloquent-spatial",
3+
"description": "Spatial library for Laravel",
4+
"homepage": "https://github.com/matanyadaev/laravel-eloquent-spatial",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Matan Yadaev",
9+
"email": "matan.yed@gmail.com"
10+
}
11+
],
12+
"require": {
13+
"php": "^8.1",
14+
"ext-json": "*",
15+
"ext-pdo": "*",
16+
"laravel/framework": "^10.0|^11.0",
17+
"phayes/geophp": "^1.2"
18+
},
19+
"require-dev": {
20+
"doctrine/dbal": "^3.5.3",
21+
"larastan/larastan": "^1.0|^2.4",
22+
"laravel/pint": "^1.14",
23+
"orchestra/testbench": "^8.0|^9.0",
24+
"pestphp/pest": "^2.0",
25+
"pestphp/pest-plugin-laravel": "^2.0"
26+
},
27+
"autoload": {
28+
"psr-4": {
29+
"MatanYadaev\\EloquentSpatial\\": "src"
30+
}
31+
},
32+
"autoload-dev": {
33+
"psr-4": {
34+
"MatanYadaev\\EloquentSpatial\\Tests\\": "tests"
35+
}
36+
},
37+
"scripts": {
38+
"pint": "./vendor/bin/pint",
39+
"phpstan": "./vendor/bin/phpstan analyse --memory-limit=2G",
40+
"pest:mysql": "DB_COLLATION=utf8mb4_unicode_ci DB_CONNECTION=mysql DB_PORT=3307 ./vendor/bin/pest",
41+
"pest:mariadb": "DB_CONNECTION=mariadb DB_PORT=3308 ./vendor/bin/pest",
42+
"pest:postgres": "DB_CONNECTION=pgsql DB_PORT=5433 ./vendor/bin/pest",
43+
"pest-coverage:mysql": "XDEBUG_MODE=coverage DB_CONNECTION=mysql DB_PORT=3307 ./vendor/bin/pest --coverage --min=100"
44+
},
45+
"config": {
46+
"sort-packages": true,
47+
"allow-plugins": {
48+
"pestphp/pest-plugin": true
49+
}
50+
},
51+
"minimum-stability": "dev",
52+
"prefer-stable": true,
53+
"extra": {
54+
"laravel": {
55+
"providers": [
56+
"MatanYadaev\\EloquentSpatial\\EloquentSpatialServiceProvider"
57+
]
58+
}
1059
}
11-
],
12-
"require": {
13-
"php": "^8.1",
14-
"ext-json": "*",
15-
"ext-pdo": "*",
16-
"laravel/framework": "^10.0",
17-
"phayes/geophp": "^1.2"
18-
},
19-
"require-dev": {
20-
"doctrine/dbal": "^3.5.3",
21-
"larastan/larastan": "^1.0|^2.4",
22-
"laravel/pint": "^1.14",
23-
"orchestra/testbench": "^8.0",
24-
"pestphp/pest": "^2.0",
25-
"pestphp/pest-plugin-laravel": "^2.0"
26-
},
27-
"autoload": {
28-
"psr-4": {
29-
"MatanYadaev\\EloquentSpatial\\": "src"
30-
}
31-
},
32-
"autoload-dev": {
33-
"psr-4": {
34-
"MatanYadaev\\EloquentSpatial\\Tests\\": "tests"
35-
}
36-
},
37-
"scripts": {
38-
"pint": "./vendor/bin/pint",
39-
"phpstan": "./vendor/bin/phpstan analyse --memory-limit=2G",
40-
"pest:mysql": "DB_PORT=3307 ./vendor/bin/pest",
41-
"pest:postgres": "DB_CONNECTION=pgsql DB_PORT=5433 ./vendor/bin/pest",
42-
"pest-coverage:mysql": "XDEBUG_MODE=coverage DB_PORT=3307 ./vendor/bin/pest --coverage --min=100"
43-
},
44-
"config": {
45-
"sort-packages": true,
46-
"allow-plugins": {
47-
"dealerdirect/phpcodesniffer-composer-installer": false,
48-
"pestphp/pest-plugin": true
49-
}
50-
},
51-
"minimum-stability": "dev",
52-
"prefer-stable": true,
53-
"extra": {
54-
"laravel": {
55-
"providers": [
56-
"MatanYadaev\\EloquentSpatial\\EloquentSpatialServiceProvider"
57-
]
58-
}
59-
}
6060
}

‎docker-compose.yaml

+37-25
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,42 @@
11
version: '3.8'
22

33
services:
4-
mysql:
5-
container_name: mysql-laravel-eloquent-spatial
6-
image: mysql:8.0
7-
environment:
8-
MYSQL_DATABASE: laravel_eloquent_spatial_test
9-
MYSQL_ALLOW_EMPTY_PASSWORD: true
10-
volumes:
11-
- mysql_data:/var/lib/mysql
12-
ports:
13-
- 3307:3306
14-
restart: unless-stopped
15-
postgres:
16-
container_name: postgres-laravel-eloquent-spatial
17-
image: postgis/postgis:16-3.4
18-
environment:
19-
POSTGRES_DB: laravel_eloquent_spatial_test
20-
POSTGRES_USER: root
21-
POSTGRES_HOST_AUTH_METHOD: trust
22-
volumes:
23-
- postgres_data:/var/lib/postgresql/data
24-
ports:
25-
- 5433:5432
26-
restart: unless-stopped
4+
mysql:
5+
container_name: mysql-laravel-eloquent-spatial
6+
image: mysql:8.0
7+
environment:
8+
MYSQL_DATABASE: laravel_eloquent_spatial_test
9+
MYSQL_ALLOW_EMPTY_PASSWORD: true
10+
volumes:
11+
- mysql_data:/var/lib/mysql
12+
ports:
13+
- 3307:3306
14+
restart: unless-stopped
15+
mariadb:
16+
container_name: mariadb-laravel-eloquent-spatial
17+
image: mariadb:10.11
18+
environment:
19+
MYSQL_DATABASE: laravel_eloquent_spatial_test
20+
MYSQL_ALLOW_EMPTY_PASSWORD: true
21+
volumes:
22+
- mariadb_data:/var/lib/mysql
23+
ports:
24+
- 3308:3306
25+
restart: unless-stopped
26+
postgres:
27+
container_name: postgres-laravel-eloquent-spatial
28+
image: postgis/postgis:16-3.4
29+
environment:
30+
POSTGRES_DB: laravel_eloquent_spatial_test
31+
POSTGRES_USER: root
32+
POSTGRES_HOST_AUTH_METHOD: trust
33+
volumes:
34+
- postgres_data:/var/lib/postgresql/data
35+
ports:
36+
- 5433:5432
37+
restart: unless-stopped
2738

2839
volumes:
29-
mysql_data:
30-
postgres_data:
40+
mysql_data:
41+
mariadb_data:
42+
postgres_data:

‎phpstan.neon

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ parameters:
66
- tests
77
excludePaths:
88
- src/Factory.php
9+
- src/EloquentSpatialServiceProvider.php
10+
- tests/DoctrineTypesTest.php
911
ignoreErrors:
1012
-
11-
message: '#Call to an undefined method Illuminate\\Database\\Schema\\ColumnDefinition\:\:isGeometry\(\)#'
12-
path: tests/database/migrations/*.php
13+
message: '#Call to an undefined method Illuminate\\Database\\Schema\\Blueprint\:\:.+\(\)#'
14+
path: 'tests/database/migrations-laravel-<=10/*.php'
1315
-
1416
message: '#Undefined variable: \$this#'
1517
path: tests/Expectations.php

‎phpunit.xml

+24-24
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,28 @@
99
cacheDirectory=".phpunit.cache"
1010
backupStaticProperties="false"
1111
>
12-
<testsuites>
13-
<testsuite name="Test Suite">
14-
<directory>tests</directory>
15-
</testsuite>
16-
</testsuites>
17-
<coverage>
18-
<report>
19-
<html outputDirectory="build/coverage"/>
20-
<text outputFile="build/coverage.txt"/>
21-
<clover outputFile="build/logs/clover.xml"/>
22-
</report>
23-
</coverage>
24-
<logging>
25-
<junit outputFile="build/report.junit.xml"/>
26-
</logging>
27-
<php>
28-
<env name="DB_DATABASE" value="laravel_eloquent_spatial_test"/>
29-
<env name="DB_USERNAME" value="root"/>
30-
</php>
31-
<source>
32-
<include>
33-
<directory suffix=".php">./src</directory>
34-
</include>
35-
</source>
12+
<testsuites>
13+
<testsuite name="Test Suite">
14+
<directory>tests</directory>
15+
</testsuite>
16+
</testsuites>
17+
<coverage>
18+
<report>
19+
<html outputDirectory="build/coverage"/>
20+
<text outputFile="build/coverage.txt"/>
21+
<clover outputFile="build/logs/clover.xml"/>
22+
</report>
23+
</coverage>
24+
<logging>
25+
<junit outputFile="build/report.junit.xml"/>
26+
</logging>
27+
<php>
28+
<env name="DB_DATABASE" value="laravel_eloquent_spatial_test"/>
29+
<env name="DB_USERNAME" value="root"/>
30+
</php>
31+
<source>
32+
<include>
33+
<directory suffix=".php">./src</directory>
34+
</include>
35+
</source>
3636
</phpunit>

‎src/EloquentSpatialServiceProvider.php

+7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Illuminate\Database\Connection;
88
use Illuminate\Database\DatabaseServiceProvider;
9+
use Illuminate\Foundation\Application;
910
use Illuminate\Support\Facades\DB;
1011
use MatanYadaev\EloquentSpatial\Doctrine\GeographyType;
1112
use MatanYadaev\EloquentSpatial\Doctrine\GeometryCollectionType;
@@ -19,8 +20,13 @@
1920

2021
class EloquentSpatialServiceProvider extends DatabaseServiceProvider
2122
{
23+
// @codeCoverageIgnoreStart
2224
public function boot(): void
2325
{
26+
if (version_compare(Application::VERSION, '11.0.0', '>=')) {
27+
return;
28+
}
29+
2430
/** @var Connection $connection */
2531
$connection = DB::connection();
2632

@@ -49,4 +55,5 @@ protected function registerDoctrineTypes(Connection $connection): void
4955
$connection->registerDoctrineType($class, $type, $type);
5056
}
5157
}
58+
// @codeCoverageIgnoreEnd
5259
}

‎tests/DoctrineTypesTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
use Doctrine\DBAL\Types\Type;
4+
use Illuminate\Foundation\Application;
45
use Illuminate\Support\Facades\DB;
56
use MatanYadaev\EloquentSpatial\Doctrine\GeographyType;
67
use MatanYadaev\EloquentSpatial\Doctrine\GeometryCollectionType;
@@ -62,4 +63,4 @@
6263
$columns = $doctrineSchemaManager->listTableColumns('test_places');
6364

6465
expect($columns[$column]->getType())->toBeInstanceOfOnPostgres($postgresType)->toBeInstanceOfOnMysql($mySqlType);
65-
})->with($dataset);
66+
})->with($dataset)->skip(version_compare(Application::VERSION, '11.0.0', '>='));

‎tests/Pest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

3-
use Illuminate\Foundation\Testing\RefreshDatabase;
3+
use Illuminate\Foundation\Testing\DatabaseTransactions;
44
use MatanYadaev\EloquentSpatial\Tests\TestCase;
55

66
uses(TestCase::class)->in(__DIR__);
77

8-
uses(RefreshDatabase::class)->in(__DIR__);
8+
uses(DatabaseTransactions::class)->in(__DIR__);

‎tests/TestCase.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace MatanYadaev\EloquentSpatial\Tests;
44

5+
use Illuminate\Foundation\Application;
56
use Illuminate\Support\ServiceProvider;
67
use MatanYadaev\EloquentSpatial\EloquentSpatialServiceProvider;
78
use Orchestra\Testbench\TestCase as Orchestra;
@@ -12,7 +13,12 @@ protected function setUp(): void
1213
{
1314
parent::setUp();
1415

15-
$this->loadMigrationsFrom(__DIR__.'/database/migrations');
16+
// @phpstan-ignore-next-line
17+
if (version_compare(Application::VERSION, '11.0.0', '>=')) {
18+
$this->loadMigrationsFrom(__DIR__.'/database/migrations-laravel->=11');
19+
} else {
20+
$this->loadMigrationsFrom(__DIR__.'/database/migrations-laravel-<=10');
21+
}
1622
}
1723

1824
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
class CreateTestPlacesTable extends Migration
8+
{
9+
public function up(): void
10+
{
11+
Schema::create('test_places', function (Blueprint $table): void {
12+
$table->id();
13+
$table->timestamps();
14+
$table->string('name');
15+
$table->string('address');
16+
$table->geometry('point', subtype: 'point')->nullable();
17+
$table->geometry('multi_point', subtype: 'multipoint')->nullable();
18+
$table->geometry('line_string', subtype: 'linestring')->nullable();
19+
$table->geometry('multi_line_string', subtype: 'multilinestring')->nullable();
20+
$table->geometry('polygon', subtype: 'polygon')->nullable();
21+
$table->geometry('multi_polygon', subtype: 'multipolygon')->nullable();
22+
$table->geometry('geometry_collection', subtype: 'geometrycollection')->nullable();
23+
$table->geometry('point_with_line_string_cast', subtype: 'point')->nullable();
24+
$table->decimal('longitude')->nullable();
25+
$table->decimal('latitude')->nullable();
26+
});
27+
}
28+
29+
public function down(): void
30+
{
31+
Schema::dropIfExists('test_places');
32+
}
33+
}

0 commit comments

Comments
 (0)
Please sign in to comment.