diff --git a/.gitignore b/.gitignore
index 52370244..30009528 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,4 +2,6 @@
vendor/
composer.lock
_db/
-build/
\ No newline at end of file
+build/
+_db*
+.phpunit.result.cache
\ No newline at end of file
diff --git a/Makefile b/Makefile
index 62db4599..e2286c82 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-V=8.0
+V=5.7
DB_DIR=$(shell pwd)/_db-$(V)
mV=10.3
mDB_DIR=$(shell pwd)/_db-$(mV)
@@ -6,7 +6,7 @@ mDB_DIR=$(shell pwd)/_db-$(mV)
start_db:
@echo Starting MySQL $(V)
docker run --rm -d --name spatial-mysql \
- -p 3306:3306 \
+ -p 3309:3306 \
-v $(DB_DIR):/var/lib/mysql \
-e MYSQL_DATABASE=spatial_test \
-e MYSQL_ALLOW_EMPTY_PASSWORD=yes \
diff --git a/composer.json b/composer.json
index 4451cb50..dfd898fd 100644
--- a/composer.json
+++ b/composer.json
@@ -15,19 +15,19 @@
}
],
"require": {
- "php": ">=7.3",
+ "php": ">=8.0",
"ext-pdo": "*",
"ext-json": "*",
- "illuminate/database": "^8.0",
+ "illuminate/database": ">=8.0",
"geo-io/wkb-parser": "^1.0",
"jmikola/geojson": "^1.0"
},
"require-dev": {
- "phpunit/phpunit": "~6.5",
- "laravel/laravel": "^8.0",
+ "phpunit/phpunit": ">=6.5",
+ "laravel/laravel": ">=8.0",
"doctrine/dbal": "^2.5",
"laravel/browser-kit-testing": "^2.0",
- "mockery/mockery": "^1.3"
+ "mockery/mockery": ">=1.3"
},
"autoload": {
"psr-4": {
@@ -42,7 +42,7 @@
},
"extra": {
"branch-alias": {
- "dev-master": "4.0.x-dev"
+ "dev-master": "5.0.x-dev"
},
"laravel": {
"providers": [
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 1456a6ac..05462e00 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -1,45 +1,37 @@
-
-
-
- ./tests/Unit
-
-
- ./tests/Integration
-
-
-
-
+
+
+
+ ./src
+
+
+
+
+
+
+
+ ./tests/Unit
+
+
+ ./tests/Integration
+
+
+
+
-
-
-
- ./src
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/phpunit.xml.dist.bak b/phpunit.xml.dist.bak
new file mode 100644
index 00000000..1456a6ac
--- /dev/null
+++ b/phpunit.xml.dist.bak
@@ -0,0 +1,45 @@
+
+
+
+
+ ./tests/Unit
+
+
+ ./tests/Integration
+
+
+
+
+
+
+
+
+ ./src
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Eloquent/BaseBuilder.php b/src/Eloquent/BaseBuilder.php
index a2130840..9ad40337 100644
--- a/src/Eloquent/BaseBuilder.php
+++ b/src/Eloquent/BaseBuilder.php
@@ -9,7 +9,7 @@ class BaseBuilder extends QueryBuilder
public function cleanBindings(array $bindings)
{
$spatialBindings = [];
- foreach ($bindings as &$binding) {
+ foreach ($bindings as $binding) {
if ($binding instanceof SpatialExpression) {
$spatialBindings[] = $binding->getSpatialValue();
$spatialBindings[] = $binding->getSrid();
diff --git a/src/Eloquent/SpatialExpression.php b/src/Eloquent/SpatialExpression.php
index 9224af0f..3358633a 100644
--- a/src/Eloquent/SpatialExpression.php
+++ b/src/Eloquent/SpatialExpression.php
@@ -8,7 +8,7 @@ class SpatialExpression extends Expression
{
public function getValue()
{
- return "ST_GeomFromText(?, ?, 'axis-order=long-lat')";
+ return "ST_GeomFromText('?')";
}
public function getSpatialValue()
diff --git a/src/Types/GeometryCollection.php b/src/Types/GeometryCollection.php
index 35f093f7..288ef7a8 100755
--- a/src/Types/GeometryCollection.php
+++ b/src/Types/GeometryCollection.php
@@ -11,6 +11,7 @@
use Illuminate\Contracts\Support\Arrayable;
use InvalidArgumentException;
use IteratorAggregate;
+use Traversable;
class GeometryCollection extends Geometry implements IteratorAggregate, ArrayAccess, Arrayable, Countable
{
@@ -82,27 +83,27 @@ public static function fromString($wktArgument, $srid = 0)
}, $geometry_strings), $srid);
}
- public function toArray()
+ public function toArray(): array
{
return $this->items;
}
- public function getIterator()
+ public function getIterator(): Traversable
{
return new ArrayIterator($this->items);
}
- public function offsetExists($offset)
+ public function offsetExists(mixed $offset): bool
{
return isset($this->items[$offset]);
}
- public function offsetGet($offset)
+ public function offsetGet(mixed $offset): mixed
{
return $this->offsetExists($offset) ? $this->items[$offset] : null;
}
- public function offsetSet($offset, $value)
+ public function offsetSet($offset, $value): void
{
$this->validateItemType($value);
@@ -113,12 +114,12 @@ public function offsetSet($offset, $value)
}
}
- public function offsetUnset($offset)
+ public function offsetUnset(mixed $offset): void
{
unset($this->items[$offset]);
}
- public function count()
+ public function count(): int
{
return count($this->items);
}
@@ -144,9 +145,9 @@ public static function fromJson($geoJson)
/**
* Convert to GeoJson GeometryCollection that is jsonable to GeoJSON.
*
- * @return \GeoJson\Geometry\GeometryCollection
+ * @return mixed|\GeoJson\Geometry\GeometryCollection
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$geometries = [];
foreach ($this->items as $geometry) {
diff --git a/src/Types/LineString.php b/src/Types/LineString.php
index 1cc4a410..09017149 100644
--- a/src/Types/LineString.php
+++ b/src/Types/LineString.php
@@ -65,7 +65,7 @@ public static function fromJson($geoJson)
*
* @return \GeoJson\Geometry\LineString
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$points = [];
foreach ($this->items as $point) {
diff --git a/src/Types/MultiLineString.php b/src/Types/MultiLineString.php
index 62c4d576..02debf41 100644
--- a/src/Types/MultiLineString.php
+++ b/src/Types/MultiLineString.php
@@ -49,7 +49,7 @@ public function __toString()
}, $this->getLineStrings()));
}
- public function offsetSet($offset, $value)
+ public function offsetSet($offset, $value): void
{
$this->validateItemType($value);
@@ -83,7 +83,7 @@ public static function fromJson($geoJson)
*
* @return \GeoJson\Geometry\MultiLineString
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$lineStrings = [];
diff --git a/src/Types/MultiPoint.php b/src/Types/MultiPoint.php
index 752967eb..eb98cfd8 100644
--- a/src/Types/MultiPoint.php
+++ b/src/Types/MultiPoint.php
@@ -69,7 +69,7 @@ public static function fromJson($geoJson)
*
* @return \GeoJson\Geometry\MultiPoint
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$points = [];
foreach ($this->items as $point) {
diff --git a/src/Types/MultiPolygon.php b/src/Types/MultiPolygon.php
index cdea3a9c..4f317635 100644
--- a/src/Types/MultiPolygon.php
+++ b/src/Types/MultiPolygon.php
@@ -89,7 +89,7 @@ protected static function assembleParts(array $parts)
return $polygons;
}
- public function offsetSet($offset, $value)
+ public function offsetSet($offset, $value): void
{
$this->validateItemType($value);
@@ -127,7 +127,7 @@ public static function fromJson($geoJson)
*
* @return \GeoJson\Geometry\MultiPolygon
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$polygons = [];
foreach ($this->items as $polygon) {
diff --git a/src/Types/Point.php b/src/Types/Point.php
index d424ec5e..860d25e8 100644
--- a/src/Types/Point.php
+++ b/src/Types/Point.php
@@ -92,7 +92,7 @@ public static function fromJson($geoJson)
*
* @return \GeoJson\Geometry\Point
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
return new GeoJsonPoint([$this->getLng(), $this->getLat()]);
}
diff --git a/src/Types/PointCollection.php b/src/Types/PointCollection.php
index 30d1b8de..862e80aa 100755
--- a/src/Types/PointCollection.php
+++ b/src/Types/PointCollection.php
@@ -21,7 +21,7 @@ public function toPairList()
}, $this->items));
}
- public function offsetSet($offset, $value)
+ public function offsetSet($offset, $value): void
{
$this->validateItemType($value);
diff --git a/src/Types/Polygon.php b/src/Types/Polygon.php
index 9c10cecc..acd6da10 100644
--- a/src/Types/Polygon.php
+++ b/src/Types/Polygon.php
@@ -40,7 +40,7 @@ public static function fromJson($geoJson)
*
* @return \GeoJson\Geometry\Polygon
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$linearRings = [];
foreach ($this->items as $lineString) {
diff --git a/tests/Integration/IntegrationBaseTestCase.php b/tests/Integration/IntegrationBaseTestCase.php
index 04634734..ebb34353 100644
--- a/tests/Integration/IntegrationBaseTestCase.php
+++ b/tests/Integration/IntegrationBaseTestCase.php
@@ -1,5 +1,6 @@
register(SpatialServiceProvider::class);
- $app->make('Illuminate\Contracts\Console\Kernel')->bootstrap();
+ $app->make(Kernel::class)->bootstrap();
$app['config']->set('database.default', 'mysql');
$app['config']->set('database.connections.mysql.host', env('DB_HOST'));
@@ -44,7 +45,7 @@ public function createApplication()
*
* @return void
*/
- public function setUp()
+ public function setUp(): void
{
parent::setUp();
@@ -59,7 +60,7 @@ public function setUp()
//});
}
- public function tearDown()
+ public function tearDown(): void
{
$this->onMigrations(function ($migrationClass) {
(new $migrationClass())->down();
diff --git a/tests/Integration/Migrations/CreateTables.php b/tests/Integration/Migrations/CreateTables.php
index fdff4f58..0b629ee1 100644
--- a/tests/Integration/Migrations/CreateTables.php
+++ b/tests/Integration/Migrations/CreateTables.php
@@ -6,6 +6,13 @@
class CreateLocationTable extends Migration
{
+ private \Illuminate\Database\Schema\Builder $schema;
+
+ public function __construct()
+ {
+ $this->schema = app('db')->getSchemaBuilder();
+ }
+
/**
* Run the migrations.
*
@@ -13,39 +20,45 @@ class CreateLocationTable extends Migration
*/
public function up()
{
- Schema::create('geometry', function (Blueprint $table) {
- $table->charset = 'utf8mb4';
- $table->collation = 'utf8mb4_unicode_ci';
- $table->increments('id');
- $table->geometry('geo')->default(null)->nullable();
- $table->point('location'); // required to be not null in order to add an index
- $table->lineString('line')->default(null)->nullable();
- $table->polygon('shape')->default(null)->nullable();
- $table->multiPoint('multi_locations')->default(null)->nullable();
- $table->multiLineString('multi_lines')->default(null)->nullable();
- $table->multiPolygon('multi_shapes')->default(null)->nullable();
- $table->geometryCollection('multi_geometries')->default(null)->nullable();
- $table->timestamps();
- });
+ if (!$this->schema->hasTable('geometry')) {
+ $this->schema->create('geometry', function (Blueprint $table) {
+ $table->charset = 'utf8mb4';
+ $table->collation = 'utf8mb4_unicode_ci';
+ $table->increments('id');
+ $table->geometry('geo')->default(null)->nullable();
+ $table->point('location'); // required to be not null in order to add an index
+ $table->lineString('line')->default(null)->nullable();
+ $table->polygon('shape')->default(null)->nullable();
+ $table->multiPoint('multi_locations')->default(null)->nullable();
+ $table->multiLineString('multi_lines')->default(null)->nullable();
+ $table->multiPolygon('multi_shapes')->default(null)->nullable();
+ $table->geometryCollection('multi_geometries')->default(null)->nullable();
+ $table->timestamps();
+ });
+ }
- Schema::create('no_spatial_fields', function (Blueprint $table) {
- $table->increments('id');
- $table->geometry('geometry')->default(null)->nullable();
- });
+ if (!$this->schema->hasTable('no_spatial_fields')) {
+ $this->schema->create('no_spatial_fields', function (Blueprint $table) {
+ $table->increments('id');
+ $table->geometry('geometry')->default(null)->nullable();
+ });
+ }
- Schema::create('with_srid', function (Blueprint $table) {
- $table->charset = 'utf8mb4';
- $table->collation = 'utf8mb4_unicode_ci';
- $table->increments('id');
- $table->geometry('geo', 3857)->default(null)->nullable();
- $table->point('location', 3857)->default(null)->nullable();
- $table->lineString('line', 3857)->default(null)->nullable();
- $table->polygon('shape', 3857)->default(null)->nullable();
- $table->multiPoint('multi_locations', 3857)->default(null)->nullable();
- $table->multiLineString('multi_lines', 3857)->default(null)->nullable();
- $table->multiPolygon('multi_shapes', 3857)->default(null)->nullable();
- $table->geometryCollection('multi_geometries', 3857)->default(null)->nullable();
- });
+ if (!$this->schema->hasTable('with_srid')) {
+ $this->schema->create('with_srid', function (Blueprint $table) {
+ $table->charset = 'utf8mb4';
+ $table->collation = 'utf8mb4_unicode_ci';
+ $table->increments('id');
+ $table->geometry('geo', 3857)->default(null)->nullable();
+ $table->point('location', 3857)->default(null)->nullable();
+ $table->lineString('line', 3857)->default(null)->nullable();
+ $table->polygon('shape', 3857)->default(null)->nullable();
+ $table->multiPoint('multi_locations', 3857)->default(null)->nullable();
+ $table->multiLineString('multi_lines', 3857)->default(null)->nullable();
+ $table->multiPolygon('multi_shapes', 3857)->default(null)->nullable();
+ $table->geometryCollection('multi_geometries', 3857)->default(null)->nullable();
+ });
+ }
}
/**
@@ -55,8 +68,8 @@ public function up()
*/
public function down()
{
- Schema::drop('geometry');
- Schema::drop('no_spatial_fields');
- Schema::drop('with_srid');
+ $this->schema->dropIfExists('geometry');
+ $this->schema->dropIfExists('no_spatial_fields');
+ $this->schema->dropIfExists('with_srid');
}
}
diff --git a/tests/Unit/BaseTestCase.php b/tests/Unit/BaseTestCase.php
index 219f737d..215690ef 100644
--- a/tests/Unit/BaseTestCase.php
+++ b/tests/Unit/BaseTestCase.php
@@ -4,7 +4,7 @@
abstract class BaseTestCase extends TestCase
{
- public function tearDown()
+ public function tearDown(): void
{
Mockery::close();
}
diff --git a/tests/Unit/Eloquent/BuilderTest.php b/tests/Unit/Eloquent/BuilderTest.php
index d9a12a55..5d88ba19 100644
--- a/tests/Unit/Eloquent/BuilderTest.php
+++ b/tests/Unit/Eloquent/BuilderTest.php
@@ -20,7 +20,7 @@ class BuilderTest extends BaseTestCase
protected $builder;
protected $queryBuilder;
- protected function setUp()
+ protected function setUp(): void
{
$connection = Mockery::mock(MysqlConnection::class)->makePartial();
$grammar = Mockery::mock(MySqlGrammar::class)->makePartial();
diff --git a/tests/Unit/Eloquent/SpatialTraitTest.php b/tests/Unit/Eloquent/SpatialTraitTest.php
index 8ece7d25..76d67b19 100644
--- a/tests/Unit/Eloquent/SpatialTraitTest.php
+++ b/tests/Unit/Eloquent/SpatialTraitTest.php
@@ -21,13 +21,13 @@ class SpatialTraitTest extends BaseTestCase
*/
protected $queries;
- public function setUp()
+ public function setUp(): void
{
$this->model = new TestModel();
$this->queries = &$this->model->getConnection()->getPdo()->queries;
}
- public function tearDown()
+ public function tearDown(): void
{
$this->model->getConnection()->getPdo()->resetQueries();
}
@@ -580,9 +580,9 @@ class TestPDO extends PDO
public $counter = 1;
- public function prepare($statement, $driver_options = [])
+ public function prepare(string $query, array $options = []): PDOStatement|false
{
- $this->queries[] = $statement;
+ $this->queries[] = $query;
$stmt = m::mock('PDOStatement');
$stmt->shouldReceive('bindValue')->zeroOrMoreTimes();
@@ -593,7 +593,11 @@ public function prepare($statement, $driver_options = [])
return $stmt;
}
- public function lastInsertId($name = null)
+ /**
+ * @param string|null $name
+ * @return string|false
+ */
+ public function lastInsertId(?string $name = null): string|false
{
return $this->counter++;
}
diff --git a/tests/Unit/MysqlConnectionTest.php b/tests/Unit/MysqlConnectionTest.php
index cae970a2..4b221067 100644
--- a/tests/Unit/MysqlConnectionTest.php
+++ b/tests/Unit/MysqlConnectionTest.php
@@ -7,12 +7,13 @@
class MysqlConnectionTest extends TestCase
{
- private $mysqlConnection;
+ private MysqlConnection $mysqlConnection;
- protected function setUp()
+ protected function setUp(): void
{
- $mysqlConfig = ['driver' => 'mysql', 'prefix' => 'prefix', 'database' => 'database', 'name' => 'foo'];
- $this->mysqlConnection = new MysqlConnection(new PDOStub(), 'database', 'prefix', $mysqlConfig);
+ $mysqlConfig = ['driver' => 'mysql', 'prefix' => 'prefix', 'database' => 'database', 'name' => 'spatial_test', 'port' => 3309];
+
+ $this->mysqlConnection = new MysqlConnection(new PDOStub(options: $mysqlConfig), 'database', 'prefix', $mysqlConfig);
}
public function testGetSchemaBuilder()
diff --git a/tests/Unit/Schema/BlueprintTest.php b/tests/Unit/Schema/BlueprintTest.php
index c22c9518..457adab1 100644
--- a/tests/Unit/Schema/BlueprintTest.php
+++ b/tests/Unit/Schema/BlueprintTest.php
@@ -14,7 +14,7 @@ class BlueprintTest extends BaseTestCase
*/
protected $blueprint;
- public function setUp()
+ public function setUp(): void
{
parent::setUp();
diff --git a/tests/Unit/Stubs/PDOStub.php b/tests/Unit/Stubs/PDOStub.php
index 99d2d806..55b2f921 100644
--- a/tests/Unit/Stubs/PDOStub.php
+++ b/tests/Unit/Stubs/PDOStub.php
@@ -4,7 +4,23 @@
class PDOStub extends \PDO
{
- public function __construct()
- {
+ public function __construct(
+ ?string $username = null,
+ ?string $password = null,
+ ?array $options = null
+ ) {
+ $port = env('DB_PORT', 3306);
+ $dbHost = env('DB_HOST', 'spatial_test');
+ $dbName = env('DB_DATABASE', 'spatial_test');
+ $dsn = 'mysql:host=' . $dbHost . ':' . $port . ';dbname=' . $dbName;
+
+ if (is_null($username)) {
+ $username = env('DB_USERNAME');
+ }
+
+ if (is_null($password)) {
+ $password = env('DB_PASSWORD');
+ }
+ parent::__construct($dsn, $username, $password, $options);
}
}
diff --git a/tests/Unit/Types/GeometryCollectionTest.php b/tests/Unit/Types/GeometryCollectionTest.php
index a0d6f016..a054a7dc 100644
--- a/tests/Unit/Types/GeometryCollectionTest.php
+++ b/tests/Unit/Types/GeometryCollectionTest.php
@@ -71,7 +71,7 @@ public function testToArray()
{
$geometryCollection = $this->getGeometryCollection();
- $this->assertInternalType('array', $geometryCollection->toArray());
+ $this->assertIsArray( $geometryCollection->toArray());
}
public function testIteratorAggregate()
@@ -136,7 +136,7 @@ public function testInvalidGeoJsonException()
GeometryCollection::fromJson('{"type":"Point","coordinates":[3.4,1.2]}');
}
- private function getGeometryCollection()
+ private function getGeometryCollection(): GeometryCollection
{
return new GeometryCollection([$this->getLineString(), $this->getPoint()]);
}
diff --git a/tests/Unit/Types/LineStringTest.php b/tests/Unit/Types/LineStringTest.php
index ce5713d2..0262dea0 100644
--- a/tests/Unit/Types/LineStringTest.php
+++ b/tests/Unit/Types/LineStringTest.php
@@ -7,7 +7,7 @@ class LineStringTest extends BaseTestCase
{
private $points;
- protected function setUp()
+ protected function setUp(): void
{
$this->points = [new Point(0, 0), new Point(1, 1), new Point(2, 2)];
}
diff --git a/tests/Unit/Types/PolygonTest.php b/tests/Unit/Types/PolygonTest.php
index aaab437b..b572f121 100644
--- a/tests/Unit/Types/PolygonTest.php
+++ b/tests/Unit/Types/PolygonTest.php
@@ -8,7 +8,7 @@ class PolygonTest extends BaseTestCase
{
private $polygon;
- protected function setUp()
+ protected function setUp(): void
{
$collection = new LineString(
[