Skip to content

Commit 66eecf4

Browse files
committed
Reverted Mockery update. Fixed some unit tests unit tests.
1 parent 78c96b5 commit 66eecf4

File tree

3 files changed

+75
-45
lines changed

3 files changed

+75
-45
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
},
1818
"require-dev": {
1919
"phpunit/phpunit": "~4.8||~5.7",
20-
"mockery/mockery": "^1.1.0",
20+
"mockery/mockery": "^0.9.9",
2121
"laravel/laravel": "^5.2",
2222
"doctrine/dbal": "^2.5",
2323
"laravel/browser-kit-testing": "^2.0",

tests/Unit/Eloquent/BuilderTest.php

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

55
use BaseTestCase;
66
use Grimzy\LaravelMysqlSpatial\Eloquent\Builder;
7+
use Grimzy\LaravelMysqlSpatial\Eloquent\SpatialExpression;
78
use Grimzy\LaravelMysqlSpatial\Eloquent\SpatialTrait;
89
use Grimzy\LaravelMysqlSpatial\MysqlConnection;
910
use Grimzy\LaravelMysqlSpatial\Types\LineString;
@@ -36,50 +37,39 @@ protected function setUp()
3637

3738
public function testUpdatePoint()
3839
{
39-
$this->queryBuilder
40-
->shouldReceive('raw')
41-
->with("ST_GeomFromText('POINT(2 1)')")
42-
->once();
43-
40+
$point = new Point(1, 2);
4441
$this->queryBuilder
4542
->shouldReceive('update')
43+
->with(['point' => new SpatialExpression($point)])
4644
->once();
4745

48-
$this->builder->update(['point' => new Point(1, 2)]);
46+
$this->builder->update(['point' => $point]);
4947
}
5048

5149
public function testUpdateLinestring()
5250
{
53-
$this->queryBuilder
54-
->shouldReceive('raw')
55-
->with("ST_GeomFromText('LINESTRING(0 0,1 1,2 2)')")
56-
->once();
51+
$linestring = new LineString([new Point(0, 0), new Point(1, 1), new Point(2, 2)]);
5752

5853
$this->queryBuilder
5954
->shouldReceive('update')
55+
->with(['linestring' => new SpatialExpression($linestring)])
6056
->once();
6157

62-
$linestring = new LineString([new Point(0, 0), new Point(1, 1), new Point(2, 2)]);
63-
6458
$this->builder->update(['linestring' => $linestring]);
6559
}
6660

6761
public function testUpdatePolygon()
6862
{
69-
$this->queryBuilder
70-
->shouldReceive('raw')
71-
->with("ST_GeomFromText('POLYGON((0 0,1 0),(1 0,1 1),(1 1,0 0))')")
72-
->once();
73-
74-
$this->queryBuilder
75-
->shouldReceive('update')
76-
->once();
77-
7863
$linestrings[] = new LineString([new Point(0, 0), new Point(0, 1)]);
7964
$linestrings[] = new LineString([new Point(0, 1), new Point(1, 1)]);
8065
$linestrings[] = new LineString([new Point(1, 1), new Point(0, 0)]);
8166
$polygon = new Polygon($linestrings);
8267

68+
$this->queryBuilder
69+
->shouldReceive('update')
70+
->with(['polygon' => new SpatialExpression($polygon)])
71+
->once();
72+
8373
$this->builder->update(['polygon' => $polygon]);
8474
}
8575
}

tests/Unit/Eloquent/SpatialTraitTest.php

Lines changed: 63 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,10 @@ public function testScopeDistance()
215215
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
216216
$q = $query->getQuery();
217217
$this->assertNotEmpty($q->wheres);
218-
$this->assertContains("st_distance(`point`, ST_GeomFromText('POINT(2 1)')) <= 10", $q->wheres[0]['sql']);
218+
$this->assertNotEmpty($q->bindings['where']);
219+
$this->assertEquals('st_distance(`point`, ST_GeomFromText(?)) <= ?', $q->wheres[0]['sql']);
220+
$this->assertEquals('POINT(2 1)', $q->bindings['where'][0]);
221+
$this->assertEquals(10, $q->bindings['where'][1]);
219222
}
220223

