Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
6adeba6
wip
MatanYadaev Feb 18, 2024
3c8f8c2
wip
MatanYadaev Feb 18, 2024
721a2a3
fix postgres ci
MatanYadaev Feb 18, 2024
8df2ae5
fixes
MatanYadaev Feb 18, 2024
b2ab8ce
backward compatibility
MatanYadaev Feb 18, 2024
dcb6a45
fixes
MatanYadaev Feb 19, 2024
d221dbb
fixes
MatanYadaev Feb 19, 2024
c8e1de4
fixes
MatanYadaev Feb 19, 2024
536002d
fixes
MatanYadaev Feb 19, 2024
6b21766
fixes
MatanYadaev Feb 19, 2024
323efc1
fix ci
MatanYadaev Feb 19, 2024
7fc08fe
fix ci
MatanYadaev Feb 19, 2024
ca2f1f1
fixes
MatanYadaev Feb 19, 2024
853d889
fix ci
MatanYadaev Feb 19, 2024
2a543b8
fix coverage
MatanYadaev Feb 19, 2024
6b7d17c
fixes
MatanYadaev Feb 19, 2024
193904e
reduce ci jobs
MatanYadaev Feb 20, 2024
80c4f61
fix mariadb
MatanYadaev Feb 20, 2024
327c483
fix postgres
MatanYadaev Feb 20, 2024
3358295
fix ci
MatanYadaev Feb 20, 2024
fdaabbf
fix ci
MatanYadaev Feb 20, 2024
387db18
fix ci
MatanYadaev Feb 20, 2024
18259c7
fix ci
MatanYadaev Feb 20, 2024
e2bf520
fix ci
MatanYadaev Feb 20, 2024
7840955
fix ci
MatanYadaev Feb 20, 2024
1fdf47b
ci test
MatanYadaev Feb 20, 2024
1f9981b
ci test
MatanYadaev Feb 20, 2024
9c1fe09
fix tests
MatanYadaev Feb 20, 2024
74799c4
fix tests
MatanYadaev Feb 20, 2024
cd70116
fixes
MatanYadaev Feb 20, 2024
c996a28
fixes
MatanYadaev Feb 20, 2024
5549552
fixes
MatanYadaev Feb 20, 2024
d5407c1
ci test
MatanYadaev Feb 20, 2024
8a30e19
ci test
MatanYadaev Feb 20, 2024
1eb07b1
ci test
MatanYadaev Feb 20, 2024
4c96d7d
ci test
MatanYadaev Feb 20, 2024
84f30eb
ci test
MatanYadaev Feb 20, 2024
1388b6f
ci test
MatanYadaev Feb 20, 2024
46275b1
ci test
MatanYadaev Feb 21, 2024
0f607b3
ci test
MatanYadaev Feb 21, 2024
a26616d
ci test
MatanYadaev Feb 21, 2024
85ab828
ci test
MatanYadaev Feb 21, 2024
004c7ff
ci test
MatanYadaev Feb 21, 2024
030d366
ci test
MatanYadaev Feb 21, 2024
77c9b8c
ci test
MatanYadaev Feb 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/pest-coverage.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Tests coverage

on: [ push, pull_request ]
on:
push:
branches:
- master
pull_request:

jobs:
test:
Expand Down
22 changes: 16 additions & 6 deletions .github/workflows/pest.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Tests

on: [ push, pull_request ]
on:
push:
branches:
- master
pull_request:

jobs:
test:
Expand All @@ -13,8 +17,8 @@ jobs:
matrix:
php: [ 8.3, 8.2, 8.1 ]
laravel: [ 10.* ]
db: [ 'mysql:8.0', 'mysql:5.7', 'mariadb:10.9' ]
dependency-version: [ prefer-lowest, prefer-stable ]
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' ]
dependency-version: [ prefer-stable, prefer-lowest ]
include:
- laravel: 10.*
testbench: ^8.0
Comment on lines 17 to 24
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How to run the combinations of PHP 8.2/8.1 and dependency version prefer-lowest only when DB is mysql:8.0?
In other words, all the DBs except MySQL 8 should run with PHP 8.3 and prefer-stable only.

