Skip to content

Support Laravel 8 / MySQL 5.7 (v5.0.0) #156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
language: php

php:
- '5.5'
- '5.6'
- '7.0'
- '7.1'
- '7.2'
- '7.3'
- '7.4'

env:
- MYSQL_VERSION=5.7
Expand Down Expand Up @@ -33,7 +30,5 @@ before_script:

script: vendor/bin/phpunit --coverage-clover build/logs/clover.xml

after_script:
- php vendor/bin/coveralls -v
- ./cc-test-reporter after-build --coverage-input-type clover --exit-code $TRAVIS_TEST_RESULT
after_script: ./cc-test-reporter after-build --coverage-input-type clover --exit-code $TRAVIS_TEST_RESULT

10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ 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.x.x`: MySQL 5.7 and 8.0 (Laravel version < 8.0)
- `3.x.x`: MySQL 8.0 with SRID support (Laravel version < 8.0)
- `4.x.x`: MySQL 8.0 with SRID support (Laravel 8)
- **`5.x.x`: MySQL 5.7 and 8.0 (Laravel 8) [Current branch]**

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.

Expand All @@ -22,7 +25,10 @@ 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
$ composer require grimzy/laravel-mysql-spatial:^5.0

# or for Laravel version < 8.0
$ composer require grimzy/laravel-mysql-spatial:^2.0
```