221224
public function testScopeDistanceExcludingSelf()
@@ -226,8 +229,12 @@ public function testScopeDistanceExcludingSelf()
226229
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
227230
$q = $query->getQuery();
228231
$this->assertNotEmpty($q->wheres);
229-
$this->assertContains("st_distance(`point`, ST_GeomFromText('POINT(2 1)')) <= 10", $q->wheres[0]['sql']);
230-
$this->assertContains("st_distance(`point`, ST_GeomFromText('POINT(2 1)')) != 0", $q->wheres[1]['sql']);
232+
$this->assertNotEmpty($q->bindings['where']);
233+
$this->assertEquals('st_distance(`point`, ST_GeomFromText(?)) <= ?', $q->wheres[0]['sql']);
234+
$this->assertEquals('st_distance(`point`, ST_GeomFromText(?)) != 0', $q->wheres[1]['sql']);
235+
$this->assertEquals('POINT(2 1)', $q->bindings['where'][0]);
236+
$this->assertEquals(10, $q->bindings['where'][1]);
237+
$this->assertEquals('POINT(2 1)', $q->bindings['where'][2]);
231238
}
232239

233240
public function testScopeDistanceSphere()
@@ -238,7 +245,10 @@ public function testScopeDistanceSphere()
238245
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
239246
$q = $query->getQuery();
240247
$this->assertNotEmpty($q->wheres);
241-
$this->assertContains("st_distance_sphere(`point`, ST_GeomFromText('POINT(2 1)')) <= 10", $q->wheres[0]['sql']);
248+
$this->assertNotEmpty($q->bindings['where']);
249+
$this->assertEquals('st_distance_sphere(`point`, ST_GeomFromText(?)) <= ?', $q->wheres[0]['sql']);
250+
$this->assertEquals('POINT(2 1)', $q->bindings['where'][0]);
251+
$this->assertEquals(10, $q->bindings['where'][1]);
242252
}
243253

244254
public function testScopeDistanceSphereExcludingSelf()
@@ -249,8 +259,12 @@ public function testScopeDistanceSphereExcludingSelf()
249259
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
250260
$q = $query->getQuery();
251261
$this->assertNotEmpty($q->wheres);
252-
$this->assertContains("st_distance_sphere(`point`, ST_GeomFromText('POINT(2 1)')) <= 10", $q->wheres[0]['sql']);
253-
$this->assertContains("st_distance_sphere(`point`, ST_GeomFromText('POINT(2 1)')) != 0", $q->wheres[1]['sql']);
262+
$this->assertNotEmpty($q->bindings['where']);
263+
$this->assertEquals('st_distance_sphere(`point`, ST_GeomFromText(?)) <= ?', $q->wheres[0]['sql']);
264+
$this->assertEquals('st_distance_sphere(point, ST_GeomFromText(?)) != 0', $q->wheres[1]['sql']);
265+
$this->assertEquals('POINT(2 1)', $q->bindings['where'][0]);
266+
$this->assertEquals(10, $q->bindings['where'][1]);
267+
$this->assertEquals('POINT(2 1)', $q->bindings['where'][2]);
254268
}
255269

256270
public function testScopeDistanceValue()
@@ -261,9 +275,11 @@ public function testScopeDistanceValue()
261275
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
262276
$q = $query->getQuery();
263277
$this->assertNotEmpty($q->columns);
264-
$this->assertContains('*', $q->columns[0]);
278+
$this->assertNotEmpty($q->bindings['select']);
279+
$this->assertEquals('*', $q->columns[0]);
265280
$this->assertInstanceOf(\Illuminate\Database\Query\Expression::class, $q->columns[1]);
266-
$this->assertContains("st_distance(`point`, ST_GeomFromText('POINT(2 1)')) as distance", $q->columns[1]->getValue());
281+
$this->assertEquals('st_distance(`point`, ST_GeomFromText(?)) as distance', $q->columns[1]->getValue());
282+
$this->assertEquals('POINT(2 1)', $q->bindings['select'][0]);
267283
}
268284