Expand All @@ -25,9 +29,14 @@ jobs:
env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_DATABASE: laravel_eloquent_spatial_test
POSTGRES_DB: laravel_eloquent_spatial_test
POSTGRES_USER: root
POSTGRES_HOST_AUTH_METHOD: trust
ports:
- 3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
- ${{ contains(matrix.db, 'postgis') && '5432' || '3306' }}
options: >-
${{ (contains(matrix.db, 'postgis') && '--health-cmd="pg_isready"') || '--health-cmd="mysqladmin ping"' }}
--health-interval=10s --health-timeout=5s --health-retries=3

steps:
- name: Checkout code
Expand All @@ -46,5 +55,6 @@ jobs:

- name: Execute tests
env:
DB_PORT: ${{ job.services.db.ports['3306'] }}
DB_PORT: ${{ job.services.db.ports[contains(matrix.db, 'postgis') && '5432' || '3306'] }}
DB_CONNECTION: ${{ contains(matrix.db, 'postgis') && 'pgsql' || 'mysql' }}
run: vendor/bin/pest
6 changes: 5 additions & 1 deletion .github/workflows/php-cs-fixer.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Lint

on: [ push, pull_request ]
on:
push:
branches:
- master
pull_request:

jobs:
php-cs-fixer:
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Static code analysis

on: [ push, pull_request ]
on:
push:
branches:
- master
pull_request:

jobs:
phpstan:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.idea
.php-cs-fixer.cache
.phpunit.cache
.phpunit.result.cache
build
composer.lock
Expand Down
7 changes: 6 additions & 1 deletion .run/Test.run.xml → .run/Test - MySQL 8.0.run.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Test" type="PestRunConfigurationType">
<configuration default="false" name="Test - MySQL 8.0" type="PestRunConfigurationType">
<CommandLine>
<envs>
<env name="DB_PORT" value="3307" />
</envs>
</CommandLine>
<option name="pestRunnerSettings">
<PestRunner method="" scope="ConfigurationFile" />
</option>
Expand Down
17 changes: 17 additions & 0 deletions .run/Test - Postgres.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Test - Postgres" type="PestRunConfigurationType">
<CommandLine>
<envs>
<env name="DB_CONNECTION" value="pgsql" />
<env name="DB_PORT" value="5433" />
</envs>
</CommandLine>
<option name="pestRunnerSettings">
<PestRunner method="" scope="ConfigurationFile" />
</option>
<option name="runnerSettings">
<PhpTestRunnerSettings method="" scope="ConfigurationFile" />
</option>
<method v="2" />
</configuration>
</component>
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

**This Laravel package allows you to easily work with spatial data types and functions.**

This package supports MySQL v8, MySQL v5.7, and MariaDB v10.
Supported databases:
- MySQL 5.7/8
- MariaDB 10
- Postgres 12/13/14/15/16 with PostGIS 3.4

## Getting Started

Expand Down Expand Up @@ -177,8 +180,8 @@ echo $londonEyePoint->getName(); // Point

Here are some useful commands for development:

