Skip to content

Commit 2ce48fe

Browse files
committed
Fix tests PHP 7.4 / Laravel 8
- Updated phpunit/phpunit to ~6.5 - Updated mockery/mockery to ^1.3
1 parent 76a48e7 commit 2ce48fe

14 files changed

+147
-37
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
"jmikola/geojson": "^1.0"
2424
},
2525
"require-dev": {
26-
"phpunit/phpunit": "~4.8|~5.7",
26+
"phpunit/phpunit": "~6.5",
2727
"laravel/laravel": "^8.0",
2828
"doctrine/dbal": "^2.5",
2929
"laravel/browser-kit-testing": "^2.0",
30-
"mockery/mockery": "^0.9.9"
30+
"mockery/mockery": "^1.3"
3131
},
3232
"autoload": {
3333
"psr-4": {

src/Eloquent/BaseBuilder.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22

3-
declare(strict_types=1);
4-
53
namespace Grimzy\LaravelMysqlSpatial\Eloquent;
64

75
use Illuminate\Database\Query\Builder as QueryBuilder;

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
@@ -5,9 +5,12 @@
55
use Grimzy\LaravelMysqlSpatial\Types\Point;
66
use Illuminate\Database\Eloquent\Model;
77
use Mockery as m;
8+
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
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

tests/Unit/Types/MultiPointTest.php

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

4343
public function testInvalidGeoJsonException()
4444
{
45-
$this->setExpectedException(\Grimzy\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class);
45+
$this->assertException(
46+
\Grimzy\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class,
47+
sprintf('Expected %s, got %s', GeoJson\Geometry\MultiPoint::class, GeoJson\Geometry\Point::class)
48+
);
4649
MultiPoint::fromJson('{"type":"Point","coordinates":[3.4,1.2]}');
4750
}
4851

tests/Unit/Types/MultiPolygonTest.php

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

6666
public function testInvalidGeoJsonException()
6767
{
68-
$this->setExpectedException(\Grimzy\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class);
68+
$this->assertException(
69+
\Grimzy\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class,
70+
sprintf('Expected %s, got %s', GeoJson\Geometry\MultiPolygon::class, GeoJson\Geometry\Point::class)
71+
);
6972
MultiPolygon::fromJson('{"type":"Point","coordinates":[3.4,1.2]}');
7073
}
7174

tests/Unit/Types/PointTest.php

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

6464
public function testInvalidGeoJsonException()
6565
{
66-
$this->setExpectedException(\Grimzy\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class);
66+
$this->assertException(
67+
\Grimzy\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class,
68+
'Expected GeoJson\Geometry\Point, got GeoJson\Geometry\LineString'
69+
);
6770
Point::fromJson('{"type": "LineString","coordinates":[[1,1],[2,2]]}');
6871
}
6972

tests/Unit/Types/PolygonTest.php

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

5757
public function testInvalidGeoJsonException()
5858
{
59-
$this->setExpectedException(\Grimzy\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class);
59+
$this->assertException(
60+
\Grimzy\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException::class,
61+
'Expected GeoJson\Geometry\Polygon, got GeoJson\Geometry\Point'
62+
);
6063
Polygon::fromJson('{"type":"Point","coordinates":[3.4,1.2]}');
6164
}
6265

0 commit comments

Comments
 (0)