269285
public function testScopeDistanceValueWithSelect()
@@ -274,9 +290,11 @@ public function testScopeDistanceValueWithSelect()
274290
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
275291
$q = $query->getQuery();
276292
$this->assertNotEmpty($q->columns);
277-
$this->assertContains('some_column', $q->columns[0]);
293+
$this->assertNotEmpty($q->bindings['select']);
294+
$this->assertEquals('some_column', $q->columns[0]);
278295
$this->assertInstanceOf(\Illuminate\Database\Query\Expression::class, $q->columns[1]);
279-
$this->assertContains("st_distance(`point`, ST_GeomFromText('POINT(2 1)')) as distance", $q->columns[1]->getValue());
296+
$this->assertEquals('st_distance(`point`, ST_GeomFromText(?)) as distance', $q->columns[1]->getValue());
297+
$this->assertEquals('POINT(2 1)', $q->bindings['select'][0]);
280298
}
281299

282300
public function testScopeDistanceSphereValue()
@@ -287,9 +305,11 @@ public function testScopeDistanceSphereValue()
287305
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
288306
$q = $query->getQuery();
289307
$this->assertNotEmpty($q->columns);
290-
$this->assertContains('*', $q->columns[0]);
308+
$this->assertNotEmpty($q->bindings['select']);
309+
$this->assertEquals('*', $q->columns[0]);
291310
$this->assertInstanceOf(\Illuminate\Database\Query\Expression::class, $q->columns[1]);
292-
$this->assertContains("st_distance_sphere(`point`, ST_GeomFromText('POINT(2 1)')) as distance", $q->columns[1]->getValue());
311+
$this->assertEquals('st_distance_sphere(`point`, ST_GeomFromText(?)) as distance', $q->columns[1]->getValue());
312+
$this->assertEquals('POINT(2 1)', $q->bindings['select'][0]);
293313
}
294314

295315
public function testScopeDistanceSphereValueWithSelect()
@@ -300,9 +320,11 @@ public function testScopeDistanceSphereValueWithSelect()
300320
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
301321
$q = $query->getQuery();
302322
$this->assertNotEmpty($q->columns);
303-
$this->assertContains('some_column', $q->columns[0]);
323+
$this->assertNotEmpty($q->bindings['select']);
324+
$this->assertEquals('some_column', $q->columns[0]);
304325
$this->assertInstanceOf(\Illuminate\Database\Query\Expression::class, $q->columns[1]);
305-
$this->assertContains("st_distance_sphere(`point`, ST_GeomFromText('POINT(2 1)')) as distance", $q->columns[1]->getValue());
326+
$this->assertEquals('st_distance_sphere(`point`, ST_GeomFromText(?)) as distance', $q->columns[1]->getValue());
327+
$this->assertEquals('POINT(2 1)', $q->bindings['select'][0]);
306328
}
307329

308330
private function buildTestPolygon()
@@ -327,7 +349,9 @@ public function testScopeComparison()
327349
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
328350
$q = $query->getQuery();
329351
$this->assertNotEmpty($q->wheres);
330-
$this->assertContains("st_within(`point`, ST_GeomFromText('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))'))", $q->wheres[0]['sql']);
352+
$this->assertNotEmpty($q->bindings['where']);
353+
$this->assertContains('st_within(`point`, ST_GeomFromText(?))', $q->wheres[0]['sql']);
354+
$this->assertEquals('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))', $q->bindings['where'][0]);
331355
}
332356

333357
public function testScopeWithin()
@@ -337,7 +361,9 @@ public function testScopeWithin()
337361
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
338362
$q = $query->getQuery();
339363
$this->assertNotEmpty($q->wheres);
340-
$this->assertContains("st_within(`point`, ST_GeomFromText('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))'))", $q->wheres[0]['sql']);
364+
$this->assertNotEmpty($q->bindings['where']);
365+
$this->assertContains('st_within(`point`, ST_GeomFromText(?))', $q->wheres[0]['sql']);
366+
$this->assertEquals('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))', $q->bindings['where'][0]);
341367
}
342368

