diff --git a/README.md b/README.md index 58a58de2..dcffdb97 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,5 @@ # Laravel MySQL Spatial extension -[![Build Status](https://img.shields.io/travis/grimzy/laravel-mysql-spatial.svg?style=flat-square)](https://travis-ci.org/grimzy/laravel-mysql-spatial) -[![Code Climate](https://img.shields.io/codeclimate/maintainability/grimzy/laravel-mysql-spatial.svg?style=flat-square)](https://codeclimate.com/github/grimzy/laravel-mysql-spatial/maintainability) -[![Code Climate](https://img.shields.io/codeclimate/c/grimzy/laravel-mysql-spatial.svg?style=flat-square&colorB=4BCA2A)](https://codeclimate.com/github/grimzy/laravel-mysql-spatial/test_coverage) [![Packagist](https://img.shields.io/packagist/v/grimzy/laravel-mysql-spatial.svg?style=flat-square)](https://packagist.org/packages/grimzy/laravel-mysql-spatial) -[![Packagist](https://img.shields.io/packagist/dt/grimzy/laravel-mysql-spatial.svg?style=flat-square)](https://packagist.org/packages/grimzy/laravel-mysql-spatial) [![StyleCI](https://github.styleci.io/repos/83766141/shield?branch=master)](https://github.styleci.io/repos/83766141) [![license](https://img.shields.io/github/license/mashape/apistatus.svg?style=flat-square)](LICENSE) Laravel package to easily work with [MySQL Spatial Data Types](https://dev.mysql.com/doc/refman/8.0/en/spatial-type-overview.html) and [MySQL Spatial Functions](https://dev.mysql.com/doc/refman/8.0/en/spatial-function-reference.html). @@ -12,8 +8,7 @@ Please check the documentation for your MySQL version. MySQL's Extension for Spa **Versions** -- `1.x.x`: MySQL 5.6 (also supports MySQL 5.5 but not all spatial analysis functions) -- `2.x.x`: MySQL 5.7 and 8.0 +- `2.1.4`: MySQL 5.7 and 8.0 This package also works with MariaDB. Please refer to the [MySQL/MariaDB Spatial Support Matrix](https://mariadb.com/kb/en/library/mysqlmariadb-spatial-support-matrix/) for compatibility. @@ -22,13 +17,7 @@ This package also works with MariaDB. Please refer to the [MySQL/MariaDB Spatial Add the package using composer: ```shell -composer require grimzy/laravel-mysql-spatial -``` - -For MySQL 5.6 and 5.5: - -```shell -composer require grimzy/laravel-mysql-spatial:^1.0 +composer require kndol/laravel-mysql-spatial ``` For Laravel versions before 5.5 or if not using auto-discovery, register the service provider in `config/app.php`: @@ -38,7 +27,7 @@ For Laravel versions before 5.5 or if not using auto-discovery, register the ser /* * Package Service Providers... */ - Grimzy\LaravelMysqlSpatial\SpatialServiceProvider::class, + Kndol\LaravelMysqlSpatial\SpatialServiceProvider::class, ], ``` @@ -52,14 +41,14 @@ From the command line: php artisan make:migration create_places_table ``` -Then edit the migration you just created by adding at least one spatial data field. For Laravel versions prior to 5.5, you can use the Blueprint provided by this package (Grimzy\LaravelMysqlSpatial\Schema\Blueprint): +Then edit the migration you just created by adding at least one spatial data field. For Laravel versions prior to 5.5, you can use the Blueprint provided by this package (Kndol\LaravelMysqlSpatial\Schema\Blueprint): ```php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; // For Laravel < 5.5 -// use Grimzy\LaravelMysqlSpatial\Schema\Blueprint; +// use Kndol\LaravelMysqlSpatial\Schema\Blueprint; class CreatePlacesTable extends Migration { @@ -114,11 +103,11 @@ Then edit the model you just created. It must use the `SpatialTrait` and define namespace App; use Illuminate\Database\Eloquent\Model; -use Grimzy\LaravelMysqlSpatial\Eloquent\SpatialTrait; +use Kndol\LaravelMysqlSpatial\Eloquent\SpatialTrait; /** - * @property \Grimzy\LaravelMysqlSpatial\Types\Point $location - * @property \Grimzy\LaravelMysqlSpatial\Types\Polygon $area + * @property \Kndol\LaravelMysqlSpatial\Types\Point $location + * @property \Kndol\LaravelMysqlSpatial\Types\Polygon $area */ class Place extends Model { @@ -138,8 +127,8 @@ class Place extends Model ### Saving a model ```php -use Grimzy\LaravelMysqlSpatial\Types\Point; -use Grimzy\LaravelMysqlSpatial\Types\Polygon; +use Kndol\LaravelMysqlSpatial\Types\Point; +use Kndol\LaravelMysqlSpatial\Types\Polygon; $place1 = new Place(); $place1->name = 'Empire State Building'; @@ -174,7 +163,7 @@ $lng = $place2->location->getLng(); // -73.9878441 ### Available Geometry classes -| Grimzy\LaravelMysqlSpatial\Types | OpenGIS Class | +| Kndol\LaravelMysqlSpatial\Types | OpenGIS Class | | ------------------------------------------------------------ | ------------------------------------------------------------ | | `Point($lat, $lng)` | [Point](https://dev.mysql.com/doc/refman/8.0/en/gis-class-point.html) | | `MultiPoint(Point[])` | [MultiPoint](https://dev.mysql.com/doc/refman/8.0/en/gis-class-multipoint.html) | @@ -188,7 +177,7 @@ Check out the [Class diagram](https://user-images.githubusercontent.com/1837678/ ### Using Geometry classes -In order for your Eloquent Model to handle the Geometry classes, it must use the `Grimzy\LaravelMysqlSpatial\Eloquent\SpatialTrait` trait and define a `protected` property `$spatialFields` as an array of MySQL Spatial Data Type column names (example in [Quickstart](#user-content-create-a-model)). +In order for your Eloquent Model to handle the Geometry classes, it must use the `Kndol\LaravelMysqlSpatial\Eloquent\SpatialTrait` trait and define a `protected` property `$spatialFields` as an array of MySQL Spatial Data Type column names (example in [Quickstart](#user-content-create-a-model)). #### IteratorAggregate and ArrayAccess @@ -265,6 +254,7 @@ Spatial analysis functions are implemented using [Eloquent Local Scopes](https:/ Available scopes: +- `eachDistance($geometryColumn, $distanceColumn, $geometry)` - `distance($geometryColumn, $geometry, $distance)` - `distanceExcludingSelf($geometryColumn, $geometry, $distance)` - `distanceSphere($geometryColumn, $geometry, $distance)` @@ -279,18 +269,18 @@ Available scopes: - `overlaps($geometryColumn, $geometry)` - `doesTouch($geometryColumn, $geometry)` - `orderBySpatial($geometryColumn, $geometry, $orderFunction, $direction = 'asc')` -- `orderByDistance($geometryColumn, ​$geometry, ​$direction = 'asc')` -- `orderByDistanceSphere($geometryColumn, ​$geometry, ​$direction = 'asc')` +- `orderByDistance($geometryColumn, $geometry, $direction = 'asc')` +- `orderByDistanceSphere($geometryColumn, $geometry, $direction = 'asc')` *Note that behavior and availability of MySQL spatial analysis functions differs in each MySQL version (cf. [documentation](https://dev.mysql.com/doc/refman/5.7/en/spatial-function-reference.html)).* ## Migrations -For Laravel versions prior to 5.5, you can use the Blueprint provided with this package: `Grimzy\LaravelMysqlSpatial\Schema\Blueprint`. +For Laravel versions prior to 5.5, you can use the Blueprint provided with this package: `Kndol\LaravelMysqlSpatial\Schema\Blueprint`. ```php use Illuminate\Database\Migrations\Migration; -use Grimzy\LaravelMysqlSpatial\Schema\Blueprint; +use Kndol\LaravelMysqlSpatial\Schema\Blueprint; class CreatePlacesTable extends Migration { // ... diff --git a/composer.json b/composer.json index 9a4efa85..d16880be 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "grimzy/laravel-mysql-spatial", + "name": "kndol/laravel-mysql-spatial", "description": "MySQL spatial data types extension for Laravel.", "scripts": { "test": "phpunit -c phpunit.xml.dist", @@ -32,7 +32,7 @@ }, "autoload": { "psr-4": { - "Grimzy\\LaravelMysqlSpatial\\": "src/" + "Kndol\\LaravelMysqlSpatial\\": "src/" } }, "autoload-dev" : { @@ -47,7 +47,7 @@ }, "laravel": { "providers": [ - "Grimzy\\LaravelMysqlSpatial\\SpatialServiceProvider" + "Kndol\\LaravelMysqlSpatial\\SpatialServiceProvider" ] } } diff --git a/src/Connectors/ConnectionFactory.php b/src/Connectors/ConnectionFactory.php index 223cea13..bfabb09a 100644 --- a/src/Connectors/ConnectionFactory.php +++ b/src/Connectors/ConnectionFactory.php @@ -1,8 +1,8 @@ isColumnAllowed($geometryColumn); + + $query->whereRaw("st_distance(`$geometryColumn`, ST_GeomFromText(?))*100000 <= `$distanceColumn`", + $geometry->toWkt()); + + return $query; + } + public function scopeDistance($query, $geometryColumn, $geometry, $distance) { $this->isColumnAllowed($geometryColumn); - $query->whereRaw("st_distance(`$geometryColumn`, ST_GeomFromText(?)) <= ?", [ + $query->whereRaw("st_distance(`$geometryColumn`, ST_GeomFromText(?))*100000 <= ?", [ $geometry->toWkt(), $distance, ]); @@ -146,7 +157,7 @@ public function scopeDistanceExcludingSelf($query, $geometryColumn, $geometry, $ $query = $this->scopeDistance($query, $geometryColumn, $geometry, $distance); - $query->whereRaw("st_distance(`$geometryColumn`, ST_GeomFromText(?)) != 0", [ + $query->whereRaw("st_distance(`$geometryColumn`, ST_GeomFromText(?))*100000 != 0", [ $geometry->toWkt(), ]); @@ -163,7 +174,7 @@ public function scopeDistanceValue($query, $geometryColumn, $geometry) $query->select('*'); } - $query->selectRaw("st_distance(`$geometryColumn`, ST_GeomFromText(?)) as distance", [ + $query->selectRaw("st_distance(`$geometryColumn`, ST_GeomFromText(?)*100000) as distance", [ $geometry->toWkt(), ]); } diff --git a/src/Exceptions/InvalidGeoJsonException.php b/src/Exceptions/InvalidGeoJsonException.php index 3374fdb7..e92a480c 100644 --- a/src/Exceptions/InvalidGeoJsonException.php +++ b/src/Exceptions/InvalidGeoJsonException.php @@ -1,6 +1,6 @@ getGeometry(); } - $type = '\Grimzy\LaravelMysqlSpatial\Types\\'.$geoJson->getType(); + $type = '\Kndol\LaravelMysqlSpatial\Types\\'.$geoJson->getType(); return $type::fromJson($geoJson); } diff --git a/src/Types/GeometryCollection.php b/src/Types/GeometryCollection.php index 2e1f0321..101c8ec2 100755 --- a/src/Types/GeometryCollection.php +++ b/src/Types/GeometryCollection.php @@ -1,13 +1,13 @@ geometry = new Point(1, 2); $geo->save(); - $this->assertException(\Grimzy\LaravelMysqlSpatial\Exceptions\SpatialFieldsNotDefinedException::class); + $this->assertException(\Kndol\LaravelMysqlSpatial\Exceptions\SpatialFieldsNotDefinedException::class); NoSpatialFieldsModel::all(); } @@ -377,7 +377,7 @@ public function testOrderBySpatialWithUnknownFunction() $loc = new GeometryModel(); $loc->location = new Point(1, 1); - $this->assertException(\Grimzy\LaravelMysqlSpatial\Exceptions\UnknownSpatialFunctionException::class); + $this->assertException(\Kndol\LaravelMysqlSpatial\Exceptions\UnknownSpatialFunctionException::class); GeometryModel::orderBySpatial('location', $loc->location, 'does-not-exist')->get(); } @@ -451,9 +451,9 @@ public function testOrderByDistanceSphere() //public function testBounding() { // $point = new Point(0, 0); // - // $linestring1 = \Grimzy\LaravelMysqlSpatial\Types\LineString::fromWkt("LINESTRING(1 1, 2 2)"); - // $linestring2 = \Grimzy\LaravelMysqlSpatial\Types\LineString::fromWkt("LINESTRING(20 20, 24 24)"); - // $linestring3 = \Grimzy\LaravelMysqlSpatial\Types\LineString::fromWkt("LINESTRING(0 10, 10 10)"); + // $linestring1 = \Kndol\LaravelMysqlSpatial\Types\LineString::fromWkt("LINESTRING(1 1, 2 2)"); + // $linestring2 = \Kndol\LaravelMysqlSpatial\Types\LineString::fromWkt("LINESTRING(20 20, 24 24)"); + // $linestring3 = \Kndol\LaravelMysqlSpatial\Types\LineString::fromWkt("LINESTRING(0 10, 10 10)"); // // $geo1 = new GeometryModel(); // $geo1->location = $point; diff --git a/tests/Unit/Connectors/ConnectionFactoryTest.php b/tests/Unit/Connectors/ConnectionFactoryTest.php index ea1cdd4c..f3ab4766 100644 --- a/tests/Unit/Connectors/ConnectionFactoryTest.php +++ b/tests/Unit/Connectors/ConnectionFactoryTest.php @@ -1,7 +1,7 @@ assertFalse($this->model->exists); - $this->model->linestring = new \Grimzy\LaravelMysqlSpatial\Types\LineString([$point1, $point2]); + $this->model->linestring = new \Kndol\LaravelMysqlSpatial\Types\LineString([$point1, $point2]); $this->model->save(); $this->assertStringStartsWith('insert', $this->queries[0]); @@ -64,7 +64,7 @@ public function testInsertUpdateLineStringHasCorrectSql() // TODO: assert bindings in query $this->assertTrue($this->model->exists); - $this->model->linestring = new \Grimzy\LaravelMysqlSpatial\Types\LineString([$point1, $point2]); + $this->model->linestring = new \Kndol\LaravelMysqlSpatial\Types\LineString([$point1, $point2]); $this->model->save(); $this->assertStringStartsWith('update', $this->queries[1]); @@ -76,14 +76,14 @@ public function testInsertUpdatePolygonHasCorrectSql() { $point1 = new Point(1, 2); $point2 = new Point(2, 3); - $linestring1 = new \Grimzy\LaravelMysqlSpatial\Types\LineString([$point1, $point2]); + $linestring1 = new \Kndol\LaravelMysqlSpatial\Types\LineString([$point1, $point2]); $point3 = new Point(3, 2); $point4 = new Point(2, 1); - $linestring2 = new \Grimzy\LaravelMysqlSpatial\Types\LineString([$point3, $point4]); + $linestring2 = new \Kndol\LaravelMysqlSpatial\Types\LineString([$point3, $point4]); $this->assertFalse($this->model->exists); - $this->model->polygon = new \Grimzy\LaravelMysqlSpatial\Types\Polygon([$linestring1, $linestring2]); + $this->model->polygon = new \Kndol\LaravelMysqlSpatial\Types\Polygon([$linestring1, $linestring2]); $this->model->save(); $this->assertStringStartsWith('insert', $this->queries[0]); @@ -91,7 +91,7 @@ public function testInsertUpdatePolygonHasCorrectSql() // TODO: assert bindings in query $this->assertTrue($this->model->exists); - $this->model->polygon = new \Grimzy\LaravelMysqlSpatial\Types\Polygon([$linestring1, $linestring2]); + $this->model->polygon = new \Kndol\LaravelMysqlSpatial\Types\Polygon([$linestring1, $linestring2]); $this->model->save(); $this->assertStringStartsWith('update', $this->queries[1]); $this->assertContains('update `test_models` set `polygon` = ST_GeomFromText(?) where `id` = ?', $this->queries[1]); @@ -105,7 +105,7 @@ public function testInsertUpdateMultiPointHasCorrectSql() $this->assertFalse($this->model->exists); - $this->model->multipoint = new \Grimzy\LaravelMysqlSpatial\Types\MultiPoint([$point1, $point2]); + $this->model->multipoint = new \Kndol\LaravelMysqlSpatial\Types\MultiPoint([$point1, $point2]); $this->model->save(); $this->assertStringStartsWith('insert', $this->queries[0]); @@ -113,7 +113,7 @@ public function testInsertUpdateMultiPointHasCorrectSql() // TODO: assert bindings in query $this->assertTrue($this->model->exists); - $this->model->multipoint = new \Grimzy\LaravelMysqlSpatial\Types\MultiPoint([$point1, $point2]); + $this->model->multipoint = new \Kndol\LaravelMysqlSpatial\Types\MultiPoint([$point1, $point2]); $this->model->save(); $this->assertStringStartsWith('update', $this->queries[1]); @@ -125,14 +125,14 @@ public function testInsertUpdateMultiLineStringHasCorrectSql() { $point1 = new Point(1, 2); $point2 = new Point(2, 3); - $linestring1 = new \Grimzy\LaravelMysqlSpatial\Types\LineString([$point1, $point2]); + $linestring1 = new \Kndol\LaravelMysqlSpatial\Types\LineString([$point1, $point2]); $point3 = new Point(3, 2); $point4 = new Point(2, 1); - $linestring2 = new \Grimzy\LaravelMysqlSpatial\Types\LineString([$point3, $point4]); + $linestring2 = new \Kndol\LaravelMysqlSpatial\Types\LineString([$point3, $point4]); $this->assertFalse($this->model->exists); - $this->model->multilinestring = new \Grimzy\LaravelMysqlSpatial\Types\MultiLineString([$linestring1, $linestring2]); + $this->model->multilinestring = new \Kndol\LaravelMysqlSpatial\Types\MultiLineString([$linestring1, $linestring2]); $this->model->save(); $this->assertStringStartsWith('insert', $this->queries[0]); @@ -140,7 +140,7 @@ public function testInsertUpdateMultiLineStringHasCorrectSql() // TODO: assert bindings in query $this->assertTrue($this->model->exists); - $this->model->multilinestring = new \Grimzy\LaravelMysqlSpatial\Types\MultiLineString([$linestring1, $linestring2]); + $this->model->multilinestring = new \Kndol\LaravelMysqlSpatial\Types\MultiLineString([$linestring1, $linestring2]); $this->model->save(); $this->assertStringStartsWith('update', $this->queries[1]); $this->assertContains('update `test_models` set `multilinestring` = ST_GeomFromText(?) where `id` = ?', $this->queries[1]); @@ -151,23 +151,23 @@ public function testInsertUpdateMultiPolygonHasCorrectSql() { $point1 = new Point(1, 2); $point2 = new Point(2, 3); - $linestring1 = new \Grimzy\LaravelMysqlSpatial\Types\LineString([$point1, $point2]); + $linestring1 = new \Kndol\LaravelMysqlSpatial\Types\LineString([$point1, $point2]); $point3 = new Point(3, 2); $point4 = new Point(2, 1); - $linestring2 = new \Grimzy\LaravelMysqlSpatial\Types\LineString([$point3, $point4]); - $polygon1 = new \Grimzy\LaravelMysqlSpatial\Types\Polygon([$linestring1, $linestring2]); + $linestring2 = new \Kndol\LaravelMysqlSpatial\Types\LineString([$point3, $point4]); + $polygon1 = new \Kndol\LaravelMysqlSpatial\Types\Polygon([$linestring1, $linestring2]); $point5 = new Point(4, 5); $point6 = new Point(5, 6); - $linestring3 = new \Grimzy\LaravelMysqlSpatial\Types\LineString([$point5, $point6]); + $linestring3 = new \Kndol\LaravelMysqlSpatial\Types\LineString([$point5, $point6]); $point7 = new Point(6, 5); $point8 = new Point(5, 4); - $linestring4 = new \Grimzy\LaravelMysqlSpatial\Types\LineString([$point7, $point8]); - $polygon2 = new \Grimzy\LaravelMysqlSpatial\Types\Polygon([$linestring3, $linestring4]); + $linestring4 = new \Kndol\LaravelMysqlSpatial\Types\LineString([$point7, $point8]); + $polygon2 = new \Kndol\LaravelMysqlSpatial\Types\Polygon([$linestring3, $linestring4]); $this->assertFalse($this->model->exists); - $this->model->multipolygon = new \Grimzy\LaravelMysqlSpatial\Types\MultiPolygon([$polygon1, $polygon2]); + $this->model->multipolygon = new \Kndol\LaravelMysqlSpatial\Types\MultiPolygon([$polygon1, $polygon2]); $this->model->save(); $this->assertStringStartsWith('insert', $this->queries[0]); @@ -175,7 +175,7 @@ public function testInsertUpdateMultiPolygonHasCorrectSql() // TODO: assert bindings in query $this->assertTrue($this->model->exists); - $this->model->multipolygon = new \Grimzy\LaravelMysqlSpatial\Types\MultiPolygon([$polygon1, $polygon2]); + $this->model->multipolygon = new \Kndol\LaravelMysqlSpatial\Types\MultiPolygon([$polygon1, $polygon2]); $this->model->save(); $this->assertStringStartsWith('update', $this->queries[1]); $this->assertContains('update `test_models` set `multipolygon` = ST_GeomFromText(?) where `id` = ?', $this->queries[1]); @@ -187,11 +187,11 @@ public function testInsertUpdateGeometryCollectionHasCorrectSql() $point1 = new Point(1, 2); $point2 = new Point(2, 3); $point3 = new Point(3, 3); - $linestring1 = new \Grimzy\LaravelMysqlSpatial\Types\LineString([$point2, $point3]); + $linestring1 = new \Kndol\LaravelMysqlSpatial\Types\LineString([$point2, $point3]); $this->assertFalse($this->model->exists); - $this->model->geometrycollection = new \Grimzy\LaravelMysqlSpatial\Types\GeometryCollection([$point1, $linestring1]); + $this->model->geometrycollection = new \Kndol\LaravelMysqlSpatial\Types\GeometryCollection([$point1, $linestring1]); $this->model->save(); $this->assertStringStartsWith('insert', $this->queries[0]); @@ -199,7 +199,7 @@ public function testInsertUpdateGeometryCollectionHasCorrectSql() // TODO: assert bindings in query $this->assertTrue($this->model->exists); - $this->model->geometrycollection = new \Grimzy\LaravelMysqlSpatial\Types\GeometryCollection([$point1, $linestring1]); + $this->model->geometrycollection = new \Kndol\LaravelMysqlSpatial\Types\GeometryCollection([$point1, $linestring1]); $this->model->save(); $this->assertStringStartsWith('update', $this->queries[1]); $this->assertContains('update `test_models` set `geometrycollection` = ST_GeomFromText(?) where `id` = ?', $this->queries[1]); @@ -226,7 +226,7 @@ public function testScopeDistance() $point = new Point(1, 2); $query = TestModel::distance('point', $point, 10); - $this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query); + $this->assertInstanceOf(\Kndol\LaravelMysqlSpatial\Eloquent\Builder::class, $query); $q = $query->getQuery(); $this->assertNotEmpty($q->wheres); $bindings = $q->getRawBindings()['where']; @@ -241,7 +241,7 @@ public function testScopeDistanceExcludingSelf() $point = new Point(1, 2); $query = TestModel::distanceExcludingSelf('point', $point, 10); - $this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query); + $this->assertInstanceOf(\Kndol\LaravelMysqlSpatial\Eloquent\Builder::class, $query); $q = $query->getQuery(); $this->assertNotEmpty($q->wheres); $bindings = $q->getRawBindings()['where']; @@ -258,7 +258,7 @@ public function testScopeDistanceSphere() $point = new Point(1, 2); $query = TestModel::distanceSphere('point', $point, 10); - $this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query); + $this->assertInstanceOf(\Kndol\LaravelMysqlSpatial\Eloquent\Builder::class, $query); $q = $query->getQuery(); $this->assertNotEmpty($q->wheres); $bindings = $q->getRawBindings()['where']; @@ -273,7 +273,7 @@ public function testScopeDistanceSphereExcludingSelf() $point = new Point(1, 2); $query = TestModel::distanceSphereExcludingSelf('point', $point, 10); - $this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query); + $this->assertInstanceOf(\Kndol\LaravelMysqlSpatial\Eloquent\Builder::class, $query); $q = $query->getQuery(); $this->assertNotEmpty($q->wheres); $bindings = $q->getRawBindings()['where']; @@ -290,7 +290,7 @@ public function testScopeDistanceValue() $point = new Point(1, 2); $query = TestModel::distanceValue('point', $point); - $this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query); + $this->assertInstanceOf(\Kndol\LaravelMysqlSpatial\Eloquent\Builder::class, $query); $q = $query->getQuery(); $this->assertNotEmpty($q->columns); $bindings = $q->getRawBindings()['select']; @@ -306,7 +306,7 @@ public function testScopeDistanceValueWithSelect() $point = new Point(1, 2); $query = TestModel::select('some_column')->distanceValue('point', $point); - $this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query); + $this->assertInstanceOf(\Kndol\LaravelMysqlSpatial\Eloquent\Builder::class, $query); $q = $query->getQuery(); $this->assertNotEmpty($q->columns); $bindings = $q->getRawBindings()['select']; @@ -322,7 +322,7 @@ public function testScopeDistanceSphereValue() $point = new Point(1, 2); $query = TestModel::distanceSphereValue('point', $point); - $this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query); + $this->assertInstanceOf(\Kndol\LaravelMysqlSpatial\Eloquent\Builder::class, $query); $q = $query->getQuery(); $this->assertNotEmpty($q->columns); $bindings = $q->getRawBindings()['select']; @@ -338,7 +338,7 @@ public function testScopeDistanceSphereValueWithSelect() $point = new Point(1, 2); $query = TestModel::select('some_column')->distanceSphereValue('point', $point); - $this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query); + $this->assertInstanceOf(\Kndol\LaravelMysqlSpatial\Eloquent\Builder::class, $query); $q = $query->getQuery(); $this->assertNotEmpty($q->columns); $bindings = $q->getRawBindings()['select']; @@ -353,22 +353,22 @@ private function buildTestPolygon() { $point1 = new Point(1, 1); $point2 = new Point(1, 2); - $linestring1 = new \Grimzy\LaravelMysqlSpatial\Types\LineString([$point1, $point2]); + $linestring1 = new \Kndol\LaravelMysqlSpatial\Types\LineString([$point1, $point2]); $point3 = new Point(1, 2); $point4 = new Point(2, 2); - $linestring2 = new \Grimzy\LaravelMysqlSpatial\Types\LineString([$point3, $point4]); + $linestring2 = new \Kndol\LaravelMysqlSpatial\Types\LineString([$point3, $point4]); $point5 = new Point(2, 2); $point6 = new Point(1, 1); - $linestring3 = new \Grimzy\LaravelMysqlSpatial\Types\LineString([$point5, $point6]); + $linestring3 = new \Kndol\LaravelMysqlSpatial\Types\LineString([$point5, $point6]); - return new \Grimzy\LaravelMysqlSpatial\Types\Polygon([$linestring1, $linestring2, $linestring3]); + return new \Kndol\LaravelMysqlSpatial\Types\Polygon([$linestring1, $linestring2, $linestring3]); } public function testScopeComparison() { $query = TestModel::comparison('point', $this->buildTestPolygon(), 'within'); - $this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query); + $this->assertInstanceOf(\Kndol\LaravelMysqlSpatial\Eloquent\Builder::class, $query); $q = $query->getQuery(); $this->assertNotEmpty($q->wheres); $bindings = $q->getRawBindings()['where']; @@ -381,7 +381,7 @@ public function testScopeWithin() { $query = TestModel::within('point', $this->buildTestPolygon()); - $this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query); + $this->assertInstanceOf(\Kndol\LaravelMysqlSpatial\Eloquent\Builder::class, $query); $q = $query->getQuery(); $this->assertNotEmpty($q->wheres); $bindings = $q->getRawBindings()['where']; @@ -394,7 +394,7 @@ public function testScopeCrosses() { $query = TestModel::crosses('point', $this->buildTestPolygon()); - $this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query); + $this->assertInstanceOf(\Kndol\LaravelMysqlSpatial\Eloquent\Builder::class, $query); $q = $query->getQuery(); $this->assertNotEmpty($q->wheres); $bindings = $q->getRawBindings()['where']; @@ -407,7 +407,7 @@ public function testScopeContains() { $query = TestModel::contains('point', $this->buildTestPolygon()); - $this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query); + $this->assertInstanceOf(\Kndol\LaravelMysqlSpatial\Eloquent\Builder::class, $query); $q = $query->getQuery(); $this->assertNotEmpty($q->wheres); $bindings = $q->getRawBindings()['where']; @@ -420,7 +420,7 @@ public function testScopeDisjoint() { $query = TestModel::disjoint('point', $this->buildTestPolygon()); - $this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query); + $this->assertInstanceOf(\Kndol\LaravelMysqlSpatial\Eloquent\Builder::class, $query); $q = $query->getQuery(); $this->assertNotEmpty($q->wheres); $bindings = $q->getRawBindings()['where']; @@ -433,7 +433,7 @@ public function testScopeEquals() { $query = TestModel::equals('point', $this->buildTestPolygon()); - $this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query); + $this->assertInstanceOf(\Kndol\LaravelMysqlSpatial\Eloquent\Builder::class, $query); $q = $query->getQuery(); $this->assertNotEmpty($q->wheres); $bindings = $q->getRawBindings()['where']; @@ -446,7 +446,7 @@ public function testScopeIntersects() { $query = TestModel::intersects('point', $this->buildTestPolygon()); - $this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query); + $this->assertInstanceOf(\Kndol\LaravelMysqlSpatial\Eloquent\Builder::class, $query); $q = $query->getQuery(); $this->assertNotEmpty($q->wheres); $bindings = $q->getRawBindings()['where']; @@ -459,7 +459,7 @@ public function testScopeOverlaps() { $query = TestModel::overlaps('point', $this->buildTestPolygon()); - $this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query); + $this->assertInstanceOf(\Kndol\LaravelMysqlSpatial\Eloquent\Builder::class, $query); $q = $query->getQuery(); $this->assertNotEmpty($q->wheres); $bindings = $q->getRawBindings()['where']; @@ -472,7 +472,7 @@ public function testScopeDoesTouch() { $query = TestModel::doesTouch('point', $this->buildTestPolygon()); - $this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query); + $this->assertInstanceOf(\Kndol\LaravelMysqlSpatial\Eloquent\Builder::class, $query); $q = $query->getQuery(); $this->assertNotEmpty($q->wheres); $bindings = $q->getRawBindings()['where']; @@ -484,7 +484,7 @@ public function testScopeDoesTouch() public function testScopeOrderBySpatialThrowsExceptionWhenFunctionNotRegistered() { $point = new Point(1, 2); - $this->assertException(\Grimzy\LaravelMysqlSpatial\Exceptions\UnknownSpatialFunctionException::class); + $this->assertException(\Kndol\LaravelMysqlSpatial\Exceptions\UnknownSpatialFunctionException::class); TestModel::orderBySpatial('point', $point, 'does-not-exist'); } @@ -493,7 +493,7 @@ public function testScopeOrderByDistance() $point = new Point(1, 2); $query = TestModel::orderByDistance('point', $point); - $this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query); + $this->assertInstanceOf(\Kndol\LaravelMysqlSpatial\Eloquent\Builder::class, $query); $q = $query->getQuery(); $this->assertNotEmpty($q->orders); $bindings = $q->getRawBindings()['order']; @@ -507,7 +507,7 @@ public function testScopeOrderByDistanceSphere() $point = new Point(1, 2); $query = TestModel::orderByDistanceSphere('point', $point); - $this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query); + $this->assertInstanceOf(\Kndol\LaravelMysqlSpatial\Eloquent\Builder::class, $query); $q = $query->getQuery(); $this->assertNotEmpty($q->orders); $bindings = $q->getRawBindings()['order']; @@ -519,7 +519,7 @@ public function testScopeOrderByDistanceSphere() class TestModel extends Model { - use \Grimzy\LaravelMysqlSpatial\Eloquent\SpatialTrait; + use \Kndol\LaravelMysqlSpatial\Eloquent\SpatialTrait; protected $spatialFields = ['point']; // TODO: only required when fetching, not saving @@ -562,7 +562,7 @@ public function testmodels() class TestNoSpatialModel extends Model { - use \Grimzy\LaravelMysqlSpatial\Eloquent\SpatialTrait; + use \Kndol\LaravelMysqlSpatial\Eloquent\SpatialTrait; } class TestPDO extends PDO diff --git a/tests/Unit/MysqlConnectionTest.php b/tests/Unit/MysqlConnectionTest.php index c630d990..56ba6b99 100644 --- a/tests/Unit/MysqlConnectionTest.php +++ b/tests/Unit/MysqlConnectionTest.php @@ -1,7 +1,7 @@ setExpectedException(\Grimzy\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class); + $this->setExpectedException(\Kndol\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class); GeometryCollection::fromJson('{"type":"Point","coordinates":[3.4,1.2]}'); } diff --git a/tests/Unit/Types/GeometryTest.php b/tests/Unit/Types/GeometryTest.php index 8bd765a7..716de7ea 100644 --- a/tests/Unit/Types/GeometryTest.php +++ b/tests/Unit/Types/GeometryTest.php @@ -1,14 +1,14 @@ setExpectedException(\Grimzy\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class); + $this->setExpectedException(\Kndol\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class); LineString::fromJson('{"type":"Point","coordinates":[3.4,1.2]}'); } diff --git a/tests/Unit/Types/MultiLineStringTest.php b/tests/Unit/Types/MultiLineStringTest.php index df7b42e4..ac041945 100644 --- a/tests/Unit/Types/MultiLineStringTest.php +++ b/tests/Unit/Types/MultiLineStringTest.php @@ -1,8 +1,8 @@ setExpectedException(\Grimzy\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class); + $this->setExpectedException(\Kndol\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class); MultiLineString::fromJson('{"type":"Point","coordinates":[3.4,1.2]}'); } diff --git a/tests/Unit/Types/MultiPointTest.php b/tests/Unit/Types/MultiPointTest.php index 1e9bf7f4..171e386b 100644 --- a/tests/Unit/Types/MultiPointTest.php +++ b/tests/Unit/Types/MultiPointTest.php @@ -1,7 +1,7 @@ setExpectedException(\Grimzy\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class); + $this->setExpectedException(\Kndol\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class); MultiPoint::fromJson('{"type":"Point","coordinates":[3.4,1.2]}'); } diff --git a/tests/Unit/Types/MultiPolygonTest.php b/tests/Unit/Types/MultiPolygonTest.php index cf5894ff..d2b708e8 100644 --- a/tests/Unit/Types/MultiPolygonTest.php +++ b/tests/Unit/Types/MultiPolygonTest.php @@ -1,9 +1,9 @@ setExpectedException(\Grimzy\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class); + $this->setExpectedException(\Kndol\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class); MultiPolygon::fromJson('{"type":"Point","coordinates":[3.4,1.2]}'); } diff --git a/tests/Unit/Types/PointTest.php b/tests/Unit/Types/PointTest.php index 257f6a45..d1218268 100644 --- a/tests/Unit/Types/PointTest.php +++ b/tests/Unit/Types/PointTest.php @@ -1,6 +1,6 @@ setExpectedException(\Grimzy\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class); + $this->setExpectedException(\Kndol\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class); Point::fromJson('{"type": "LineString","coordinates":[[1,1],[2,2]]}'); } diff --git a/tests/Unit/Types/PolygonTest.php b/tests/Unit/Types/PolygonTest.php index de923c2f..986ff95d 100644 --- a/tests/Unit/Types/PolygonTest.php +++ b/tests/Unit/Types/PolygonTest.php @@ -1,8 +1,8 @@ setExpectedException(\Grimzy\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class); + $this->setExpectedException(\Kndol\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class); Polygon::fromJson('{"type":"Point","coordinates":[3.4,1.2]}'); }