* Run tests: `composer pest`
* Run tests with coverage: `composer pest-coverage`
* Run tests: `composer pest:mysql` or `composer pest:postgres`
* Run tests with coverage: `composer pest-coverage:mysql`
* Perform type checking: `composer phpstan`
* Format your code: `composer php-cs-fixer`

Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@
"scripts": {
"php-cs-fixer": "PHP_CS_FIXER_IGNORE_ENV=1 ./vendor/bin/php-cs-fixer fix --allow-risky=yes",
"phpstan": "./vendor/bin/phpstan analyse --memory-limit=2G",
"pest": "./vendor/bin/pest",
"pest-coverage": "XDEBUG_MODE=coverage ./vendor/bin/pest --coverage --min=100"
"pest:mysql": "DB_PORT=3307 ./vendor/bin/pest",
"pest:postgres": "DB_CONNECTION=pgsql DB_PORT=5433 ./vendor/bin/pest",
"pest-coverage:mysql": "XDEBUG_MODE=coverage DB_PORT=3307 ./vendor/bin/pest --coverage --min=100"
},
"config": {
"sort-packages": true,
Expand Down
17 changes: 15 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3.8'

services:
db:
mysql:
container_name: mysql-laravel-eloquent-spatial
image: mysql:8.0
environment:
Expand All @@ -10,8 +10,21 @@ services:
volumes:
- mysql_data:/var/lib/mysql
ports:
- 3306:3306
- 3307:3306
restart: unless-stopped
postgres:
container_name: postgres-laravel-eloquent-spatial
image: postgis/postgis:16-2
environment:
POSTGRES_DB: laravel_eloquent_spatial_test
POSTGRES_USER: root
POSTGRES_HOST_AUTH_METHOD: trust
volumes:
- postgres_data:/var/lib/postgresql/data
ports:
- 5433:5432
restart: unless-stopped

volumes:
mysql_data:
postgres_data:
11 changes: 11 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ parameters:
- tests
excludePaths:
- src/Factory.php
ignoreErrors:
-
message: '#Call to an undefined method Illuminate\\Database\\Schema\\ColumnDefinition\:\:(isGeometry|projection)\(\)#'
path: tests/database/migrations/*.php
-
message: '#Undefined variable: \$this#'
path: tests/Expectations.php
-
message: '#Call to an undefined method Pest\\Expectation\<.+\>\:\:toBe(InstanceOf)?On(Postgres|Mysql)\(\)#'
path: tests/*.php

level: max
checkMissingIterableValueType: true
checkGenericClassInNonGenericObjectType: false
34 changes: 17 additions & 17 deletions src/AxisOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,40 @@
use Illuminate\Database\MySqlConnection;
use PDO;

/** @codeCoverageIgnore */
class AxisOrder
{
public function __construct()
public static function supported(ConnectionInterface $connection): bool
{
}

public function supported(ConnectionInterface $connection): bool
{
/** @var MySqlConnection $connection */
if ($this->isMariaDb($connection)) {
// @codeCoverageIgnoreStart
if (self::isMariaDb($connection)) {
return false;
// @codeCoverageIgnoreEnd
}

if ($this->isMySql57($connection)) {
// @codeCoverageIgnoreStart
return false;
// @codeCoverageIgnoreEnd
if (self::isMySql8OrAbove($connection)) {
return true;
}

return true;
return false;
}

private function isMariaDb(MySqlConnection $connection): bool
private static function isMariaDb(ConnectionInterface $connection): bool
{
if (! ($connection instanceof MySqlConnection)) {
return false;
}

return $connection->isMaria();
}

private function isMySql57(MySqlConnection $connection): bool
private static function isMySql8OrAbove(ConnectionInterface $connection): bool
{
if (! ($connection instanceof MySqlConnection)) {
return false;
}

/** @var string $version */
$version = $connection->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION);

return version_compare($version, '5.8.0', '<');
return version_compare($version, '8.0.0', '>=');
}
}
22 changes: 22 additions & 0 deletions src/Doctrine/GeographyType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace MatanYadaev\EloquentSpatial\Doctrine;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;

/** @codeCoverageIgnore */
class GeographyType extends Type
{
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
return 'geography';
}

public function getName(): string
{
return 'geography';
}
}
3 changes: 1 addition & 2 deletions src/Doctrine/GeometryCollectionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;

/** @codeCoverageIgnore */
class GeometryCollectionType extends Type
{
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
// @codeCoverageIgnoreStart
return 'geometrycollection';
// @codeCoverageIgnoreEnd
}

public function getName(): string
Expand Down
22 changes: 22 additions & 0 deletions src/Doctrine/GeometryType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace MatanYadaev\EloquentSpatial\Doctrine;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;

/** @codeCoverageIgnore */
class GeometryType extends Type
{
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
return 'geometry';
}

public function getName(): string
{
return 'geometry';
}
}
3 changes: 1 addition & 2 deletions src/Doctrine/LineStringType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;

/** @codeCoverageIgnore */
class LineStringType extends Type
{
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
// @codeCoverageIgnoreStart
return 'linestring';
// @codeCoverageIgnoreEnd
}

public function getName(): string
Expand Down
3 changes: 1 addition & 2 deletions src/Doctrine/MultiLineStringType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;

/** @codeCoverageIgnore */
class MultiLineStringType extends Type
{
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
// @codeCoverageIgnoreStart
return 'multilinestring';
// @codeCoverageIgnoreEnd
}

public function getName(): string
Expand Down
3 changes: 1 addition & 2 deletions src/Doctrine/MultiPointType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;

/** @codeCoverageIgnore */
class MultiPointType extends Type
{
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
// @codeCoverageIgnoreStart
return 'multipoint';
// @codeCoverageIgnoreEnd
}

public function getName(): string
Expand Down
3 changes: 1 addition & 2 deletions src/Doctrine/MultiPolygonType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;

/** @codeCoverageIgnore */
class MultiPolygonType extends Type
{
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
// @codeCoverageIgnoreStart
return 'multipolygon';
// @codeCoverageIgnoreEnd
}

public function getName(): string
Expand Down
Loading