343369
public function testScopeCrosses()
@@ -347,7 +373,9 @@ public function testScopeCrosses()
347373
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
348374
$q = $query->getQuery();
349375
$this->assertNotEmpty($q->wheres);
350-
$this->assertContains("st_crosses(`point`, ST_GeomFromText('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))'))", $q->wheres[0]['sql']);
376+
$this->assertNotEmpty($q->bindings['where']);
377+
$this->assertContains('st_crosses(`point`, ST_GeomFromText(?))', $q->wheres[0]['sql']);
378+
$this->assertEquals('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))', $q->bindings['where'][0]);
351379
}
352380

353381
public function testScopeContains()
@@ -357,7 +385,9 @@ public function testScopeContains()
357385
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
358386
$q = $query->getQuery();
359387
$this->assertNotEmpty($q->wheres);
360-
$this->assertContains("st_contains(`point`, ST_GeomFromText('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))'))", $q->wheres[0]['sql']);
388+
$this->assertNotEmpty($q->bindings['where']);
389+
$this->assertContains('st_contains(`point`, ST_GeomFromText(?))', $q->wheres[0]['sql']);
390+
$this->assertEquals('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))', $q->bindings['where'][0]);
361391
}
362392

363393
public function testScopeDisjoint()
@@ -367,7 +397,9 @@ public function testScopeDisjoint()
367397
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
368398
$q = $query->getQuery();
369399
$this->assertNotEmpty($q->wheres);
370-
$this->assertContains("st_disjoint(`point`, ST_GeomFromText('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))'))", $q->wheres[0]['sql']);
400+
$this->assertNotEmpty($q->bindings['where']);
401+
$this->assertContains('st_disjoint(`point`, ST_GeomFromText(?))', $q->wheres[0]['sql']);
402+
$this->assertEquals('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))', $q->bindings['where'][0]);
371403
}
372404

373405
public function testScopeEquals()
@@ -377,7 +409,9 @@ public function testScopeEquals()
377409
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
378410
$q = $query->getQuery();
379411
$this->assertNotEmpty($q->wheres);
380-
$this->assertContains("st_equals(`point`, ST_GeomFromText('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))'))", $q->wheres[0]['sql']);
412+
$this->assertNotEmpty($q->bindings['where']);
413+
$this->assertContains('st_equals(`point`, ST_GeomFromText(?))', $q->wheres[0]['sql']);
414+
$this->assertEquals('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))', $q->bindings['where'][0]);
381415
}
382416

383417
public function testScopeIntersects()
@@ -387,7 +421,9 @@ public function testScopeIntersects()
387421
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
388422
$q = $query->getQuery();
389423
$this->assertNotEmpty($q->wheres);
390-
$this->assertContains("st_intersects(`point`, ST_GeomFromText('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))'))", $q->wheres[0]['sql']);
424+
$this->assertNotEmpty($q->bindings['where']);
425+
$this->assertContains('st_intersects(`point`, ST_GeomFromText(?))', $q->wheres[0]['sql']);
426+
$this->assertEquals('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))', $q->bindings['where'][0]);
391427
}
392428

393429
public function testScopeOverlaps()
@@ -397,7 +433,9 @@ public function testScopeOverlaps()
397433
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
398434
$q = $query->getQuery();
399435
$this->assertNotEmpty($q->wheres);
400-
$this->assertContains("st_overlaps(`point`, ST_GeomFromText('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))'))", $q->wheres[0]['sql']);
436+
$this->assertNotEmpty($q->bindings['where']);
437+
$this->assertContains('st_overlaps(`point`, ST_GeomFromText(?))', $q->wheres[0]['sql']);
438+
$this->assertEquals('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))', $q->bindings['where'][0]);
401439
}
402440

403441
public function testScopeDoesTouch()
@@ -407,7 +445,9 @@ public function testScopeDoesTouch()
407445
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
408446
$q = $query->getQuery();
409447
$this->assertNotEmpty($q->wheres);
410-
$this->assertContains("st_touches(`point`, ST_GeomFromText('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))'))", $q->wheres[0]['sql']);
448+
$this->assertNotEmpty($q->bindings['where']);
449+
$this->assertContains('st_touches(`point`, ST_GeomFromText(?))', $q->wheres[0]['sql']);
450+
$this->assertEquals('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))', $q->bindings['where'][0]);
411451
}
412452
}
413453

0 commit comments

Comments
 (0)