Skip to content

Commit b89ed02

Browse files
authored
Merge pull request #156 from grimzy/laravel-8-mysql-5.7
Support Laravel 8 / MySQL 5.7 (v5.0.0)
2 parents 7f62564 + 25d075b commit b89ed02

16 files changed

+163
-51
lines changed

.travis.yml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
language: php
22

33
php:
4-
- '5.5'
5-
- '5.6'
6-
- '7.0'
7-
- '7.1'
8-
- '7.2'
4+
- '7.3'
5+
- '7.4'
96

107
env:
118
- MYSQL_VERSION=5.7
@@ -33,7 +30,5 @@ before_script:
3330

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

36-
after_script:
37-
- php vendor/bin/coveralls -v
38-
- ./cc-test-reporter after-build --coverage-input-type clover --exit-code $TRAVIS_TEST_RESULT
33+
after_script: ./cc-test-reporter after-build --coverage-input-type clover --exit-code $TRAVIS_TEST_RESULT
3934

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ Please check the documentation for your MySQL version. MySQL's Extension for Spa
1313
**Versions**
1414

1515
- `1.x.x`: MySQL 5.6 (also supports MySQL 5.5 but not all spatial analysis functions)
16-
- `2.x.x`: MySQL 5.7 and 8.0
16+
- `2.x.x`: MySQL 5.7 and 8.0 (Laravel version < 8.0)
17+
- `3.x.x`: MySQL 8.0 with SRID support (Laravel version < 8.0)
18+
- `4.x.x`: MySQL 8.0 with SRID support (Laravel 8)
19+
- **`5.x.x`: MySQL 5.7 and 8.0 (Laravel 8) [Current branch]**
1720

1821
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.
1922

