diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..badbe2f --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,41 @@ +name: PHP CI + +on: + push: + branches: [ main ] + tags: + - 'v*' + pull_request: + branches: [ main ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.2' + extensions: mbstring, xml, gd, zip, pdo_mysql, sockets, intl, bcmath, gmp + coverage: xdebug + + - name: Update and Install additional packages + run: | + sudo apt-get update + sudo apt-get install -y libzip-dev libgd-dev libfreetype6-dev libjpeg-dev libpng-dev imagemagick libmagickwand-dev libmemcached-dev libgeos-dev libgmp-dev default-mysql-client libicu-dev + + - name: Validate composer.json and composer.lock + run: composer validate + + - name: Install dependencies + run: composer install --prefer-dist --no-progress + + - name: Run Lint + run: composer lint + + # - name: Run Tests -- Will add tests back after phppest issue https://github.com/pestphp/pest/issues/920 is fixed + # run: composer test:unit diff --git a/.gitignore b/.gitignore index 5237024..864a68c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,13 @@ vendor/ composer.lock _db/ -build/ \ No newline at end of file +build/ +.idea/* +.idea/codeStyleSettings.xml +server_vendor/ +.phpunit.result.cache +.php_cs.cache +.php-cs-fixer.cache +*.swp +*.swo +.DS_Store \ No newline at end of file diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php new file mode 100644 index 0000000..b0982fa --- /dev/null +++ b/.php-cs-fixer.php @@ -0,0 +1,29 @@ +in(__DIR__ . DIRECTORY_SEPARATOR . 'tests') + ->in(__DIR__ . DIRECTORY_SEPARATOR . 'src') + ->append(['.php-cs-fixer.php']); + +$rules = [ + '@Symfony' => true, + 'phpdoc_no_empty_return' => false, + 'array_syntax' => ['syntax' => 'short'], + 'yoda_style' => false, + 'binary_operator_spaces' => [ + 'operators' => [ + '=>' => 'align', + '=' => 'align', + ], + ], + 'concat_space' => ['spacing' => 'one'], + 'not_operator_with_space' => false, + 'increment_style' => ['style' => 'post'], + 'indentation_type' => true, + 'single_quote' => true, +]; + +return (new PhpCsFixer\Config()) + ->setUsingCache(true) + ->setRules($rules) + ->setFinder($finder); diff --git a/composer.json b/composer.json index e8c97b5..0ab448b 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,10 @@ "description": "MySQL spatial data types extension for Laravel x Fleetbase.", "version": "1.0.2", "scripts": { + "lint": "php-cs-fixer fix -v", "test": "phpunit -c phpunit.xml.dist", + "test:lint": "php-cs-fixer fix -v --dry-run", + "test:types": "phpstan analyse --ansi --memory-limit=4G", "test:unit": "phpunit -c phpunit.xml.dist --testsuite unit", "test:integration": "phpunit -c phpunit.xml.dist --testsuite integration" }, @@ -23,16 +26,19 @@ "php": "^8.0", "ext-pdo": "*", "ext-json": "*", + "doctrine/dbal": "^3.5", + "illuminate/contracts": "^9.0|^10.0", "illuminate/database": "^9.0|^10.0", "geo-io/wkb-parser": "^1.0", "jmikola/geojson": "^1.0" }, "require-dev": { - "phpunit/phpunit": "^10.0", - "laravel/laravel": "^8.0", - "doctrine/dbal": "^3.4", + "phpunit/phpunit": "^10.0.15", + "laravel/laravel": "^10.0.4", "laravel/browser-kit-testing": "^7.0", - "mockery/mockery": "^1.5" + "mockery/mockery": "^1.5", + "friendsofphp/php-cs-fixer": "^3.34.1", + "phpstan/phpstan": "^1.10.38" }, "autoload": { "psr-4": { diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 0000000..14bdd86 --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,8 @@ +parameters: + level: max + paths: + - src + + checkMissingIterableValueType: true + checkGenericClassInNonGenericObjectType: false + reportUnmatchedIgnoredErrors: true diff --git a/src/Connectors/ConnectionFactory.php b/src/Connectors/ConnectionFactory.php index 750712e..1ac3d45 100644 --- a/src/Connectors/ConnectionFactory.php +++ b/src/Connectors/ConnectionFactory.php @@ -4,16 +4,14 @@ use Fleetbase\LaravelMysqlSpatial\MysqlConnection; use Illuminate\Database\Connectors\ConnectionFactory as IlluminateConnectionFactory; -use PDO; class ConnectionFactory extends IlluminateConnectionFactory { /** - * @param string $driver - * @param \Closure|PDO $connection - * @param string $database - * @param string $prefix - * @param array $config + * @param string $driver + * @param \Closure|\PDO $connection + * @param string $database + * @param string $prefix * * @return \Illuminate\Database\ConnectionInterface */ diff --git a/src/Doctrine/Geometry.php b/src/Doctrine/Geometry.php index 1872a3c..e8a8b66 100644 --- a/src/Doctrine/Geometry.php +++ b/src/Doctrine/Geometry.php @@ -7,7 +7,7 @@ class Geometry extends Type { - const GEOMETRY = 'geometry'; + public const GEOMETRY = 'geometry'; public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) { diff --git a/src/Doctrine/GeometryCollection.php b/src/Doctrine/GeometryCollection.php index 78ae588..27b60d4 100644 --- a/src/Doctrine/GeometryCollection.php +++ b/src/Doctrine/GeometryCollection.php @@ -7,7 +7,7 @@ class GeometryCollection extends Type { - const GEOMETRYCOLLECTION = 'geometrycollection'; + public const GEOMETRYCOLLECTION = 'geometrycollection'; public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) { diff --git a/src/Doctrine/LineString.php b/src/Doctrine/LineString.php index ac6e522..ca66a77 100644 --- a/src/Doctrine/LineString.php +++ b/src/Doctrine/LineString.php @@ -7,7 +7,7 @@ class LineString extends Type { - const LINESTRING = 'linestring'; + public const LINESTRING = 'linestring'; public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) { diff --git a/src/Doctrine/MultiLineString.php b/src/Doctrine/MultiLineString.php index dff48af..f3070a3 100644 --- a/src/Doctrine/MultiLineString.php +++ b/src/Doctrine/MultiLineString.php @@ -7,7 +7,7 @@ class MultiLineString extends Type { - const MULTILINESTRING = 'multilinestring'; + public const MULTILINESTRING = 'multilinestring'; public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) { diff --git a/src/Doctrine/MultiPoint.php b/src/Doctrine/MultiPoint.php index 55ead76..037719d 100644 --- a/src/Doctrine/MultiPoint.php +++ b/src/Doctrine/MultiPoint.php @@ -7,7 +7,7 @@ class MultiPoint extends Type { - const MULTIPOINT = 'multipoint'; + public const MULTIPOINT = 'multipoint'; public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) { diff --git a/src/Doctrine/MultiPolygon.php b/src/Doctrine/MultiPolygon.php index 6f25672..9a7cb80 100644 --- a/src/Doctrine/MultiPolygon.php +++ b/src/Doctrine/MultiPolygon.php @@ -7,7 +7,7 @@ class MultiPolygon extends Type { - const MULTIPOLYGON = 'multipolygon'; + public const MULTIPOLYGON = 'multipolygon'; public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) { diff --git a/src/Doctrine/Point.php b/src/Doctrine/Point.php index 4a26f44..3cba940 100644 --- a/src/Doctrine/Point.php +++ b/src/Doctrine/Point.php @@ -7,7 +7,7 @@ class Point extends Type { - const POINT = 'point'; + public const POINT = 'point'; public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) { diff --git a/src/Doctrine/Polygon.php b/src/Doctrine/Polygon.php index db9cdf7..171d769 100644 --- a/src/Doctrine/Polygon.php +++ b/src/Doctrine/Polygon.php @@ -7,7 +7,7 @@ class Polygon extends Type { - const POLYGON = 'polygon'; + public const POLYGON = 'polygon'; public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) { diff --git a/src/Eloquent/SpatialTrait.php b/src/Eloquent/SpatialTrait.php index abce63c..b5bc023 100755 --- a/src/Eloquent/SpatialTrait.php +++ b/src/Eloquent/SpatialTrait.php @@ -63,7 +63,7 @@ trait SpatialTrait * * @param \Illuminate\Database\Query\Builder $query * - * @return \Fleetbase\LaravelMysqlSpatial\Eloquent\Builder + * @return Builder */ public function newEloquentBuilder($query) { @@ -85,7 +85,7 @@ protected function performInsert(EloquentBuilder $query, array $options = []) { foreach ($this->attributes as $key => $value) { if ($value instanceof GeometryInterface) { - $this->geometries[$key] = $value; //Preserve the geometry objects prior to the insert + $this->geometries[$key] = $value; // Preserve the geometry objects prior to the insert $this->attributes[$key] = new SpatialExpression($value); } } @@ -93,10 +93,10 @@ protected function performInsert(EloquentBuilder $query, array $options = []) $insert = parent::performInsert($query, $options); foreach ($this->geometries as $key => $value) { - $this->attributes[$key] = $value; //Retrieve the geometry objects so they can be used in the model + $this->attributes[$key] = $value; // Retrieve the geometry objects so they can be used in the model } - return $insert; //Return the result of the parent insert + return $insert; // Return the result of the parent insert } public function setRawAttributes(array $attributes, $sync = false) @@ -117,7 +117,7 @@ public function getSpatialFields() if (property_exists($this, 'spatialFields')) { return $this->spatialFields; } else { - throw new SpatialFieldsNotDefinedException(__CLASS__.' has to define $spatialFields'); + throw new SpatialFieldsNotDefinedException(__CLASS__ . ' has to define $spatialFields'); } } diff --git a/src/Schema/Blueprint.php b/src/Schema/Blueprint.php index 2cde4fa..4c39b07 100644 --- a/src/Schema/Blueprint.php +++ b/src/Schema/Blueprint.php @@ -10,7 +10,7 @@ class Blueprint extends IlluminateBlueprint * Add a geometry column on the table. * * @param string $column - * @param null|int $srid + * @param int|null $srid * * @return \Illuminate\Support\Fluent */ @@ -23,7 +23,7 @@ public function geometry($column, $srid = null) * Add a point column on the table. * * @param string $column - * @param null|int $srid + * @param int|null $srid * * @return \Illuminate\Support\Fluent */ @@ -36,7 +36,7 @@ public function point($column, $srid = null) * Add a linestring column on the table. * * @param string $column - * @param null|int $srid + * @param int|null $srid * * @return \Illuminate\Support\Fluent */ @@ -49,7 +49,7 @@ public function lineString($column, $srid = null) * Add a polygon column on the table. * * @param string $column - * @param null|int $srid + * @param int|null $srid * * @return \Illuminate\Support\Fluent */ @@ -62,7 +62,7 @@ public function polygon($column, $srid = null) * Add a multipoint column on the table. * * @param string $column - * @param null|int $srid + * @param int|null $srid * * @return \Illuminate\Support\Fluent */ @@ -75,7 +75,7 @@ public function multiPoint($column, $srid = null) * Add a multilinestring column on the table. * * @param string $column - * @param null|int $srid + * @param int|null $srid * * @return \Illuminate\Support\Fluent */ @@ -88,7 +88,7 @@ public function multiLineString($column, $srid = null) * Add a multipolygon column on the table. * * @param string $column - * @param null|int $srid + * @param int|null $srid * * @return \Illuminate\Support\Fluent */ @@ -101,7 +101,7 @@ public function multiPolygon($column, $srid = null) * Add a geometrycollection column on the table. * * @param string $column - * @param null|int $srid + * @param int|null $srid * * @return \Illuminate\Support\Fluent */ diff --git a/src/Schema/Builder.php b/src/Schema/Builder.php index 1506319..a5d2533 100644 --- a/src/Schema/Builder.php +++ b/src/Schema/Builder.php @@ -10,12 +10,11 @@ class Builder extends MySqlBuilder /** * Create a new command set with a Closure. * - * @param string $table - * @param Closure $callback + * @param string $table * * @return Blueprint */ - protected function createBlueprint($table, Closure $callback = null) + protected function createBlueprint($table, ?\Closure $callback = null) { return new Blueprint($table, $callback); } diff --git a/src/Schema/Grammars/MySqlGrammar.php b/src/Schema/Grammars/MySqlGrammar.php index 85b18ba..23179e4 100644 --- a/src/Schema/Grammars/MySqlGrammar.php +++ b/src/Schema/Grammars/MySqlGrammar.php @@ -8,7 +8,7 @@ class MySqlGrammar extends IlluminateMySqlGrammar { - const COLUMN_MODIFIER_SRID = 'Srid'; + public const COLUMN_MODIFIER_SRID = 'Srid'; public function __construct() { @@ -21,8 +21,6 @@ public function __construct() /** * Adds a statement to add a geometry column. * - * @param Fluent $column - * * @return string */ public function typeGeometry(Fluent $column) @@ -33,8 +31,6 @@ public function typeGeometry(Fluent $column) /** * Adds a statement to add a point column. * - * @param Fluent $column - * * @return string */ public function typePoint(Fluent $column) @@ -45,8 +41,6 @@ public function typePoint(Fluent $column) /** * Adds a statement to add a linestring column. * - * @param Fluent $column - * * @return string */ public function typeLinestring(Fluent $column) @@ -57,8 +51,6 @@ public function typeLinestring(Fluent $column) /** * Adds a statement to add a polygon column. * - * @param Fluent $column - * * @return string */ public function typePolygon(Fluent $column) @@ -69,8 +61,6 @@ public function typePolygon(Fluent $column) /** * Adds a statement to add a multipoint column. * - * @param Fluent $column - * * @return string */ public function typeMultipoint(Fluent $column) @@ -81,8 +71,6 @@ public function typeMultipoint(Fluent $column) /** * Adds a statement to add a multilinestring column. * - * @param Fluent $column - * * @return string */ public function typeMultilinestring(Fluent $column) @@ -93,8 +81,6 @@ public function typeMultilinestring(Fluent $column) /** * Adds a statement to add a multipolygon column. * - * @param Fluent $column - * * @return string */ public function typeMultipolygon(Fluent $column) @@ -105,8 +91,6 @@ public function typeMultipolygon(Fluent $column) /** * Adds a statement to add a geometrycollection column. * - * @param Fluent $column - * * @return string */ public function typeGeometrycollection(Fluent $column) @@ -117,9 +101,6 @@ public function typeGeometrycollection(Fluent $column) /** * Compile a spatial index key command. * - * @param Blueprint $blueprint - * @param Fluent $command - * * @return string */ public function compileSpatial(Blueprint $blueprint, Fluent $command) @@ -130,15 +111,12 @@ public function compileSpatial(Blueprint $blueprint, Fluent $command) /** * Get the SQL for a SRID column modifier. * - * @param \Illuminate\Database\Schema\Blueprint $blueprint - * @param Fluent $column - * * @return string|null */ protected function modifySrid(\Illuminate\Database\Schema\Blueprint $blueprint, Fluent $column) { if (!is_null($column->srid) && is_int($column->srid) && $column->srid > 0) { - return ' srid '.$column->srid; + return ' srid ' . $column->srid; } } } diff --git a/src/Types/Geometry.php b/src/Types/Geometry.php index 42d9840..526286f 100644 --- a/src/Types/Geometry.php +++ b/src/Types/Geometry.php @@ -2,9 +2,9 @@ namespace Fleetbase\LaravelMysqlSpatial\Types; +use Fleetbase\LaravelMysqlSpatial\Exceptions\UnknownWKTTypeException; use GeoIO\WKB\Parser\Parser; use GeoJson\GeoJson; -use Fleetbase\LaravelMysqlSpatial\Exceptions\UnknownWKTTypeException; use Illuminate\Contracts\Support\Jsonable; abstract class Geometry implements GeometryInterface, Jsonable, \JsonSerializable @@ -38,7 +38,7 @@ public function setSrid($srid) public static function getWKTArgument($value) { - $left = strpos($value, '('); + $left = strpos($value, '('); $right = strrpos($value, ')'); return substr($value, $left + 1, $right - $left - 1); @@ -65,7 +65,7 @@ public static function getWKTClass($value) case 'GEOMETRYCOLLECTION': return GeometryCollection::class; default: - throw new UnknownWKTTypeException('Type was '.$type); + throw new UnknownWKTTypeException('Type was ' . $type); } } @@ -74,7 +74,7 @@ public static function fromWKB($wkb) $srid = substr($wkb, 0, 4); $srid = unpack('L', $srid)[1]; - $wkb = substr($wkb, 4); + $wkb = substr($wkb, 4); $parser = new Parser(new Factory()); /** @var Geometry $parsed */ @@ -108,7 +108,7 @@ public static function fromJson($geoJson) $geoJson = $geoJson->getGeometry(); } - $type = '\Fleetbase\LaravelMysqlSpatial\Types\\'.$geoJson->getType(); + $type = '\Fleetbase\LaravelMysqlSpatial\Types\\' . $geoJson->getType(); return $type::fromJson($geoJson); } diff --git a/src/Types/GeometryCollection.php b/src/Types/GeometryCollection.php index 8854f93..f943347 100755 --- a/src/Types/GeometryCollection.php +++ b/src/Types/GeometryCollection.php @@ -2,17 +2,12 @@ namespace Fleetbase\LaravelMysqlSpatial\Types; -use ArrayAccess; -use ArrayIterator; -use Countable; +use Fleetbase\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException; use GeoJson\Feature\FeatureCollection; use GeoJson\GeoJson; -use Fleetbase\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException; use Illuminate\Contracts\Support\Arrayable; -use InvalidArgumentException; -use IteratorAggregate; -class GeometryCollection extends Geometry implements IteratorAggregate, ArrayAccess, Arrayable, Countable +class GeometryCollection extends Geometry implements \IteratorAggregate, \ArrayAccess, Arrayable, \Countable { /** * The minimum number of items required to create this collection. @@ -39,7 +34,7 @@ class GeometryCollection extends Geometry implements IteratorAggregate, ArrayAcc * @param GeometryInterface[] $geometries * @param int $srid * - * @throws InvalidArgumentException + * @throws \InvalidArgumentException */ public function __construct(array $geometries, $srid = 0) { @@ -78,7 +73,7 @@ public static function fromString($wktArgument, $srid = 0) return new static(array_map(function ($geometry_string) { $klass = Geometry::getWKTClass($geometry_string); - return call_user_func($klass.'::fromWKT', $geometry_string); + return call_user_func($klass . '::fromWKT', $geometry_string); }, $geometry_strings), $srid); } @@ -89,7 +84,7 @@ public function toArray() public function getIterator() { - return new ArrayIterator($this->items); + return new \ArrayIterator($this->items); } public function offsetExists($offset) @@ -97,6 +92,7 @@ public function offsetExists($offset) return isset($this->items[$offset]); } + #[\ReturnTypeWillChange] public function offsetGet($offset) { return $this->offsetExists($offset) ? $this->items[$offset] : null; @@ -130,7 +126,7 @@ public static function fromJson($geoJson) } if (!is_a($geoJson, FeatureCollection::class)) { - throw new InvalidGeoJsonException('Expected '.FeatureCollection::class.', got '.get_class($geoJson)); + throw new InvalidGeoJsonException('Expected ' . FeatureCollection::class . ', got ' . get_class($geoJson)); } $set = []; @@ -146,6 +142,7 @@ public static function fromJson($geoJson) * * @return \GeoJson\Geometry\GeometryCollection */ + #[\ReturnTypeWillChange] public function jsonSerialize() { $geometries = []; @@ -158,8 +155,6 @@ public function jsonSerialize() /** * Checks whether the items are valid to create this collection. - * - * @param array $items */ protected function validateItems(array $items) { @@ -173,8 +168,6 @@ protected function validateItems(array $items) /** * Checks whether the array has enough items to generate a valid WKT. * - * @param array $items - * * @see $minimumCollectionItems */ protected function validateItemCount(array $items) @@ -182,30 +175,19 @@ protected function validateItemCount(array $items) if (count($items) < $this->minimumCollectionItems) { $entries = $this->minimumCollectionItems === 1 ? 'entry' : 'entries'; - throw new InvalidArgumentException(sprintf( - '%s must contain at least %d %s', - get_class($this), - $this->minimumCollectionItems, - $entries - )); + throw new \InvalidArgumentException(sprintf('%s must contain at least %d %s', get_class($this), $this->minimumCollectionItems, $entries)); } } /** * Checks the type of the items in the array. * - * @param $item - * * @see $collectionItemType */ protected function validateItemType($item) { if (!$item instanceof $this->collectionItemType) { - throw new InvalidArgumentException(sprintf( - '%s must be a collection of %s', - get_class($this), - $this->collectionItemType - )); + throw new \InvalidArgumentException(sprintf('%s must be a collection of %s', get_class($this), $this->collectionItemType)); } } } diff --git a/src/Types/LineString.php b/src/Types/LineString.php index 2b0e389..a9dd14e 100644 --- a/src/Types/LineString.php +++ b/src/Types/LineString.php @@ -2,9 +2,9 @@ namespace Fleetbase\LaravelMysqlSpatial\Types; +use Fleetbase\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException; use GeoJson\GeoJson; use GeoJson\Geometry\LineString as GeoJsonLineString; -use Fleetbase\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException; class LineString extends PointCollection { @@ -29,7 +29,7 @@ public static function fromWkt($wkt, $srid = 0) public static function fromString($wktArgument, $srid = 0) { - $pairs = explode(',', trim($wktArgument)); + $pairs = explode(',', trim($wktArgument)); $points = array_map(function ($pair) { return Point::fromPair($pair); }, $pairs); @@ -49,7 +49,7 @@ public static function fromJson($geoJson) } if (!is_a($geoJson, GeoJsonLineString::class)) { - throw new InvalidGeoJsonException('Expected '.GeoJsonLineString::class.', got '.get_class($geoJson)); + throw new InvalidGeoJsonException('Expected ' . GeoJsonLineString::class . ', got ' . get_class($geoJson)); } $set = []; @@ -63,8 +63,9 @@ public static function fromJson($geoJson) /** * Convert to GeoJson LineString that is jsonable to GeoJSON. * - * @return \GeoJson\Geometry\LineString + * @return GeoJsonLineString */ + #[\ReturnTypeWillChange] public function jsonSerialize() { $points = []; diff --git a/src/Types/MultiLineString.php b/src/Types/MultiLineString.php index 3b5309a..84d54d6 100644 --- a/src/Types/MultiLineString.php +++ b/src/Types/MultiLineString.php @@ -2,9 +2,9 @@ namespace Fleetbase\LaravelMysqlSpatial\Types; +use Fleetbase\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException; use GeoJson\GeoJson; use GeoJson\Geometry\MultiLineString as GeoJsonMultiLineString; -use Fleetbase\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException; class MultiLineString extends GeometryCollection { @@ -34,7 +34,7 @@ public function toWKT() public static function fromString($wktArgument, $srid = 0) { - $str = preg_split('/\)\s*,\s*\(/', substr(trim($wktArgument), 1, -1)); + $str = preg_split('/\)\s*,\s*\(/', substr(trim($wktArgument), 1, -1)); $lineStrings = array_map(function ($data) { return LineString::fromString($data); }, $str); @@ -63,7 +63,7 @@ public static function fromJson($geoJson) } if (!is_a($geoJson, GeoJsonMultiLineString::class)) { - throw new InvalidGeoJsonException('Expected '.GeoJsonMultiLineString::class.', got '.get_class($geoJson)); + throw new InvalidGeoJsonException('Expected ' . GeoJsonMultiLineString::class . ', got ' . get_class($geoJson)); } $set = []; @@ -81,8 +81,9 @@ public static function fromJson($geoJson) /** * Convert to GeoJson Point that is jsonable to GeoJSON. * - * @return \GeoJson\Geometry\MultiLineString + * @return GeoJsonMultiLineString */ + #[\ReturnTypeWillChange] public function jsonSerialize() { $lineStrings = []; diff --git a/src/Types/MultiPoint.php b/src/Types/MultiPoint.php index ebff2a2..35f275a 100644 --- a/src/Types/MultiPoint.php +++ b/src/Types/MultiPoint.php @@ -2,9 +2,9 @@ namespace Fleetbase\LaravelMysqlSpatial\Types; +use Fleetbase\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException; use GeoJson\GeoJson; use GeoJson\Geometry\MultiPoint as GeoJsonMultiPoint; -use Fleetbase\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException; class MultiPoint extends PointCollection { @@ -53,7 +53,7 @@ public static function fromJson($geoJson) } if (!is_a($geoJson, GeoJsonMultiPoint::class)) { - throw new InvalidGeoJsonException('Expected '.GeoJsonMultiPoint::class.', got '.get_class($geoJson)); + throw new InvalidGeoJsonException('Expected ' . GeoJsonMultiPoint::class . ', got ' . get_class($geoJson)); } $set = []; @@ -67,7 +67,7 @@ public static function fromJson($geoJson) /** * Convert to GeoJson MultiPoint that is jsonable to GeoJSON. * - * @return \GeoJson\Geometry\MultiPoint + * @return GeoJsonMultiPoint */ public function jsonSerialize() { diff --git a/src/Types/MultiPolygon.php b/src/Types/MultiPolygon.php index 5c427e4..8b4d390 100644 --- a/src/Types/MultiPolygon.php +++ b/src/Types/MultiPolygon.php @@ -2,9 +2,9 @@ namespace Fleetbase\LaravelMysqlSpatial\Types; +use Fleetbase\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException; use GeoJson\GeoJson; use GeoJson\Geometry\MultiPolygon as GeoJsonMultiPolygon; -use Fleetbase\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException; class MultiPolygon extends GeometryCollection { @@ -36,7 +36,7 @@ public function __toString() public static function fromString($wktArgument, $srid = 0) { - $parts = preg_split('/(\)\s*\)\s*,\s*\(\s*\()/', $wktArgument, -1, PREG_SPLIT_DELIM_CAPTURE); + $parts = preg_split('/(\)\s*\)\s*,\s*\(\s*\()/', $wktArgument, -1, PREG_SPLIT_DELIM_CAPTURE); $polygons = static::assembleParts($parts); return new static(array_map(function ($polygonString) { @@ -67,20 +67,18 @@ public function getPolygons() * "((-1 -1,-1 -2,-2 -2,-2 -1,-1 -1))", * "((-1 -1,-1 -2,-2 -2,-2 -1,-1 -1))" * - * @param array $parts - * * @return array */ protected static function assembleParts(array $parts) { $polygons = []; - $count = count($parts); + $count = count($parts); for ($i = 0; $i < $count; $i++) { if ($i % 2 !== 0) { list($end, $start) = explode(',', $parts[$i]); $polygons[$i - 1] .= $end; - $polygons[++$i] = $start.$parts[$i]; + $polygons[++$i] = $start . $parts[$i]; } else { $polygons[] = $parts[$i]; } @@ -103,7 +101,7 @@ public static function fromJson($geoJson) } if (!is_a($geoJson, GeoJsonMultiPolygon::class)) { - throw new InvalidGeoJsonException('Expected '.GeoJsonMultiPolygon::class.', got '.get_class($geoJson)); + throw new InvalidGeoJsonException('Expected ' . GeoJsonMultiPolygon::class . ', got ' . get_class($geoJson)); } $set = []; @@ -125,8 +123,9 @@ public static function fromJson($geoJson) /** * Convert to GeoJson MultiPolygon that is jsonable to GeoJSON. * - * @return \GeoJson\Geometry\MultiPolygon + * @return GeoJsonMultiPolygon */ + #[\ReturnTypeWillChange] public function jsonSerialize() { $polygons = []; diff --git a/src/Types/Point.php b/src/Types/Point.php index 28e062f..9821d63 100644 --- a/src/Types/Point.php +++ b/src/Types/Point.php @@ -2,9 +2,9 @@ namespace Fleetbase\LaravelMysqlSpatial\Types; +use Fleetbase\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException; use GeoJson\GeoJson; use GeoJson\Geometry\Point as GeoJsonPoint; -use Fleetbase\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException; class Point extends Geometry { @@ -42,7 +42,7 @@ public function setLng($lng) public function toPair() { - return $this->getLng().' '.$this->getLat(); + return $this->getLng() . ' ' . $this->getLat(); } public static function fromPair($pair, $srid = 0) @@ -62,15 +62,15 @@ public static function fromString($wktArgument, $srid = 0) return static::fromPair($wktArgument, $srid); } - public function __toString() + public function __toString(): string { - return $this->getLng().' '.$this->getLat(); + return $this->getLng() . ' ' . $this->getLat(); } /** - * @param $geoJson \GeoJson\Feature\Feature|string + * @param $geoJson \GeoJson\Feature\Feature|string * - * @return \Fleetbase\LaravelMysqlSpatial\Types\Point + * @return Point */ public static function fromJson($geoJson) { @@ -79,7 +79,7 @@ public static function fromJson($geoJson) } if (!is_a($geoJson, GeoJsonPoint::class)) { - throw new InvalidGeoJsonException('Expected '.GeoJsonPoint::class.', got '.get_class($geoJson)); + throw new InvalidGeoJsonException('Expected ' . GeoJsonPoint::class . ', got ' . get_class($geoJson)); } $coordinates = $geoJson->getCoordinates(); @@ -90,8 +90,9 @@ public static function fromJson($geoJson) /** * Convert to GeoJson Point that is jsonable to GeoJSON. * - * @return \GeoJson\Geometry\Point + * @return GeoJsonPoint */ + #[\ReturnTypeWillChange] public function jsonSerialize() { return new GeoJsonPoint([$this->getLng(), $this->getLat()]); diff --git a/src/Types/PointCollection.php b/src/Types/PointCollection.php index d63916c..5efebd0 100755 --- a/src/Types/PointCollection.php +++ b/src/Types/PointCollection.php @@ -3,7 +3,6 @@ namespace Fleetbase\LaravelMysqlSpatial\Types; use ArrayAccess; -use InvalidArgumentException; abstract class PointCollection extends GeometryCollection { @@ -37,8 +36,6 @@ public function getPoints() } /** - * @param \Fleetbase\LaravelMysqlSpatial\Types\Point $point - * * @deprecated 2.1.0 Use array_unshift($multipoint, $point); instead * @see array_unshift * @see ArrayAccess @@ -49,8 +46,6 @@ public function prependPoint(Point $point) } /** - * @param \Fleetbase\LaravelMysqlSpatial\Types\Point $point - * * @deprecated 2.1.0 Use $multipoint[] = $point; instead * @see ArrayAccess */ @@ -60,9 +55,6 @@ public function appendPoint(Point $point) } /** - * @param $index - * @param \Fleetbase\LaravelMysqlSpatial\Types\Point $point - * * @deprecated 2.1.0 Use array_splice($multipoint, $index, 0, [$point]); instead * @see array_splice * @see ArrayAccess @@ -70,7 +62,7 @@ public function appendPoint(Point $point) public function insertPoint($index, Point $point) { if (count($this->items) - 1 < $index) { - throw new InvalidArgumentException('$index is greater than the size of the array'); + throw new \InvalidArgumentException('$index is greater than the size of the array'); } array_splice($this->items, $index, 0, [$point]); diff --git a/src/Types/Polygon.php b/src/Types/Polygon.php index 19120a1..183c8ba 100644 --- a/src/Types/Polygon.php +++ b/src/Types/Polygon.php @@ -2,9 +2,9 @@ namespace Fleetbase\LaravelMysqlSpatial\Types; +use Fleetbase\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException; use GeoJson\GeoJson; use GeoJson\Geometry\Polygon as GeoJsonPolygon; -use Fleetbase\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException; class Polygon extends MultiLineString { @@ -20,7 +20,7 @@ public static function fromJson($geoJson) } if (!is_a($geoJson, GeoJsonPolygon::class)) { - throw new InvalidGeoJsonException('Expected '.GeoJsonPolygon::class.', got '.get_class($geoJson)); + throw new InvalidGeoJsonException('Expected ' . GeoJsonPolygon::class . ', got ' . get_class($geoJson)); } $set = []; @@ -38,8 +38,9 @@ public static function fromJson($geoJson) /** * Convert to GeoJson Polygon that is jsonable to GeoJSON. * - * @return \GeoJson\Geometry\Polygon + * @return GeoJsonPolygon */ + #[\ReturnTypeWillChange] public function jsonSerialize() { $linearRings = []; diff --git a/tests/Integration/IntegrationBaseTestCase.php b/tests/Integration/IntegrationBaseTestCase.php index 35e7176..523e41b 100644 --- a/tests/Integration/IntegrationBaseTestCase.php +++ b/tests/Integration/IntegrationBaseTestCase.php @@ -6,17 +6,17 @@ abstract class IntegrationBaseTestCase extends BaseTestCase { - protected $after_fix = false; + protected $after_fix = false; protected $migrations = []; /** * Boots the application. * - * @return \Illuminate\Foundation\Application + * @return Illuminate\Foundation\Application */ public function createApplication() { - $app = require __DIR__.'/../../vendor/laravel/laravel/bootstrap/app.php'; + $app = require __DIR__ . '/../../vendor/laravel/laravel/bootstrap/app.php'; $app->register(SpatialServiceProvider::class); $app->make('Illuminate\Contracts\Console\Kernel')->bootstrap(); @@ -54,9 +54,9 @@ public function setUp(): void (new $migrationClass())->up(); }); - //\DB::listen(function($sql) { + // \DB::listen(function($sql) { // var_dump($sql); - //}); + // }); } public function tearDown(): void @@ -71,8 +71,7 @@ public function tearDown(): void // MySQL 8.0.4 fixed bug #26941370 and bug #88031 private function isMySQL8AfterFix() { - $expression = DB::raw('select version()'); - $results = DB::select($expression->getValue(DB::connection()->getQueryGrammar())); + $results = DB::select(DB::raw('select version()')); $mysql_version = $results[0]->{'version()'}; return version_compare($mysql_version, '8.0.4', '>='); @@ -99,7 +98,7 @@ protected function assertException($exceptionName, $exceptionMessage = null) } } - private function onMigrations(\Closure $closure, $reverse_sort = false) + private function onMigrations(Closure $closure, $reverse_sort = false) { $migrations = $this->migrations; $reverse_sort ? rsort($migrations, SORT_STRING) : sort($migrations, SORT_STRING); diff --git a/tests/Integration/Migrations/CreateTables.php b/tests/Integration/Migrations/CreateTables.php index 7948fe4..4b9c980 100644 --- a/tests/Integration/Migrations/CreateTables.php +++ b/tests/Integration/Migrations/CreateTables.php @@ -14,7 +14,7 @@ class CreateLocationTable extends Migration public function up() { Schema::create('geometry', function (Blueprint $table) { - $table->charset = 'utf8mb4'; + $table->charset = 'utf8mb4'; $table->collation = 'utf8mb4_unicode_ci'; $table->increments('id'); $table->geometry('geo')->default(null)->nullable(); @@ -34,7 +34,7 @@ public function up() }); Schema::create('with_srid', function (Blueprint $table) { - $table->charset = 'utf8mb4'; + $table->charset = 'utf8mb4'; $table->collation = 'utf8mb4_unicode_ci'; $table->increments('id'); $table->geometry('geo', 3857)->default(null)->nullable(); diff --git a/tests/Integration/Migrations/UpdateTables.php b/tests/Integration/Migrations/UpdateTables.php index bab7e07..79c2d97 100644 --- a/tests/Integration/Migrations/UpdateTables.php +++ b/tests/Integration/Migrations/UpdateTables.php @@ -14,7 +14,7 @@ class UpdateLocationTable extends Migration public function up() { // MySQL < 5.7.5: table has to be MyISAM - \DB::statement('ALTER TABLE geometry ENGINE = MyISAM'); + DB::statement('ALTER TABLE geometry ENGINE = MyISAM'); Schema::table('geometry', function (Blueprint $table) { // Make sure point is not nullable @@ -45,7 +45,7 @@ public function down() $table->dropSpatialIndex(['location']); // either an array of column names or the index name }); - \DB::statement('ALTER TABLE geometry ENGINE = InnoDB'); + DB::statement('ALTER TABLE geometry ENGINE = InnoDB'); Schema::table('geometry', function (Blueprint $table) { $table->point('location')->nullable()->change(); diff --git a/tests/Integration/Models/GeometryModel.php b/tests/Integration/Models/GeometryModel.php index fb55db6..199f2de 100644 --- a/tests/Integration/Models/GeometryModel.php +++ b/tests/Integration/Models/GeometryModel.php @@ -7,9 +7,9 @@ * Class GeometryModel. * * @property int id - * @property \Fleetbase\LaravelMysqlSpatial\Types\Point location - * @property \Fleetbase\LaravelMysqlSpatial\Types\LineString line - * @property \Fleetbase\LaravelMysqlSpatial\Types\LineString shape + * @property Fleetbase\LaravelMysqlSpatial\Types\Point location + * @property Fleetbase\LaravelMysqlSpatial\Types\LineString line + * @property Fleetbase\LaravelMysqlSpatial\Types\LineString shape */ class GeometryModel extends Model { diff --git a/tests/Integration/Models/NoSpatialFieldsModel.php b/tests/Integration/Models/NoSpatialFieldsModel.php index 2bc0ba5..25bfb3f 100644 --- a/tests/Integration/Models/NoSpatialFieldsModel.php +++ b/tests/Integration/Models/NoSpatialFieldsModel.php @@ -6,7 +6,7 @@ /** * Class NoSpatialFieldsModel. * - * @property \Fleetbase\LaravelMysqlSpatial\Types\Geometry geometry + * @property Fleetbase\LaravelMysqlSpatial\Types\Geometry geometry */ class NoSpatialFieldsModel extends Model { diff --git a/tests/Integration/Models/WithSridModel.php b/tests/Integration/Models/WithSridModel.php index f4fb751..addfb6c 100644 --- a/tests/Integration/Models/WithSridModel.php +++ b/tests/Integration/Models/WithSridModel.php @@ -7,9 +7,9 @@ * Class WithSridModel. * * @property int id - * @property \Fleetbase\LaravelMysqlSpatial\Types\Point location - * @property \Fleetbase\LaravelMysqlSpatial\Types\LineString line - * @property \Fleetbase\LaravelMysqlSpatial\Types\LineString shape + * @property Fleetbase\LaravelMysqlSpatial\Types\Point location + * @property Fleetbase\LaravelMysqlSpatial\Types\LineString line + * @property Fleetbase\LaravelMysqlSpatial\Types\LineString shape */ class WithSridModel extends Model { diff --git a/tests/Integration/SpatialTest.php b/tests/Integration/SpatialTest.php index 35c5abb..611065d 100644 --- a/tests/Integration/SpatialTest.php +++ b/tests/Integration/SpatialTest.php @@ -16,17 +16,17 @@ class SpatialTest extends IntegrationBaseTestCase public function testSpatialFieldsNotDefinedException() { - $geo = new NoSpatialFieldsModel(); + $geo = new NoSpatialFieldsModel(); $geo->geometry = new Point(1, 2); $geo->save(); - $this->assertException(\Fleetbase\LaravelMysqlSpatial\Exceptions\SpatialFieldsNotDefinedException::class); + $this->assertException(Fleetbase\LaravelMysqlSpatial\Exceptions\SpatialFieldsNotDefinedException::class); NoSpatialFieldsModel::all(); } public function testInsertPoint() { - $geo = new GeometryModel(); + $geo = new GeometryModel(); $geo->location = new Point(1, 2); $geo->save(); $this->assertDatabaseHas('geometry', ['id' => $geo->id]); @@ -37,7 +37,7 @@ public function testInsertLineString() $geo = new GeometryModel(); $geo->location = new Point(1, 2); - $geo->line = new LineString([new Point(1, 1), new Point(2, 2)]); + $geo->line = new LineString([new Point(1, 1), new Point(2, 2)]); $geo->save(); $this->assertDatabaseHas('geometry', ['id' => $geo->id]); } @@ -47,7 +47,7 @@ public function testInsertPolygon() $geo = new GeometryModel(); $geo->location = new Point(1, 2); - $geo->shape = Polygon::fromWKT('POLYGON((0 10,10 10,10 0,0 0,0 10))'); + $geo->shape = Polygon::fromWKT('POLYGON((0 10,10 10,10 0,0 0,0 10))'); $geo->save(); $this->assertDatabaseHas('geometry', ['id' => $geo->id]); } @@ -56,7 +56,7 @@ public function testInsertMultiPoint() { $geo = new GeometryModel(); - $geo->location = new Point(1, 2); + $geo->location = new Point(1, 2); $geo->multi_locations = new MultiPoint([new Point(1, 1), new Point(2, 2)]); $geo->save(); $this->assertDatabaseHas('geometry', ['id' => $geo->id]); @@ -108,11 +108,11 @@ public function testInsertEmptyGeometryCollection() public function testUpdate() { - $geo = new GeometryModel(); + $geo = new GeometryModel(); $geo->location = new Point(1, 2); $geo->save(); - $to_update = GeometryModel::all()->first(); + $to_update = GeometryModel::all()->first(); $to_update->location = new Point(2, 3); $to_update->save(); @@ -129,15 +129,15 @@ public function testUpdate() public function testDistance() { - $loc1 = new GeometryModel(); + $loc1 = new GeometryModel(); $loc1->location = new Point(1, 1); $loc1->save(); - $loc2 = new GeometryModel(); + $loc2 = new GeometryModel(); $loc2->location = new Point(2, 2); // Distance from loc1: 1.4142135623731 $loc2->save(); - $loc3 = new GeometryModel(); + $loc3 = new GeometryModel(); $loc3->location = new Point(3, 3); // Distance from loc1: 2.8284271247462 $loc3->save(); @@ -163,15 +163,15 @@ public function testDistance() public function testDistanceSphere() { - $loc1 = new GeometryModel(); + $loc1 = new GeometryModel(); $loc1->location = new Point(40.767864, -73.971732); $loc1->save(); - $loc2 = new GeometryModel(); + $loc2 = new GeometryModel(); $loc2->location = new Point(40.767664, -73.971271); // Distance from loc1: 44.741406484588 $loc2->save(); - $loc3 = new GeometryModel(); + $loc3 = new GeometryModel(); $loc3->location = new Point(40.761434, -73.977619); // Distance from loc1: 870.06424066202 $loc3->save(); @@ -201,11 +201,11 @@ public function testDistanceSphere() public function testDistanceValue() { - $loc1 = new GeometryModel(); + $loc1 = new GeometryModel(); $loc1->location = new Point(1, 1); $loc1->save(); - $loc2 = new GeometryModel(); + $loc2 = new GeometryModel(); $loc2->location = new Point(2, 2); // Distance from loc1: 1.4142135623731 $loc2->save(); @@ -217,11 +217,11 @@ public function testDistanceValue() public function testDistanceSphereValue() { - $loc1 = new GeometryModel(); + $loc1 = new GeometryModel(); $loc1->location = new Point(40.767864, -73.971732); $loc1->save(); - $loc2 = new GeometryModel(); + $loc2 = new GeometryModel(); $loc2->location = new Point(40.767664, -73.971271); // Distance from loc1: 44.741406484236 $loc2->save(); @@ -238,24 +238,24 @@ public function testDistanceSphereValue() public function testOrderBySpatialWithUnknownFunction() { - $loc = new GeometryModel(); + $loc = new GeometryModel(); $loc->location = new Point(1, 1); - $this->assertException(\Fleetbase\LaravelMysqlSpatial\Exceptions\UnknownSpatialFunctionException::class); + $this->assertException(Fleetbase\LaravelMysqlSpatial\Exceptions\UnknownSpatialFunctionException::class); GeometryModel::orderBySpatial('location', $loc->location, 'does-not-exist')->get(); } public function testOrderByDistance() { - $loc2 = new GeometryModel(); + $loc2 = new GeometryModel(); $loc2->location = new Point(2, 2); // Distance from loc1: 1.4142135623731 $loc2->save(); - $loc1 = new GeometryModel(); + $loc1 = new GeometryModel(); $loc1->location = new Point(1, 1); $loc1->save(); - $loc3 = new GeometryModel(); + $loc3 = new GeometryModel(); $loc3->location = new Point(3, 3); // Distance from loc1: 2.8284271247462 $loc3->save(); @@ -281,15 +281,15 @@ public function testOrderByDistance() public function testOrderByDistanceSphere() { - $loc2 = new GeometryModel(); + $loc2 = new GeometryModel(); $loc2->location = new Point(40.767664, -73.971271); // Distance from loc1: 44.741406484588 $loc2->save(); - $loc1 = new GeometryModel(); + $loc1 = new GeometryModel(); $loc1->location = new Point(40.767864, -73.971732); $loc1->save(); - $loc3 = new GeometryModel(); + $loc3 = new GeometryModel(); $loc3->location = new Point(40.761434, -73.977619); // Distance from loc1: 870.06424066202 $loc3->save(); @@ -312,7 +312,7 @@ public function testOrderByDistanceSphere() $this->assertEquals($loc1->location, $c[2]->location); } - //public function testBounding() { + // public function testBounding() { // $point = new Point(0, 0); // // $linestring1 = \Fleetbase\LaravelMysqlSpatial\Types\LineString::fromWkt("LINESTRING(1 1, 2 2)"); @@ -342,5 +342,5 @@ public function testOrderByDistanceSphere() // $this->assertFalse($result->contains($geo2)); // $this->assertTrue($result->contains($geo3)); // - //} + // } } diff --git a/tests/Integration/SridSpatialTest.php b/tests/Integration/SridSpatialTest.php index d69cb39..6954604 100644 --- a/tests/Integration/SridSpatialTest.php +++ b/tests/Integration/SridSpatialTest.php @@ -16,7 +16,7 @@ class SridSpatialTest extends IntegrationBaseTestCase public function testInsertPointWithSrid() { - $geo = new WithSridModel(); + $geo = new WithSridModel(); $geo->location = new Point(1, 2, 3857); $geo->save(); $this->assertDatabaseHas('with_srid', ['id' => $geo->id]); @@ -27,7 +27,7 @@ public function testInsertLineStringWithSrid() $geo = new WithSridModel(); $geo->location = new Point(1, 2, 3857); - $geo->line = new LineString([new Point(1, 1), new Point(2, 2)], 3857); + $geo->line = new LineString([new Point(1, 1), new Point(2, 2)], 3857); $geo->save(); $this->assertDatabaseHas('with_srid', ['id' => $geo->id]); } @@ -37,7 +37,7 @@ public function testInsertPolygonWithSrid() $geo = new WithSridModel(); $geo->location = new Point(1, 2, 3857); - $geo->shape = Polygon::fromWKT('POLYGON((0 10,10 10,10 0,0 0,0 10))', 3857); + $geo->shape = Polygon::fromWKT('POLYGON((0 10,10 10,10 0,0 0,0 10))', 3857); $geo->save(); $this->assertDatabaseHas('with_srid', ['id' => $geo->id]); } @@ -46,7 +46,7 @@ public function testInsertMultiPointWithSrid() { $geo = new WithSridModel(); - $geo->location = new Point(1, 2, 3857); + $geo->location = new Point(1, 2, 3857); $geo->multi_locations = new MultiPoint([new Point(1, 1), new Point(2, 2)], 3857); $geo->save(); $this->assertDatabaseHas('with_srid', ['id' => $geo->id]); @@ -83,11 +83,11 @@ public function testInsertGeometryCollectionWithSrid() public function testUpdateWithSrid() { - $geo = new WithSridModel(); + $geo = new WithSridModel(); $geo->location = new Point(1, 2, 3857); $geo->save(); - $to_update = WithSridModel::all()->first(); + $to_update = WithSridModel::all()->first(); $to_update->location = new Point(2, 3, 3857); $to_update->save(); @@ -104,16 +104,16 @@ public function testUpdateWithSrid() public function testInsertPointWithWrongSrid() { - $geo = new WithSridModel(); + $geo = new WithSridModel(); $geo->location = new Point(1, 2); $this->assertException( Illuminate\Database\QueryException::class, - 'SQLSTATE[HY000]: General error: 3643 The SRID of the geometry '. - 'does not match the SRID of the column \'location\'. The SRID '. - 'of the geometry is 0, but the SRID of the column is 3857. '. - 'Consider changing the SRID of the geometry or the SRID property '. - 'of the column. (SQL: insert into `with_srid` (`location`) values '. + 'SQLSTATE[HY000]: General error: 3643 The SRID of the geometry ' . + 'does not match the SRID of the column \'location\'. The SRID ' . + 'of the geometry is 0, but the SRID of the column is 3857. ' . + 'Consider changing the SRID of the geometry or the SRID property ' . + 'of the column. (SQL: insert into `with_srid` (`location`) values ' . '(ST_GeomFromText(POINT(2 1), 0, \'axis-order=long-lat\')))' ); $geo->save(); @@ -121,11 +121,11 @@ public function testInsertPointWithWrongSrid() public function testGeometryInsertedHasRightSrid() { - $geo = new WithSridModel(); + $geo = new WithSridModel(); $geo->location = new Point(1, 2, 3857); $geo->save(); - $srid = \DB::selectOne('select ST_SRID(location) as srid from with_srid'); + $srid = DB::selectOne('select ST_SRID(location) as srid from with_srid'); $this->assertEquals(3857, $srid->srid); $result = WithSridModel::first(); diff --git a/tests/Unit/Connectors/ConnectionFactoryTest.php b/tests/Unit/Connectors/ConnectionFactoryTest.php index f323f59..cad8915 100644 --- a/tests/Unit/Connectors/ConnectionFactoryTest.php +++ b/tests/Unit/Connectors/ConnectionFactoryTest.php @@ -26,6 +26,6 @@ public function testCreateConnectionDifferentDriver() $factory->shouldAllowMockingProtectedMethods(); $conn = $factory->createConnection('pgsql', $pdo, 'database'); - $this->assertInstanceOf(\Illuminate\Database\PostgresConnection::class, $conn); + $this->assertInstanceOf(Illuminate\Database\PostgresConnection::class, $conn); } } diff --git a/tests/Unit/Eloquent/BuilderTest.php b/tests/Unit/Eloquent/BuilderTest.php index 4a8af8c..5503767 100644 --- a/tests/Unit/Eloquent/BuilderTest.php +++ b/tests/Unit/Eloquent/BuilderTest.php @@ -2,7 +2,6 @@ namespace Eloquent; -use BaseTestCase; use Fleetbase\LaravelMysqlSpatial\Eloquent\Builder; use Fleetbase\LaravelMysqlSpatial\Eloquent\SpatialExpression; use Fleetbase\LaravelMysqlSpatial\Eloquent\SpatialTrait; @@ -13,18 +12,17 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Query\Builder as QueryBuilder; use Illuminate\Database\Query\Grammars\MySqlGrammar; -use Mockery; -class BuilderTest extends BaseTestCase +class BuilderTest extends \BaseTestCase { protected $builder; protected $queryBuilder; protected function setUp() { - $connection = Mockery::mock(MysqlConnection::class)->makePartial(); - $grammar = Mockery::mock(MySqlGrammar::class)->makePartial(); - $this->queryBuilder = Mockery::mock(QueryBuilder::class, [$connection, $grammar]); + $connection = \Mockery::mock(MysqlConnection::class)->makePartial(); + $grammar = \Mockery::mock(MySqlGrammar::class)->makePartial(); + $this->queryBuilder = \Mockery::mock(QueryBuilder::class, [$connection, $grammar]); $this->queryBuilder ->shouldReceive('from') @@ -69,7 +67,7 @@ public function testUpdatePolygon() $linestrings[] = new LineString([new Point(0, 0), new Point(0, 1)]); $linestrings[] = new LineString([new Point(0, 1), new Point(1, 1)]); $linestrings[] = new LineString([new Point(1, 1), new Point(0, 0)]); - $polygon = new Polygon($linestrings); + $polygon = new Polygon($linestrings); $this->queryBuilder ->shouldReceive('update') @@ -116,7 +114,7 @@ public function testUpdatePolygonWithSrid() $linestrings[] = new LineString([new Point(0, 0), new Point(0, 1)]); $linestrings[] = new LineString([new Point(0, 1), new Point(1, 1)]); $linestrings[] = new LineString([new Point(1, 1), new Point(0, 0)]); - $polygon = new Polygon($linestrings, 4326); + $polygon = new Polygon($linestrings, 4326); $this->queryBuilder ->shouldReceive('update') @@ -134,6 +132,6 @@ class TestBuilderModel extends Model { use SpatialTrait; - public $timestamps = false; + public $timestamps = false; protected $spatialFields = ['point', 'linestring', 'polygon']; } diff --git a/tests/Unit/Eloquent/SpatialTraitTest.php b/tests/Unit/Eloquent/SpatialTraitTest.php index dd702ec..0378db0 100644 --- a/tests/Unit/Eloquent/SpatialTraitTest.php +++ b/tests/Unit/Eloquent/SpatialTraitTest.php @@ -23,7 +23,7 @@ class SpatialTraitTest extends BaseTestCase public function setUp(): void { - $this->model = new TestModel(); + $this->model = new TestModel(); $this->queries = &$this->model->getConnection()->getPdo()->queries; } @@ -59,7 +59,7 @@ public function testInsertUpdateLineStringHasCorrectSql() $this->assertFalse($this->model->exists); - $this->model->linestring = new \Fleetbase\LaravelMysqlSpatial\Types\LineString([$point1, $point2]); + $this->model->linestring = new Fleetbase\LaravelMysqlSpatial\Types\LineString([$point1, $point2]); $this->model->save(); $this->assertStringStartsWith('insert', $this->queries[0]); @@ -67,7 +67,7 @@ public function testInsertUpdateLineStringHasCorrectSql() // TODO: assert bindings in query $this->assertTrue($this->model->exists); - $this->model->linestring = new \Fleetbase\LaravelMysqlSpatial\Types\LineString([$point1, $point2]); + $this->model->linestring = new Fleetbase\LaravelMysqlSpatial\Types\LineString([$point1, $point2]); $this->model->save(); $this->assertStringStartsWith('update', $this->queries[1]); @@ -77,16 +77,16 @@ public function testInsertUpdateLineStringHasCorrectSql() public function testInsertUpdatePolygonHasCorrectSql() { - $point1 = new Point(1, 2); - $point2 = new Point(2, 3); - $linestring1 = new \Fleetbase\LaravelMysqlSpatial\Types\LineString([$point1, $point2]); - $point3 = new Point(3, 2); - $point4 = new Point(2, 1); - $linestring2 = new \Fleetbase\LaravelMysqlSpatial\Types\LineString([$point3, $point4]); + $point1 = new Point(1, 2); + $point2 = new Point(2, 3); + $linestring1 = new Fleetbase\LaravelMysqlSpatial\Types\LineString([$point1, $point2]); + $point3 = new Point(3, 2); + $point4 = new Point(2, 1); + $linestring2 = new Fleetbase\LaravelMysqlSpatial\Types\LineString([$point3, $point4]); $this->assertFalse($this->model->exists); - $this->model->polygon = new \Fleetbase\LaravelMysqlSpatial\Types\Polygon([$linestring1, $linestring2]); + $this->model->polygon = new Fleetbase\LaravelMysqlSpatial\Types\Polygon([$linestring1, $linestring2]); $this->model->save(); $this->assertStringStartsWith('insert', $this->queries[0]); @@ -94,7 +94,7 @@ public function testInsertUpdatePolygonHasCorrectSql() // TODO: assert bindings in query $this->assertTrue($this->model->exists); - $this->model->polygon = new \Fleetbase\LaravelMysqlSpatial\Types\Polygon([$linestring1, $linestring2]); + $this->model->polygon = new Fleetbase\LaravelMysqlSpatial\Types\Polygon([$linestring1, $linestring2]); $this->model->save(); $this->assertStringStartsWith('update', $this->queries[1]); $this->assertContains('update `test_models` set `polygon` = ST_GeomFromText(?, ?, \'axis-order=long-lat\') where `id` = ?', $this->queries[1]); @@ -108,7 +108,7 @@ public function testInsertUpdateMultiPointHasCorrectSql() $this->assertFalse($this->model->exists); - $this->model->multipoint = new \Fleetbase\LaravelMysqlSpatial\Types\MultiPoint([$point1, $point2]); + $this->model->multipoint = new Fleetbase\LaravelMysqlSpatial\Types\MultiPoint([$point1, $point2]); $this->model->save(); $this->assertStringStartsWith('insert', $this->queries[0]); @@ -116,7 +116,7 @@ public function testInsertUpdateMultiPointHasCorrectSql() // TODO: assert bindings in query $this->assertTrue($this->model->exists); - $this->model->multipoint = new \Fleetbase\LaravelMysqlSpatial\Types\MultiPoint([$point1, $point2]); + $this->model->multipoint = new Fleetbase\LaravelMysqlSpatial\Types\MultiPoint([$point1, $point2]); $this->model->save(); $this->assertStringStartsWith('update', $this->queries[1]); @@ -126,16 +126,16 @@ public function testInsertUpdateMultiPointHasCorrectSql() public function testInsertUpdateMultiLineStringHasCorrectSql() { - $point1 = new Point(1, 2); - $point2 = new Point(2, 3); - $linestring1 = new \Fleetbase\LaravelMysqlSpatial\Types\LineString([$point1, $point2]); - $point3 = new Point(3, 2); - $point4 = new Point(2, 1); - $linestring2 = new \Fleetbase\LaravelMysqlSpatial\Types\LineString([$point3, $point4]); + $point1 = new Point(1, 2); + $point2 = new Point(2, 3); + $linestring1 = new Fleetbase\LaravelMysqlSpatial\Types\LineString([$point1, $point2]); + $point3 = new Point(3, 2); + $point4 = new Point(2, 1); + $linestring2 = new Fleetbase\LaravelMysqlSpatial\Types\LineString([$point3, $point4]); $this->assertFalse($this->model->exists); - $this->model->multilinestring = new \Fleetbase\LaravelMysqlSpatial\Types\MultiLineString([$linestring1, $linestring2]); + $this->model->multilinestring = new Fleetbase\LaravelMysqlSpatial\Types\MultiLineString([$linestring1, $linestring2]); $this->model->save(); $this->assertStringStartsWith('insert', $this->queries[0]); @@ -143,7 +143,7 @@ public function testInsertUpdateMultiLineStringHasCorrectSql() // TODO: assert bindings in query $this->assertTrue($this->model->exists); - $this->model->multilinestring = new \Fleetbase\LaravelMysqlSpatial\Types\MultiLineString([$linestring1, $linestring2]); + $this->model->multilinestring = new Fleetbase\LaravelMysqlSpatial\Types\MultiLineString([$linestring1, $linestring2]); $this->model->save(); $this->assertStringStartsWith('update', $this->queries[1]); $this->assertContains('update `test_models` set `multilinestring` = ST_GeomFromText(?, ?, \'axis-order=long-lat\') where `id` = ?', $this->queries[1]); @@ -152,25 +152,25 @@ public function testInsertUpdateMultiLineStringHasCorrectSql() public function testInsertUpdateMultiPolygonHasCorrectSql() { - $point1 = new Point(1, 2); - $point2 = new Point(2, 3); - $linestring1 = new \Fleetbase\LaravelMysqlSpatial\Types\LineString([$point1, $point2]); - $point3 = new Point(3, 2); - $point4 = new Point(2, 1); - $linestring2 = new \Fleetbase\LaravelMysqlSpatial\Types\LineString([$point3, $point4]); - $polygon1 = new \Fleetbase\LaravelMysqlSpatial\Types\Polygon([$linestring1, $linestring2]); - - $point5 = new Point(4, 5); - $point6 = new Point(5, 6); - $linestring3 = new \Fleetbase\LaravelMysqlSpatial\Types\LineString([$point5, $point6]); - $point7 = new Point(6, 5); - $point8 = new Point(5, 4); - $linestring4 = new \Fleetbase\LaravelMysqlSpatial\Types\LineString([$point7, $point8]); - $polygon2 = new \Fleetbase\LaravelMysqlSpatial\Types\Polygon([$linestring3, $linestring4]); + $point1 = new Point(1, 2); + $point2 = new Point(2, 3); + $linestring1 = new Fleetbase\LaravelMysqlSpatial\Types\LineString([$point1, $point2]); + $point3 = new Point(3, 2); + $point4 = new Point(2, 1); + $linestring2 = new Fleetbase\LaravelMysqlSpatial\Types\LineString([$point3, $point4]); + $polygon1 = new Fleetbase\LaravelMysqlSpatial\Types\Polygon([$linestring1, $linestring2]); + + $point5 = new Point(4, 5); + $point6 = new Point(5, 6); + $linestring3 = new Fleetbase\LaravelMysqlSpatial\Types\LineString([$point5, $point6]); + $point7 = new Point(6, 5); + $point8 = new Point(5, 4); + $linestring4 = new Fleetbase\LaravelMysqlSpatial\Types\LineString([$point7, $point8]); + $polygon2 = new Fleetbase\LaravelMysqlSpatial\Types\Polygon([$linestring3, $linestring4]); $this->assertFalse($this->model->exists); - $this->model->multipolygon = new \Fleetbase\LaravelMysqlSpatial\Types\MultiPolygon([$polygon1, $polygon2]); + $this->model->multipolygon = new Fleetbase\LaravelMysqlSpatial\Types\MultiPolygon([$polygon1, $polygon2]); $this->model->save(); $this->assertStringStartsWith('insert', $this->queries[0]); @@ -178,7 +178,7 @@ public function testInsertUpdateMultiPolygonHasCorrectSql() // TODO: assert bindings in query $this->assertTrue($this->model->exists); - $this->model->multipolygon = new \Fleetbase\LaravelMysqlSpatial\Types\MultiPolygon([$polygon1, $polygon2]); + $this->model->multipolygon = new Fleetbase\LaravelMysqlSpatial\Types\MultiPolygon([$polygon1, $polygon2]); $this->model->save(); $this->assertStringStartsWith('update', $this->queries[1]); $this->assertContains('update `test_models` set `multipolygon` = ST_GeomFromText(?, ?, \'axis-order=long-lat\') where `id` = ?', $this->queries[1]); @@ -187,14 +187,14 @@ public function testInsertUpdateMultiPolygonHasCorrectSql() public function testInsertUpdateGeometryCollectionHasCorrectSql() { - $point1 = new Point(1, 2); - $point2 = new Point(2, 3); - $point3 = new Point(3, 3); - $linestring1 = new \Fleetbase\LaravelMysqlSpatial\Types\LineString([$point2, $point3]); + $point1 = new Point(1, 2); + $point2 = new Point(2, 3); + $point3 = new Point(3, 3); + $linestring1 = new Fleetbase\LaravelMysqlSpatial\Types\LineString([$point2, $point3]); $this->assertFalse($this->model->exists); - $this->model->geometrycollection = new \Fleetbase\LaravelMysqlSpatial\Types\GeometryCollection([$point1, $linestring1]); + $this->model->geometrycollection = new Fleetbase\LaravelMysqlSpatial\Types\GeometryCollection([$point1, $linestring1]); $this->model->save(); $this->assertStringStartsWith('insert', $this->queries[0]); @@ -202,7 +202,7 @@ public function testInsertUpdateGeometryCollectionHasCorrectSql() // TODO: assert bindings in query $this->assertTrue($this->model->exists); - $this->model->geometrycollection = new \Fleetbase\LaravelMysqlSpatial\Types\GeometryCollection([$point1, $linestring1]); + $this->model->geometrycollection = new Fleetbase\LaravelMysqlSpatial\Types\GeometryCollection([$point1, $linestring1]); $this->model->save(); $this->assertStringStartsWith('update', $this->queries[1]); $this->assertContains('update `test_models` set `geometrycollection` = ST_GeomFromText(?, ?, \'axis-order=long-lat\') where `id` = ?', $this->queries[1]); @@ -211,10 +211,10 @@ public function testInsertUpdateGeometryCollectionHasCorrectSql() public function testSettingRawAttributes() { - $attributes['point'] = "\0\0\0\0".'0101000000000000000000f03f0000000000000040'; + $attributes['point'] = "\0\0\0\0" . '0101000000000000000000f03f0000000000000040'; $this->model->setRawAttributes($attributes); - $this->assertInstanceOf(Point::class, ($this->model->point)); + $this->assertInstanceOf(Point::class, $this->model->point); } public function testSpatialFieldsNotDefinedException() @@ -232,7 +232,7 @@ public function testScopeDistance() $point = new Point(1, 2); $query = TestModel::distance('point', $point, 10); - $this->assertInstanceOf(\Fleetbase\LaravelMysqlSpatial\Eloquent\Builder::class, $query); + $this->assertInstanceOf(Fleetbase\LaravelMysqlSpatial\Eloquent\Builder::class, $query); $q = $query->getQuery(); $this->assertNotEmpty($q->wheres); $bindings = $q->getRawBindings()['where']; @@ -247,7 +247,7 @@ public function testScopeDistanceExcludingSelf() $point = new Point(1, 2); $query = TestModel::distanceExcludingSelf('point', $point, 10); - $this->assertInstanceOf(\Fleetbase\LaravelMysqlSpatial\Eloquent\Builder::class, $query); + $this->assertInstanceOf(Fleetbase\LaravelMysqlSpatial\Eloquent\Builder::class, $query); $q = $query->getQuery(); $this->assertNotEmpty($q->wheres); $bindings = $q->getRawBindings()['where']; @@ -264,7 +264,7 @@ public function testScopeDistanceSphere() $point = new Point(1, 2); $query = TestModel::distanceSphere('point', $point, 10); - $this->assertInstanceOf(\Fleetbase\LaravelMysqlSpatial\Eloquent\Builder::class, $query); + $this->assertInstanceOf(Fleetbase\LaravelMysqlSpatial\Eloquent\Builder::class, $query); $q = $query->getQuery(); $this->assertNotEmpty($q->wheres); $bindings = $q->getRawBindings()['where']; @@ -279,7 +279,7 @@ public function testScopeDistanceSphereExcludingSelf() $point = new Point(1, 2); $query = TestModel::distanceSphereExcludingSelf('point', $point, 10); - $this->assertInstanceOf(\Fleetbase\LaravelMysqlSpatial\Eloquent\Builder::class, $query); + $this->assertInstanceOf(Fleetbase\LaravelMysqlSpatial\Eloquent\Builder::class, $query); $q = $query->getQuery(); $this->assertNotEmpty($q->wheres); $bindings = $q->getRawBindings()['where']; @@ -296,13 +296,13 @@ public function testScopeDistanceValue() $point = new Point(1, 2); $query = TestModel::distanceValue('point', $point); - $this->assertInstanceOf(\Fleetbase\LaravelMysqlSpatial\Eloquent\Builder::class, $query); + $this->assertInstanceOf(Fleetbase\LaravelMysqlSpatial\Eloquent\Builder::class, $query); $q = $query->getQuery(); $this->assertNotEmpty($q->columns); $bindings = $q->getRawBindings()['select']; $this->assertNotEmpty($bindings); $this->assertEquals('*', $q->columns[0]); - $this->assertInstanceOf(\Illuminate\Database\Query\Expression::class, $q->columns[1]); + $this->assertInstanceOf(Illuminate\Database\Query\Expression::class, $q->columns[1]); $this->assertEquals('st_distance(`point`, ST_GeomFromText(?, ?, \'axis-order=long-lat\')) as distance', $q->columns[1]->getValue()); $this->assertEquals('POINT(2 1)', $bindings[0]); } @@ -312,13 +312,13 @@ public function testScopeDistanceValueWithSelect() $point = new Point(1, 2); $query = TestModel::select('some_column')->distanceValue('point', $point); - $this->assertInstanceOf(\Fleetbase\LaravelMysqlSpatial\Eloquent\Builder::class, $query); + $this->assertInstanceOf(Fleetbase\LaravelMysqlSpatial\Eloquent\Builder::class, $query); $q = $query->getQuery(); $this->assertNotEmpty($q->columns); $bindings = $q->getRawBindings()['select']; $this->assertNotEmpty($bindings); $this->assertEquals('some_column', $q->columns[0]); - $this->assertInstanceOf(\Illuminate\Database\Query\Expression::class, $q->columns[1]); + $this->assertInstanceOf(Illuminate\Database\Query\Expression::class, $q->columns[1]); $this->assertEquals('st_distance(`point`, ST_GeomFromText(?, ?, \'axis-order=long-lat\')) as distance', $q->columns[1]->getValue()); $this->assertEquals('POINT(2 1)', $bindings[0]); } @@ -328,13 +328,13 @@ public function testScopeDistanceSphereValue() $point = new Point(1, 2); $query = TestModel::distanceSphereValue('point', $point); - $this->assertInstanceOf(\Fleetbase\LaravelMysqlSpatial\Eloquent\Builder::class, $query); + $this->assertInstanceOf(Fleetbase\LaravelMysqlSpatial\Eloquent\Builder::class, $query); $q = $query->getQuery(); $this->assertNotEmpty($q->columns); $bindings = $q->getRawBindings()['select']; $this->assertNotEmpty($bindings); $this->assertEquals('*', $q->columns[0]); - $this->assertInstanceOf(\Illuminate\Database\Query\Expression::class, $q->columns[1]); + $this->assertInstanceOf(Illuminate\Database\Query\Expression::class, $q->columns[1]); $this->assertEquals('st_distance_sphere(`point`, ST_GeomFromText(?, ?, \'axis-order=long-lat\')) as distance', $q->columns[1]->getValue()); $this->assertEquals('POINT(2 1)', $bindings[0]); } @@ -344,37 +344,37 @@ public function testScopeDistanceSphereValueWithSelect() $point = new Point(1, 2); $query = TestModel::select('some_column')->distanceSphereValue('point', $point); - $this->assertInstanceOf(\Fleetbase\LaravelMysqlSpatial\Eloquent\Builder::class, $query); + $this->assertInstanceOf(Fleetbase\LaravelMysqlSpatial\Eloquent\Builder::class, $query); $q = $query->getQuery(); $this->assertNotEmpty($q->columns); $bindings = $q->getRawBindings()['select']; $this->assertNotEmpty($bindings); $this->assertEquals('some_column', $q->columns[0]); - $this->assertInstanceOf(\Illuminate\Database\Query\Expression::class, $q->columns[1]); + $this->assertInstanceOf(Illuminate\Database\Query\Expression::class, $q->columns[1]); $this->assertEquals('st_distance_sphere(`point`, ST_GeomFromText(?, ?, \'axis-order=long-lat\')) as distance', $q->columns[1]->getValue()); $this->assertEquals('POINT(2 1)', $bindings[0]); } private function buildTestPolygon() { - $point1 = new Point(1, 1); - $point2 = new Point(1, 2); - $linestring1 = new \Fleetbase\LaravelMysqlSpatial\Types\LineString([$point1, $point2]); - $point3 = new Point(1, 2); - $point4 = new Point(2, 2); - $linestring2 = new \Fleetbase\LaravelMysqlSpatial\Types\LineString([$point3, $point4]); - $point5 = new Point(2, 2); - $point6 = new Point(1, 1); - $linestring3 = new \Fleetbase\LaravelMysqlSpatial\Types\LineString([$point5, $point6]); + $point1 = new Point(1, 1); + $point2 = new Point(1, 2); + $linestring1 = new Fleetbase\LaravelMysqlSpatial\Types\LineString([$point1, $point2]); + $point3 = new Point(1, 2); + $point4 = new Point(2, 2); + $linestring2 = new Fleetbase\LaravelMysqlSpatial\Types\LineString([$point3, $point4]); + $point5 = new Point(2, 2); + $point6 = new Point(1, 1); + $linestring3 = new Fleetbase\LaravelMysqlSpatial\Types\LineString([$point5, $point6]); - return new \Fleetbase\LaravelMysqlSpatial\Types\Polygon([$linestring1, $linestring2, $linestring3]); + return new Fleetbase\LaravelMysqlSpatial\Types\Polygon([$linestring1, $linestring2, $linestring3]); } public function testScopeComparison() { $query = TestModel::comparison('point', $this->buildTestPolygon(), 'within'); - $this->assertInstanceOf(\Fleetbase\LaravelMysqlSpatial\Eloquent\Builder::class, $query); + $this->assertInstanceOf(Fleetbase\LaravelMysqlSpatial\Eloquent\Builder::class, $query); $q = $query->getQuery(); $this->assertNotEmpty($q->wheres); $bindings = $q->getRawBindings()['where']; @@ -387,7 +387,7 @@ public function testScopeWithin() { $query = TestModel::within('point', $this->buildTestPolygon()); - $this->assertInstanceOf(\Fleetbase\LaravelMysqlSpatial\Eloquent\Builder::class, $query); + $this->assertInstanceOf(Fleetbase\LaravelMysqlSpatial\Eloquent\Builder::class, $query); $q = $query->getQuery(); $this->assertNotEmpty($q->wheres); $bindings = $q->getRawBindings()['where']; @@ -400,7 +400,7 @@ public function testScopeCrosses() { $query = TestModel::crosses('point', $this->buildTestPolygon()); - $this->assertInstanceOf(\Fleetbase\LaravelMysqlSpatial\Eloquent\Builder::class, $query); + $this->assertInstanceOf(Fleetbase\LaravelMysqlSpatial\Eloquent\Builder::class, $query); $q = $query->getQuery(); $this->assertNotEmpty($q->wheres); $bindings = $q->getRawBindings()['where']; @@ -413,7 +413,7 @@ public function testScopeContains() { $query = TestModel::contains('point', $this->buildTestPolygon()); - $this->assertInstanceOf(\Fleetbase\LaravelMysqlSpatial\Eloquent\Builder::class, $query); + $this->assertInstanceOf(Fleetbase\LaravelMysqlSpatial\Eloquent\Builder::class, $query); $q = $query->getQuery(); $this->assertNotEmpty($q->wheres); $bindings = $q->getRawBindings()['where']; @@ -426,7 +426,7 @@ public function testScopeDisjoint() { $query = TestModel::disjoint('point', $this->buildTestPolygon()); - $this->assertInstanceOf(\Fleetbase\LaravelMysqlSpatial\Eloquent\Builder::class, $query); + $this->assertInstanceOf(Fleetbase\LaravelMysqlSpatial\Eloquent\Builder::class, $query); $q = $query->getQuery(); $this->assertNotEmpty($q->wheres); $bindings = $q->getRawBindings()['where']; @@ -439,7 +439,7 @@ public function testScopeEquals() { $query = TestModel::equals('point', $this->buildTestPolygon()); - $this->assertInstanceOf(\Fleetbase\LaravelMysqlSpatial\Eloquent\Builder::class, $query); + $this->assertInstanceOf(Fleetbase\LaravelMysqlSpatial\Eloquent\Builder::class, $query); $q = $query->getQuery(); $this->assertNotEmpty($q->wheres); $bindings = $q->getRawBindings()['where']; @@ -452,7 +452,7 @@ public function testScopeIntersects() { $query = TestModel::intersects('point', $this->buildTestPolygon()); - $this->assertInstanceOf(\Fleetbase\LaravelMysqlSpatial\Eloquent\Builder::class, $query); + $this->assertInstanceOf(Fleetbase\LaravelMysqlSpatial\Eloquent\Builder::class, $query); $q = $query->getQuery(); $this->assertNotEmpty($q->wheres); $bindings = $q->getRawBindings()['where']; @@ -465,7 +465,7 @@ public function testScopeOverlaps() { $query = TestModel::overlaps('point', $this->buildTestPolygon()); - $this->assertInstanceOf(\Fleetbase\LaravelMysqlSpatial\Eloquent\Builder::class, $query); + $this->assertInstanceOf(Fleetbase\LaravelMysqlSpatial\Eloquent\Builder::class, $query); $q = $query->getQuery(); $this->assertNotEmpty($q->wheres); $bindings = $q->getRawBindings()['where']; @@ -478,7 +478,7 @@ public function testScopeDoesTouch() { $query = TestModel::doesTouch('point', $this->buildTestPolygon()); - $this->assertInstanceOf(\Fleetbase\LaravelMysqlSpatial\Eloquent\Builder::class, $query); + $this->assertInstanceOf(Fleetbase\LaravelMysqlSpatial\Eloquent\Builder::class, $query); $q = $query->getQuery(); $this->assertNotEmpty($q->wheres); $bindings = $q->getRawBindings()['where']; @@ -491,7 +491,7 @@ public function testScopeOrderBySpatialThrowsExceptionWhenFunctionNotRegistered( { $point = new Point(1, 2); $this->assertException( - \Fleetbase\LaravelMysqlSpatial\Exceptions\UnknownSpatialFunctionException::class, + Fleetbase\LaravelMysqlSpatial\Exceptions\UnknownSpatialFunctionException::class, 'does-not-exist' ); TestModel::orderBySpatial('point', $point, 'does-not-exist'); @@ -502,7 +502,7 @@ public function testScopeOrderByDistance() $point = new Point(1, 2); $query = TestModel::orderByDistance('point', $point); - $this->assertInstanceOf(\Fleetbase\LaravelMysqlSpatial\Eloquent\Builder::class, $query); + $this->assertInstanceOf(Fleetbase\LaravelMysqlSpatial\Eloquent\Builder::class, $query); $q = $query->getQuery(); $this->assertNotEmpty($q->orders); $bindings = $q->getRawBindings()['order']; @@ -516,7 +516,7 @@ public function testScopeOrderByDistanceSphere() $point = new Point(1, 2); $query = TestModel::orderByDistanceSphere('point', $point); - $this->assertInstanceOf(\Fleetbase\LaravelMysqlSpatial\Eloquent\Builder::class, $query); + $this->assertInstanceOf(Fleetbase\LaravelMysqlSpatial\Eloquent\Builder::class, $query); $q = $query->getQuery(); $this->assertNotEmpty($q->orders); $bindings = $q->getRawBindings()['order']; @@ -528,7 +528,7 @@ public function testScopeOrderByDistanceSphere() class TestModel extends Model { - use \Fleetbase\LaravelMysqlSpatial\Eloquent\SpatialTrait; + use Fleetbase\LaravelMysqlSpatial\Eloquent\SpatialTrait; protected $spatialFields = ['point']; // TODO: only required when fetching, not saving @@ -571,7 +571,7 @@ public function testmodels() class TestNoSpatialModel extends Model { - use \Fleetbase\LaravelMysqlSpatial\Eloquent\SpatialTrait; + use Fleetbase\LaravelMysqlSpatial\Eloquent\SpatialTrait; } class TestPDO extends PDO diff --git a/tests/Unit/MysqlConnectionTest.php b/tests/Unit/MysqlConnectionTest.php index 652b10f..42aa642 100644 --- a/tests/Unit/MysqlConnectionTest.php +++ b/tests/Unit/MysqlConnectionTest.php @@ -11,7 +11,7 @@ class MysqlConnectionTest extends TestCase protected function setUp(): void { - $mysqlConfig = ['driver' => 'mysql', 'prefix' => 'prefix', 'database' => 'database', 'name' => 'foo']; + $mysqlConfig = ['driver' => 'mysql', 'prefix' => 'prefix', 'database' => 'database', 'name' => 'foo']; $this->mysqlConnection = new MysqlConnection(new PDOStub(), 'database', 'prefix', $mysqlConfig); } diff --git a/tests/Unit/Schema/BlueprintTest.php b/tests/Unit/Schema/BlueprintTest.php index b926ce0..fcb67be 100644 --- a/tests/Unit/Schema/BlueprintTest.php +++ b/tests/Unit/Schema/BlueprintTest.php @@ -2,15 +2,13 @@ namespace Schema; -use BaseTestCase; use Fleetbase\LaravelMysqlSpatial\Schema\Blueprint; use Illuminate\Database\Schema\ColumnDefinition; -use Mockery; -class BlueprintTest extends BaseTestCase +class BlueprintTest extends \BaseTestCase { /** - * @var \Fleetbase\LaravelMysqlSpatial\Schema\Blueprint + * @var Blueprint */ protected $blueprint; @@ -18,7 +16,7 @@ public function setUp(): void { parent::setUp(); - $this->blueprint = Mockery::mock(Blueprint::class) + $this->blueprint = \Mockery::mock(Blueprint::class) ->makePartial()->shouldAllowMockingProtectedMethods(); } diff --git a/tests/Unit/Schema/BuilderTest.php b/tests/Unit/Schema/BuilderTest.php index 689e90f..9bdb07d 100644 --- a/tests/Unit/Schema/BuilderTest.php +++ b/tests/Unit/Schema/BuilderTest.php @@ -2,20 +2,18 @@ namespace Schema; -use BaseTestCase; use Fleetbase\LaravelMysqlSpatial\MysqlConnection; use Fleetbase\LaravelMysqlSpatial\Schema\Blueprint; use Fleetbase\LaravelMysqlSpatial\Schema\Builder; -use Mockery; -class BuilderTest extends BaseTestCase +class BuilderTest extends \BaseTestCase { public function testReturnsCorrectBlueprint() { - $connection = Mockery::mock(MysqlConnection::class); + $connection = \Mockery::mock(MysqlConnection::class); $connection->shouldReceive('getSchemaGrammar')->once()->andReturn(null); - $mock = Mockery::mock(Builder::class, [$connection]); + $mock = \Mockery::mock(Builder::class, [$connection]); $mock->makePartial()->shouldAllowMockingProtectedMethods(); $blueprint = $mock->createBlueprint('test', function () { }); diff --git a/tests/Unit/Types/GeometryCollectionTest.php b/tests/Unit/Types/GeometryCollectionTest.php index fea5d9d..be2909a 100644 --- a/tests/Unit/Types/GeometryCollectionTest.php +++ b/tests/Unit/Types/GeometryCollectionTest.php @@ -28,7 +28,7 @@ public function testToWKT() public function testJsonSerialize() { - $this->assertInstanceOf(\GeoJson\Geometry\GeometryCollection::class, $this->getGeometryCollection()->jsonSerialize()); + $this->assertInstanceOf(GeoJson\Geometry\GeometryCollection::class, $this->getGeometryCollection()->jsonSerialize()); $this->assertSame('{"type":"GeometryCollection","geometries":[{"type":"LineString","coordinates":[[0,0],[1,0],[1,1],[0,1],[0,0]]},{"type":"Point","coordinates":[200,100]}]}', json_encode($this->getGeometryCollection()->jsonSerialize())); } @@ -85,8 +85,8 @@ public function testIteratorAggregate() public function testArrayAccess() { - $linestring = $this->getLineString(); - $point = $this->getPoint(); + $linestring = $this->getLineString(); + $point = $this->getPoint(); $geometryCollection = new GeometryCollection([$linestring, $point]); // assert getting @@ -94,7 +94,7 @@ public function testArrayAccess() $this->assertEquals($point, $geometryCollection[1]); // assert setting - $polygon = $this->getPolygon(); + $polygon = $this->getPolygon(); $geometryCollection[] = $polygon; $this->assertEquals($polygon, $geometryCollection[2]); @@ -105,7 +105,7 @@ public function testArrayAccess() $this->assertEquals($polygon, $geometryCollection[2]); // assert insert - $point100 = new Point(100, 100); + $point100 = new Point(100, 100); $geometryCollection[100] = $point100; $this->assertEquals($point100, $geometryCollection[100]); @@ -130,7 +130,7 @@ public function testFromJson() public function testInvalidGeoJsonException() { $this->assertException( - \Fleetbase\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class, + Fleetbase\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class, sprintf('Expected %s, got %s', GeoJson\Feature\FeatureCollection::class, GeoJson\Geometry\Point::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 eb1aac5..3fd759e 100644 --- a/tests/Unit/Types/GeometryTest.php +++ b/tests/Unit/Types/GeometryTest.php @@ -43,18 +43,18 @@ public function testGetWKBClass() { $prefix = "\0\0\0\0"; - $this->assertInstanceOf(Point::class, Geometry::fromWKB($prefix.'0101000000000000000000f03f0000000000000040')); - - $this->assertInstanceOf(LineString::class, Geometry::fromWKB($prefix.'010200000002000000000000000000f03f000000000000004000000000000008400000000000001040')); - $this->assertInstanceOf(Polygon::class, Geometry::fromWKB($prefix.'01030000000100000004000000000000000000f03f00000000000000400000000000000840000000000000104000000000000014400000000000001840000000000000f03f0000000000000040')); - $this->assertInstanceOf(MultiPoint::class, Geometry::fromWKB($prefix.'0104000000020000000101000000000000000000f03f0000000000000040010100000000000000000008400000000000001040')); - $this->assertInstanceOf(MultiLineString::class, Geometry::fromWKB($prefix.'010500000001000000010200000002000000000000000000f03f000000000000004000000000000008400000000000001040')); - $this->assertInstanceOf(MultiLineString::class, Geometry::fromWKB($prefix.'010500000002000000010200000002000000000000000000f03f000000000000004000000000000008400000000000001040010200000002000000000000000000144000000000000018400000000000001c400000000000002040')); - $this->assertInstanceOf(MultiPolygon::class, Geometry::fromWKB($prefix.'01060000000200000001030000000100000004000000000000000000f03f00000000000000400000000000000840000000000000104000000000000014400000000000001840000000000000f03f000000000000004001030000000300000004000000000000000000f03f00000000000000400000000000000840000000000000104000000000000014400000000000001840000000000000f03f000000000000004004000000000000000000264000000000000028400000000000002a400000000000002c400000000000002e4000000000000030400000000000002640000000000000284004000000000000000000354000000000000036400000000000003740000000000000384000000000000039400000000000003a4000000000000035400000000000003640')); - $this->assertInstanceOf(GeometryCollection::class, Geometry::fromWKB($prefix.'0107000000010000000101000000000000000000f03f0000000000000040')); - $this->assertInstanceOf(GeometryCollection::class, Geometry::fromWKB($prefix.'0107000000020000000101000000000000000000f03f0000000000000040010200000002000000000000000000f03f000000000000004000000000000008400000000000001040')); - - $this->assertInstanceOf(Point::class, Geometry::fromWKB($prefix.'0101000000000000000000f03f0000000000000040')); + $this->assertInstanceOf(Point::class, Geometry::fromWKB($prefix . '0101000000000000000000f03f0000000000000040')); + + $this->assertInstanceOf(LineString::class, Geometry::fromWKB($prefix . '010200000002000000000000000000f03f000000000000004000000000000008400000000000001040')); + $this->assertInstanceOf(Polygon::class, Geometry::fromWKB($prefix . '01030000000100000004000000000000000000f03f00000000000000400000000000000840000000000000104000000000000014400000000000001840000000000000f03f0000000000000040')); + $this->assertInstanceOf(MultiPoint::class, Geometry::fromWKB($prefix . '0104000000020000000101000000000000000000f03f0000000000000040010100000000000000000008400000000000001040')); + $this->assertInstanceOf(MultiLineString::class, Geometry::fromWKB($prefix . '010500000001000000010200000002000000000000000000f03f000000000000004000000000000008400000000000001040')); + $this->assertInstanceOf(MultiLineString::class, Geometry::fromWKB($prefix . '010500000002000000010200000002000000000000000000f03f000000000000004000000000000008400000000000001040010200000002000000000000000000144000000000000018400000000000001c400000000000002040')); + $this->assertInstanceOf(MultiPolygon::class, Geometry::fromWKB($prefix . '01060000000200000001030000000100000004000000000000000000f03f00000000000000400000000000000840000000000000104000000000000014400000000000001840000000000000f03f000000000000004001030000000300000004000000000000000000f03f00000000000000400000000000000840000000000000104000000000000014400000000000001840000000000000f03f000000000000004004000000000000000000264000000000000028400000000000002a400000000000002c400000000000002e4000000000000030400000000000002640000000000000284004000000000000000000354000000000000036400000000000003740000000000000384000000000000039400000000000003a4000000000000035400000000000003640')); + $this->assertInstanceOf(GeometryCollection::class, Geometry::fromWKB($prefix . '0107000000010000000101000000000000000000f03f0000000000000040')); + $this->assertInstanceOf(GeometryCollection::class, Geometry::fromWKB($prefix . '0107000000020000000101000000000000000000f03f0000000000000040010200000002000000000000000000f03f000000000000004000000000000008400000000000001040')); + + $this->assertInstanceOf(Point::class, Geometry::fromWKB($prefix . '0101000000000000000000f03f0000000000000040')); } public function testFromJsonPoint() diff --git a/tests/Unit/Types/LineStringTest.php b/tests/Unit/Types/LineStringTest.php index e0324b6..812306b 100644 --- a/tests/Unit/Types/LineStringTest.php +++ b/tests/Unit/Types/LineStringTest.php @@ -46,8 +46,8 @@ public function testFromJson() public function testInvalidGeoJsonException() { $this->assertException( - \Fleetbase\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class, - sprintf('Expected %s, got %s', \GeoJson\Geometry\LineString::class, GeoJson\Geometry\Point::class) + Fleetbase\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class, + sprintf('Expected %s, got %s', GeoJson\Geometry\LineString::class, GeoJson\Geometry\Point::class) ); LineString::fromJson('{"type":"Point","coordinates":[3.4,1.2]}'); } @@ -56,7 +56,7 @@ public function testJsonSerialize() { $lineString = new LineString($this->points); - $this->assertInstanceOf(\GeoJson\Geometry\LineString::class, $lineString->jsonSerialize()); + $this->assertInstanceOf(GeoJson\Geometry\LineString::class, $lineString->jsonSerialize()); $this->assertSame('{"type":"LineString","coordinates":[[0,0],[1,1],[2,2]]}', json_encode($lineString)); } } diff --git a/tests/Unit/Types/MultiLineStringTest.php b/tests/Unit/Types/MultiLineStringTest.php index a2ddfeb..1827aa6 100644 --- a/tests/Unit/Types/MultiLineStringTest.php +++ b/tests/Unit/Types/MultiLineStringTest.php @@ -46,7 +46,7 @@ public function testFromJson() public function testInvalidGeoJsonException() { $this->assertException( - \Fleetbase\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class, + Fleetbase\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class, sprintf('Expected %s, got %s', GeoJson\Geometry\MultiLineString::class, GeoJson\Geometry\Point::class) ); MultiLineString::fromJson('{"type":"Point","coordinates":[3.4,1.2]}'); @@ -56,7 +56,7 @@ public function testJsonSerialize() { $multilinestring = MultiLineString::fromWKT('MULTILINESTRING((0 0,1 1,1 2),(2 3,3 2,5 4))'); - $this->assertInstanceOf(\GeoJson\Geometry\MultiLineString::class, $multilinestring->jsonSerialize()); + $this->assertInstanceOf(GeoJson\Geometry\MultiLineString::class, $multilinestring->jsonSerialize()); $this->assertSame('{"type":"MultiLineString","coordinates":[[[0,0],[1,1],[1,2]],[[2,3],[3,2],[5,4]]]}', json_encode($multilinestring)); } diff --git a/tests/Unit/Types/MultiPointTest.php b/tests/Unit/Types/MultiPointTest.php index 98850c3..c9a41fa 100644 --- a/tests/Unit/Types/MultiPointTest.php +++ b/tests/Unit/Types/MultiPointTest.php @@ -43,7 +43,7 @@ public function testFromJson() public function testInvalidGeoJsonException() { $this->assertException( - \Fleetbase\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class, + Fleetbase\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class, sprintf('Expected %s, got %s', GeoJson\Geometry\MultiPoint::class, GeoJson\Geometry\Point::class) ); MultiPoint::fromJson('{"type":"Point","coordinates":[3.4,1.2]}'); @@ -55,7 +55,7 @@ public function testJsonSerialize() $multipoint = new MultiPoint($collection); - $this->assertInstanceOf(\GeoJson\Geometry\MultiPoint::class, $multipoint->jsonSerialize()); + $this->assertInstanceOf(GeoJson\Geometry\MultiPoint::class, $multipoint->jsonSerialize()); $this->assertSame('{"type":"MultiPoint","coordinates":[[0,0],[1,0],[1,1]]}', json_encode($multipoint)); } @@ -82,8 +82,8 @@ public function testInvalidArgumentExceptionNotArrayOfLineString() public function testArrayAccess() { - $point0 = new Point(0, 0); - $point1 = new Point(1, 1); + $point0 = new Point(0, 0); + $point1 = new Point(1, 1); $multipoint = new MultiPoint([$point0, $point1]); // assert getting @@ -91,7 +91,7 @@ public function testArrayAccess() $this->assertEquals($point1, $multipoint[1]); // assert setting - $point2 = new Point(2, 2); + $point2 = new Point(2, 2); $multipoint[] = $point2; $this->assertEquals($point2, $multipoint[2]); @@ -105,8 +105,8 @@ public function testArrayAccess() public function testDeprecatedPrependPoint() { - $point1 = new Point(1, 1); - $point2 = new Point(2, 2); + $point1 = new Point(1, 1); + $point2 = new Point(2, 2); $multipoint = new MultiPoint([$point1, $point2]); $point0 = new Point(0, 0); @@ -119,8 +119,8 @@ public function testDeprecatedPrependPoint() public function testDeprecatedAppendPoint() { - $point0 = new Point(0, 0); - $point1 = new Point(1, 1); + $point0 = new Point(0, 0); + $point1 = new Point(1, 1); $multipoint = new MultiPoint([$point0, $point1]); $point2 = new Point(2, 2); @@ -133,8 +133,8 @@ public function testDeprecatedAppendPoint() public function testDeprecatedInsertPoint() { - $point1 = new Point(1, 1); - $point3 = new Point(3, 3); + $point1 = new Point(1, 1); + $point3 = new Point(3, 3); $multipoint = new MultiPoint([$point1, $point3]); $point2 = new Point(2, 2); diff --git a/tests/Unit/Types/MultiPolygonTest.php b/tests/Unit/Types/MultiPolygonTest.php index 29d9637..620b3b8 100644 --- a/tests/Unit/Types/MultiPolygonTest.php +++ b/tests/Unit/Types/MultiPolygonTest.php @@ -66,7 +66,7 @@ public function testFromJson() public function testInvalidGeoJsonException() { $this->assertException( - \Fleetbase\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class, + Fleetbase\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class, sprintf('Expected %s, got %s', GeoJson\Geometry\MultiPolygon::class, GeoJson\Geometry\Point::class) ); MultiPolygon::fromJson('{"type":"Point","coordinates":[3.4,1.2]}'); @@ -74,7 +74,7 @@ public function testInvalidGeoJsonException() public function testJsonSerialize() { - $this->assertInstanceOf(\GeoJson\Geometry\MultiPolygon::class, $this->getMultiPolygon()->jsonSerialize()); + $this->assertInstanceOf(GeoJson\Geometry\MultiPolygon::class, $this->getMultiPolygon()->jsonSerialize()); $this->assertSame('{"type":"MultiPolygon","coordinates":[[[[0,0],[1,0],[1,1],[0,1],[0,0]],[[10,10],[20,10],[20,20],[10,20],[10,10]]],[[[100,100],[200,100],[200,200],[100,200],[100,100]]]]}', json_encode($this->getMultiPolygon())); } @@ -111,7 +111,7 @@ public function testArrayAccess() $this->assertEquals($polygon1, $multipolygon[1]); // assert setting - $polygon2 = $this->getPolygon3(); + $polygon2 = $this->getPolygon3(); $multipolygon[] = $polygon2; $this->assertEquals($polygon2, $multipolygon[2]); diff --git a/tests/Unit/Types/PointTest.php b/tests/Unit/Types/PointTest.php index 35456c3..4c2ab87 100644 --- a/tests/Unit/Types/PointTest.php +++ b/tests/Unit/Types/PointTest.php @@ -70,7 +70,7 @@ public function testFromJson() public function testInvalidGeoJsonException() { $this->assertException( - \Fleetbase\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class, + Fleetbase\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class, 'Expected GeoJson\Geometry\Point, got GeoJson\Geometry\LineString' ); Point::fromJson('{"type": "LineString","coordinates":[[1,1],[2,2]]}'); @@ -80,7 +80,7 @@ public function testJsonSerialize() { $point = new Point(1.2, 3.4); - $this->assertInstanceOf(\GeoJson\Geometry\Point::class, $point->jsonSerialize()); + $this->assertInstanceOf(GeoJson\Geometry\Point::class, $point->jsonSerialize()); $this->assertSame('{"type":"Point","coordinates":[3.4,1.2]}', json_encode($point)); } } diff --git a/tests/Unit/Types/PolygonTest.php b/tests/Unit/Types/PolygonTest.php index e788a93..0d7d64f 100644 --- a/tests/Unit/Types/PolygonTest.php +++ b/tests/Unit/Types/PolygonTest.php @@ -57,7 +57,7 @@ public function testFromJson() public function testInvalidGeoJsonException() { $this->assertException( - \Fleetbase\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class, + Fleetbase\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class, 'Expected GeoJson\Geometry\Polygon, got GeoJson\Geometry\Point' ); Polygon::fromJson('{"type":"Point","coordinates":[3.4,1.2]}'); @@ -65,7 +65,7 @@ public function testInvalidGeoJsonException() public function testJsonSerialize() { - $this->assertInstanceOf(\GeoJson\Geometry\Polygon::class, $this->polygon->jsonSerialize()); + $this->assertInstanceOf(GeoJson\Geometry\Polygon::class, $this->polygon->jsonSerialize()); $this->assertSame( '{"type":"Polygon","coordinates":[[[0,0],[1,0],[1,1],[0,1],[0,0]]]}', json_encode($this->polygon)