For MySQL 5.6 and 5.5:
Expand Down
13 changes: 6 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,19 @@
}
],
"require": {
"php": ">=5.5.9",
"php": ">=7.3",
"ext-pdo": "*",
"ext-json": "*",
"illuminate/database": "^5.2|^6.0|^7.0",
"illuminate/database": "^8.0",
"geo-io/wkb-parser": "^1.0",
"jmikola/geojson": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "~4.8|~5.7",
"mockery/mockery": "^0.9.9",
"laravel/laravel": "^5.2|^6.0|^7.0",
"phpunit/phpunit": "~6.5",
"laravel/laravel": "^8.0",
"doctrine/dbal": "^2.5",
"laravel/browser-kit-testing": "^2.0",
"php-coveralls/php-coveralls": "^2.0"
"mockery/mockery": "^1.3"
},
"autoload": {
"psr-4": {
Expand All @@ -43,7 +42,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
"dev-master": "5.0.x-dev"
},
"laravel": {
"providers": [
Expand Down
2 changes: 1 addition & 1 deletion src/Eloquent/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class BaseBuilder extends QueryBuilder
{
protected function cleanBindings(array $bindings)
public function cleanBindings(array $bindings)
{
$bindings = array_map(function ($binding) {
return $binding instanceof SpatialExpression ? $binding->getSpatialValue() : $binding;
Expand Down
4 changes: 3 additions & 1 deletion tests/Unit/BaseTestCase.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

abstract class BaseTestCase extends PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;

abstract class BaseTestCase extends TestCase
{
public function tearDown()
{
Expand Down
21 changes: 15 additions & 6 deletions tests/Unit/Eloquent/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ public function testUpdatePoint()
$this->queryBuilder
->shouldReceive('update')
->with(['point' => new SpatialExpression($point)])
->once();
->once()
->andReturn(1);

$result = $this->builder->update(['point' => $point]);

$this->builder->update(['point' => $point]);
$this->assertSame(1, $result);
}

public function testUpdateLinestring()
Expand All @@ -53,9 +56,12 @@ public function testUpdateLinestring()
$this->queryBuilder
->shouldReceive('update')
->with(['linestring' => new SpatialExpression($linestring)])
->once();
->once()
->andReturn(1);

$this->builder->update(['linestring' => $linestring]);
$result = $this->builder->update(['linestring' => $linestring]);

$this->assertSame(1, $result);
}

public function testUpdatePolygon()
Expand All @@ -68,9 +74,12 @@ public function testUpdatePolygon()
$this->queryBuilder
->shouldReceive('update')
->with(['polygon' => new SpatialExpression($polygon)])
->once();
->once()
->andReturn(1);

$result = $this->builder->update(['polygon' => $polygon]);

$this->builder->update(['polygon' => $polygon]);
$this->assertSame(1, $result);
}
}

Expand Down
8 changes: 7 additions & 1 deletion tests/Unit/Eloquent/SpatialTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
use Grimzy\LaravelMysqlSpatial\MysqlConnection;
use Grimzy\LaravelMysqlSpatial\Types\Point;
use Illuminate\Database\Eloquent\Model;
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
use Mockery as m;

class SpatialTraitTest extends BaseTestCase
{
use MockeryPHPUnitIntegration;

/**
* @var TestModel
*/
Expand Down Expand Up @@ -217,7 +220,10 @@ public function testSettingRawAttributes()
public function testSpatialFieldsNotDefinedException()
{
$model = new TestNoSpatialModel();
$this->setExpectedException(SpatialFieldsNotDefinedException::class);
$this->assertException(
SpatialFieldsNotDefinedException::class,
'TestNoSpatialModel has to define $spatialFields'
);
$model->getSpatialFields();
}

Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/MysqlConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

use Grimzy\LaravelMysqlSpatial\MysqlConnection;
use Grimzy\LaravelMysqlSpatial\Schema\Builder;
use PHPUnit\Framework\TestCase;
use Stubs\PDOStub;

class MysqlConnectionTest extends PHPUnit_Framework_TestCase
class MysqlConnectionTest extends TestCase
{
private $mysqlConnection;

Expand Down
107 changes: 90 additions & 17 deletions tests/Unit/Schema/BlueprintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use BaseTestCase;
use Grimzy\LaravelMysqlSpatial\Schema\Blueprint;
use Illuminate\Database\Schema\ColumnDefinition;
use Mockery;

class BlueprintTest extends BaseTestCase
Expand All @@ -20,81 +21,153 @@ public function setUp()

public function testGeometry()
{
$expectedCol = new ColumnDefinition([
'type' => 'geometry',
'name' => 'col',
'srid' => null,
]);

$this->blueprint
->shouldReceive('addColumn')
->with('geometry', 'col')
->once();
->once()
->andReturn($expectedCol);

$result = $this->blueprint->geometry('col');

$this->blueprint->geometry('col');
$this->assertSame($expectedCol, $result);
}

public function testPoint()
{
$expectedCol = new ColumnDefinition([
'type' => 'point',
'name' => 'col',
'srid' => null,
]);

$this->blueprint
->shouldReceive('addColumn')
->with('point', 'col', ['srid' => null])
->once();
->once()
->andReturn($expectedCol);

$result = $this->blueprint->point('col');

$this->blueprint->point('col');
$this->assertSame($expectedCol, $result);
}

public function testLinestring()
{
$expectedCol = new ColumnDefinition([
'type' => 'linestring',
'name' => 'col',
'srid' => null,
]);

$this->blueprint
->shouldReceive('addColumn')
->with('linestring', 'col')
->once();
->once()
->andReturn($expectedCol);

$result = $this->blueprint->linestring('col');

$this->blueprint->linestring('col');
$this->assertSame($expectedCol, $result);
}

public function testPolygon()
{
$expectedCol = new ColumnDefinition([
'type' => 'polygon',
'name' => 'col',
'srid' => null,
]);

$this->blueprint
->shouldReceive('addColumn')
->with('polygon', 'col')
->once();
->once()
->andReturn($expectedCol);

$result = $this->blueprint->polygon('col');

$this->blueprint->polygon('col');
$this->assertSame($expectedCol, $result);
}

public function testMultiPoint()
{
$expectedCol = new ColumnDefinition([
'type' => 'multipoint',
'name' => 'col',
'srid' => null,
]);

$this->blueprint
->shouldReceive('addColumn')
->with('multipoint', 'col')
->once();
->once()
->andReturn($expectedCol);

$result = $this->blueprint->multipoint('col');

$this->blueprint->multipoint('col');
$this->assertSame($expectedCol, $result);
}

public function testMultiLineString()
{
$expectedCol = new ColumnDefinition([
'type' => 'multilinestring',
'name' => 'col',
'srid' => null,
]);

$this->blueprint
->shouldReceive('addColumn')
->with('multilinestring', 'col')
->once();
->once()
->andReturn($expectedCol);

$result = $this->blueprint->multilinestring('col');

$this->blueprint->multilinestring('col');
$this->assertSame($expectedCol, $result);
}

public function testMulltiPolygon()
public function testMultiPolygon()
{
$expectedCol = new ColumnDefinition([
'type' => 'multipolygon',
'name' => 'col',
'srid' => null,
]);

$this->blueprint
->shouldReceive('addColumn')
->with('multipolygon', 'col')
->once();
->once()
->andReturn($expectedCol);

$result = $this->blueprint->multipolygon('col');

$this->blueprint->multipolygon('col');
$this->assertSame($expectedCol, $result);
}

public function testGeometryCollection()
{
$expectedCol = new ColumnDefinition([
'type' => 'geometrycollection',
'name' => 'col',
'srid' => null,
]);

$this->blueprint
->shouldReceive('addColumn')
->with('geometrycollection', 'col')
->once();
->once()
->andReturn($expectedCol);

$result = $this->blueprint->geometrycollection('col');

$this->blueprint->geometrycollection('col');
$this->assertSame($expectedCol, $result);
}
}
5 changes: 4 additions & 1 deletion tests/Unit/Types/GeometryCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ public function testFromJson()

public function testInvalidGeoJsonException()
{
$this->setExpectedException(\Grimzy\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class);
$this->assertException(
\Grimzy\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]}');
}

Expand Down
5 changes: 4 additions & 1 deletion tests/Unit/Types/LineStringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ public function testFromJson()

public function testInvalidGeoJsonException()
{
$this->setExpectedException(\Grimzy\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class);
$this->assertException(
\Grimzy\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]}');
}

Expand Down
5 changes: 4 additions & 1 deletion tests/Unit/Types/MultiLineStringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ public function testFromJson()

public function testInvalidGeoJsonException()
{
$this->setExpectedException(\Grimzy\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class);
$this->assertException(
\Grimzy\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]}');
}

Expand Down
Loading