@@ -22,7 +25,10 @@ This package also works with MariaDB. Please refer to the [MySQL/MariaDB Spatial
2225
Add the package using composer:
2326

2427
```shell
25-
composer require grimzy/laravel-mysql-spatial
28+
$ composer require grimzy/laravel-mysql-spatial:^5.0
29+
30+
# or for Laravel version < 8.0
31+
$ composer require grimzy/laravel-mysql-spatial:^2.0
2632
```
2733

2834
For MySQL 5.6 and 5.5:

composer.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,19 @@
1515
}
1616
],
1717
"require": {
18-
"php": ">=5.5.9",
18+
"php": ">=7.3",
1919
"ext-pdo": "*",
2020
"ext-json": "*",
21-
"illuminate/database": "^5.2|^6.0|^7.0",
21+
"illuminate/database": "^8.0",
2222
"geo-io/wkb-parser": "^1.0",
2323
"jmikola/geojson": "^1.0"
2424
},
2525
"require-dev": {
26-
"phpunit/phpunit": "~4.8|~5.7",
27-
"mockery/mockery": "^0.9.9",
28-
"laravel/laravel": "^5.2|^6.0|^7.0",
26+
"phpunit/phpunit": "~6.5",
27+
"laravel/laravel": "^8.0",
2928
"doctrine/dbal": "^2.5",
3029
"laravel/browser-kit-testing": "^2.0",
31-
"php-coveralls/php-coveralls": "^2.0"
30+
"mockery/mockery": "^1.3"
3231
},
3332
"autoload": {
3433
"psr-4": {
@@ -43,7 +42,7 @@
4342
},
4443
"extra": {
4544
"branch-alias": {
46-
"dev-master": "2.0.x-dev"
45+
"dev-master": "5.0.x-dev"
4746
},
4847
"laravel": {
4948
"providers": [

src/Eloquent/BaseBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class BaseBuilder extends QueryBuilder
88
{
9-
protected function cleanBindings(array $bindings)
9+
public function cleanBindings(array $bindings)
1010
{
1111
$bindings = array_map(function ($binding) {
1212
return $binding instanceof SpatialExpression ? $binding->getSpatialValue() : $binding;

tests/Unit/BaseTestCase.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22

3-
abstract class BaseTestCase extends PHPUnit_Framework_TestCase
3+
use PHPUnit\Framework\TestCase;
4+
5+
abstract class BaseTestCase extends TestCase
46
{
57
public function tearDown()
68
{

tests/Unit/Eloquent/BuilderTest.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,12 @@ public function testUpdatePoint()
4141
$this->queryBuilder
4242
->shouldReceive('update')
4343
->with(['point' => new SpatialExpression($point)])
44-
->once();
44+
->once()
45+
->andReturn(1);
46+
47+
$result = $this->builder->update(['point' => $point]);
4548

46-
$this->builder->update(['point' => $point]);
49+
$this->assertSame(1, $result);
4750
}
4851

4952
public function testUpdateLinestring()
@@ -53,9 +56,12 @@ public function testUpdateLinestring()
5356
$this->queryBuilder
5457
->shouldReceive('update')
5558
->with(['linestring' => new SpatialExpression($linestring)])
56-
->once();
59+
->once()
60+
->andReturn(1);
5761

58-
$this->builder->update(['linestring' => $linestring]);
62+
$result = $this->builder->update(['linestring' => $linestring]);
63+
64+
$this->assertSame(1, $result);
5965
}
6066

6167
public function testUpdatePolygon()
@@ -68,9 +74,12 @@ public function testUpdatePolygon()
6874
$this->queryBuilder
6975
->shouldReceive('update')
7076
->with(['polygon' => new SpatialExpression($polygon)])
71-
->once();
77+
->once()
78+
->andReturn(1);
79+
80+
$result = $this->builder->update(['polygon' => $polygon]);
7281

73-
$this->builder->update(['polygon' => $polygon]);
82+
$this->assertSame(1, $result);
7483
}
7584
}
7685

tests/Unit/Eloquent/SpatialTraitTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
use Grimzy\LaravelMysqlSpatial\MysqlConnection;
55
use Grimzy\LaravelMysqlSpatial\Types\Point;
66
use Illuminate\Database\Eloquent\Model;
7+
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
78
use Mockery as m;
89

910
class SpatialTraitTest extends BaseTestCase
1011
{
12+
use MockeryPHPUnitIntegration;
13+
1114
/**
1215
* @var TestModel
1316
*/
@@ -217,7 +220,10 @@ public function testSettingRawAttributes()
217220
public function testSpatialFieldsNotDefinedException()
218221
{
219222
$model = new TestNoSpatialModel();
220-
$this->setExpectedException(SpatialFieldsNotDefinedException::class);
223+
$this->assertException(
224+
SpatialFieldsNotDefinedException::class,
225+
'TestNoSpatialModel has to define $spatialFields'
226+
);
221227
$model->getSpatialFields();
222228
}
223229

tests/Unit/MysqlConnectionTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
use Grimzy\LaravelMysqlSpatial\MysqlConnection;
44
use Grimzy\LaravelMysqlSpatial\Schema\Builder;
5+
use PHPUnit\Framework\TestCase;
56
use Stubs\PDOStub;
67

7-
class MysqlConnectionTest extends PHPUnit_Framework_TestCase
8+
class MysqlConnectionTest extends TestCase
89
{
910
private $mysqlConnection;
1011

tests/Unit/Schema/BlueprintTest.php

Lines changed: 90 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use BaseTestCase;
66
use Grimzy\LaravelMysqlSpatial\Schema\Blueprint;
7+
use Illuminate\Database\Schema\ColumnDefinition;
78
use Mockery;
89

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

2122
public function testGeometry()
2223
{
24+
$expectedCol = new ColumnDefinition([
25+
'type' => 'geometry',
26+
'name' => 'col',
27+
'srid' => null,
28+
]);
29+
2330
$this->blueprint
2431
->shouldReceive('addColumn')
2532
->with('geometry', 'col')
26-
->once();
33+
->once()
34+
->andReturn($expectedCol);
35+
36+
$result = $this->blueprint->geometry('col');
2737

28-
$this->blueprint->geometry('col');
38+
$this->assertSame($expectedCol, $result);
2939
}
3040

3141
public function testPoint()
3242
{
43+
$expectedCol = new ColumnDefinition([
44+
'type' => 'point',
45+
'name' => 'col',
46+
'srid' => null,
47+
]);
48+
3349
$this->blueprint
3450
->shouldReceive('addColumn')
3551
->with('point', 'col', ['srid' => null])
36-
->once();
52+
->once()
53+
->andReturn($expectedCol);
54+
55+
$result = $this->blueprint->point('col');
3756

38-
$this->blueprint->point('col');
57+
$this->assertSame($expectedCol, $result);
3958
}
4059

4160
public function testLinestring()
4261
{
62+
$expectedCol = new ColumnDefinition([
63+
'type' => 'linestring',
64+
'name' => 'col',
65+
'srid' => null,
66+
]);
67+
4368
$this->blueprint
4469
->shouldReceive('addColumn')
4570
->with('linestring', 'col')
46-
->once();
71+
->once()
72+
->andReturn($expectedCol);
73+
74+
$result = $this->blueprint->linestring('col');
4775

48-
$this->blueprint->linestring('col');
76+
$this->assertSame($expectedCol, $result);
4977
}
5078

5179
public function testPolygon()
5280
{
81+
$expectedCol = new ColumnDefinition([
82+
'type' => 'polygon',
83+
'name' => 'col',
84+
'srid' => null,
85+
]);
86+
5387
$this->blueprint
5488
->shouldReceive('addColumn')
5589
->with('polygon', 'col')
56-
->once();
90+
->once()
91+
->andReturn($expectedCol);
92+
93+
$result = $this->blueprint->polygon('col');
5794

58-
$this->blueprint->polygon('col');
95+
$this->assertSame($expectedCol, $result);
5996
}
6097

6198
public function testMultiPoint()
6299
{
100+
$expectedCol = new ColumnDefinition([
101+
'type' => 'multipoint',
102+
'name' => 'col',
103+
'srid' => null,
104+
]);
105+
63106
$this->blueprint
64107
->shouldReceive('addColumn')
65108
->with('multipoint', 'col')
66-
->once();
109+
->once()
110+
->andReturn($expectedCol);
111+
112+
$result = $this->blueprint->multipoint('col');
67113

68-
$this->blueprint->multipoint('col');
114+
$this->assertSame($expectedCol, $result);
69115
}
70116

71117
public function testMultiLineString()
72118
{
119+
$expectedCol = new ColumnDefinition([
120+
'type' => 'multilinestring',
121+
'name' => 'col',
122+
'srid' => null,
123+
]);
124+
73125
$this->blueprint
74126
->shouldReceive('addColumn')
75127
->with('multilinestring', 'col')
76-
->once();
128+
->once()
129+
->andReturn($expectedCol);
130+
131+
$result = $this->blueprint->multilinestring('col');
77132

78-
$this->blueprint->multilinestring('col');
133+
$this->assertSame($expectedCol, $result);
79134
}
80135

81-
public function testMulltiPolygon()
136+
public function testMultiPolygon()
82137
{
138+
$expectedCol = new ColumnDefinition([
139+
'type' => 'multipolygon',
140+
'name' => 'col',
141+
'srid' => null,
142+
]);
143+
83144
$this->blueprint
84145
->shouldReceive('addColumn')
85146
->with('multipolygon', 'col')
86-
->once();
147+
->once()
148+
->andReturn($expectedCol);
149+
150+
$result = $this->blueprint->multipolygon('col');
87151

88-
$this->blueprint->multipolygon('col');
152+
$this->assertSame($expectedCol, $result);
89153
}
90154

91155
public function testGeometryCollection()
92156
{
157+
$expectedCol = new ColumnDefinition([
158+
'type' => 'geometrycollection',
159+
'name' => 'col',
160+
'srid' => null,
161+
]);
162+
93163
$this->blueprint
94164
->shouldReceive('addColumn')
95165
->with('geometrycollection', 'col')
96-
->once();
166+
->once()
167+
->andReturn($expectedCol);
168+
169+
$result = $this->blueprint->geometrycollection('col');
97170

98-
$this->blueprint->geometrycollection('col');
171+
$this->assertSame($expectedCol, $result);
99172
}
100173
}

tests/Unit/Types/GeometryCollectionTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,10 @@ public function testFromJson()
129129

130130
public function testInvalidGeoJsonException()
131131
{
132-
$this->setExpectedException(\Grimzy\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class);
132+
$this->assertException(
133+
\Grimzy\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class,
134+
sprintf('Expected %s, got %s', GeoJson\Feature\FeatureCollection::class, GeoJson\Geometry\Point::class)
135+
);
133136
GeometryCollection::fromJson('{"type":"Point","coordinates":[3.4,1.2]}');
134137
}
135138

tests/Unit/Types/LineStringTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ public function testFromJson()
4545

4646
public function testInvalidGeoJsonException()
4747
{
48-
$this->setExpectedException(\Grimzy\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class);
48+
$this->assertException(
49+
\Grimzy\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class,
50+
sprintf('Expected %s, got %s', \GeoJson\Geometry\LineString::class, GeoJson\Geometry\Point::class)
51+
);
4952
LineString::fromJson('{"type":"Point","coordinates":[3.4,1.2]}');
5053
}
5154

tests/Unit/Types/MultiLineStringTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ public function testFromJson()
4545

4646
public function testInvalidGeoJsonException()
4747
{
48-
$this->setExpectedException(\Grimzy\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class);
48+
$this->assertException(
49+
\Grimzy\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class,
50+
sprintf('Expected %s, got %s', GeoJson\Geometry\MultiLineString::class, GeoJson\Geometry\Point::class)
51+
);
4952
MultiLineString::fromJson('{"type":"Point","coordinates":[3.4,1.2]}');
5053
}
5154

0 commit comments

Comments
 (0)