@@ -289,8 +289,7 @@ public function testScopeDistanceSphereValueWithSelect()
289289 $ this ->assertContains ("st_distance_sphere(`point`, GeomFromText('POINT(2 1)')) as distance " , $ q ->columns [1 ]->getValue ());
290290 }
291291
292- public function testScopeBounding ()
293- {
292+ private function buildTestPolygon (){
294293 $ point1 = new Point (1 , 1 );
295294 $ point2 = new Point (1 , 2 );
296295 $ linestring1 = new \Grimzy \LaravelMysqlSpatial \Types \LineString ([$ point1 , $ point2 ]);
@@ -300,36 +299,107 @@ public function testScopeBounding()
300299 $ point5 = new Point (2 , 2 );
301300 $ point6 = new Point (1 , 1 );
302301 $ linestring3 = new \Grimzy \LaravelMysqlSpatial \Types \LineString ([$ point5 , $ point6 ]);
302+ return new \Grimzy \LaravelMysqlSpatial \Types \Polygon ([$ linestring1 , $ linestring2 , $ linestring3 ]);
303+ }
303304
304- $ polygon = new \ Grimzy \ LaravelMysqlSpatial \ Types \ Polygon ([ $ linestring1 , $ linestring2 , $ linestring3 ]);
305- $ query = TestModel:: Bounding ( $ polygon , ' point ' );
306-
305+ public function testScopeBounding ()
306+ {
307+ $ query = TestModel:: Bounding ( $ this -> buildTestPolygon (), ' point ' );
307308 $ this ->assertInstanceOf (\Grimzy \LaravelMysqlSpatial \Eloquent \Builder::class, $ query );
308309 $ q = $ query ->getQuery ();
309310 $ this ->assertNotEmpty ($ q ->wheres );
310311 $ this ->assertContains ("st_intersects(GeomFromText('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))'), `point`) " , $ q ->wheres [0 ]['sql ' ]);
311312 }
312313
313- public function testScopeWithin ()
314+ public function testScopeComparison ()
314315 {
315- $ point1 = new Point (1 , 1 );
316- $ point2 = new Point (1 , 2 );
317- $ linestring1 = new \Grimzy \LaravelMysqlSpatial \Types \LineString ([$ point1 , $ point2 ]);
318- $ point3 = new Point (1 , 2 );
319- $ point4 = new Point (2 , 2 );
320- $ linestring2 = new \Grimzy \LaravelMysqlSpatial \Types \LineString ([$ point3 , $ point4 ]);
321- $ point5 = new Point (2 , 2 );
322- $ point6 = new Point (1 , 1 );
323- $ linestring3 = new \Grimzy \LaravelMysqlSpatial \Types \LineString ([$ point5 , $ point6 ]);
316+ $ query = TestModel::Comparison ('point ' ,$ this ->buildTestPolygon (),'within ' );
324317
325- $ polygon = new \Grimzy \LaravelMysqlSpatial \Types \Polygon ([$ linestring1 , $ linestring2 , $ linestring3 ]);
326- $ query = TestModel::Within ('point ' ,$ polygon );
318+ $ this ->assertInstanceOf (\Grimzy \LaravelMysqlSpatial \Eloquent \Builder::class, $ query );
319+ $ q = $ query ->getQuery ();
320+ $ this ->assertNotEmpty ($ q ->wheres );
321+ $ this ->assertContains ("st_within(`point`, GeomFromText('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))')) " , $ q ->wheres [0 ]['sql ' ]);
322+ }
323+
324+ public function testScopeWithin ()
325+ {
326+ $ query = TestModel::Within ('point ' ,$ this ->buildTestPolygon ());
327327
328328 $ this ->assertInstanceOf (\Grimzy \LaravelMysqlSpatial \Eloquent \Builder::class, $ query );
329329 $ q = $ query ->getQuery ();
330330 $ this ->assertNotEmpty ($ q ->wheres );
331331 $ this ->assertContains ("st_within(`point`, GeomFromText('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))')) " , $ q ->wheres [0 ]['sql ' ]);
332332 }
333+
334+ public function testScopeCrosses ()
335+ {
336+ $ query = TestModel::Crosses ('point ' ,$ this ->buildTestPolygon ());
337+
338+ $ this ->assertInstanceOf (\Grimzy \LaravelMysqlSpatial \Eloquent \Builder::class, $ query );
339+ $ q = $ query ->getQuery ();
340+ $ this ->assertNotEmpty ($ q ->wheres );
341+ $ this ->assertContains ("st_crosses(`point`, GeomFromText('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))')) " , $ q ->wheres [0 ]['sql ' ]);
342+ }
343+
344+ public function testScopeContains ()
345+ {
346+ $ query = TestModel::Contains ('point ' ,$ this ->buildTestPolygon ());
347+
348+ $ this ->assertInstanceOf (\Grimzy \LaravelMysqlSpatial \Eloquent \Builder::class, $ query );
349+ $ q = $ query ->getQuery ();
350+ $ this ->assertNotEmpty ($ q ->wheres );
351+ $ this ->assertContains ("st_contains(`point`, GeomFromText('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))')) " , $ q ->wheres [0 ]['sql ' ]);
352+ }
353+
354+ public function testScopeDisjoint ()
355+ {
356+ $ query = TestModel::Disjoint ('point ' ,$ this ->buildTestPolygon ());
357+
358+ $ this ->assertInstanceOf (\Grimzy \LaravelMysqlSpatial \Eloquent \Builder::class, $ query );
359+ $ q = $ query ->getQuery ();
360+ $ this ->assertNotEmpty ($ q ->wheres );
361+ $ this ->assertContains ("st_disjoint(`point`, GeomFromText('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))')) " , $ q ->wheres [0 ]['sql ' ]);
362+ }
363+
364+ public function testScopeEquals ()
365+ {
366+ $ query = TestModel::Equals ('point ' ,$ this ->buildTestPolygon ());
367+
368+ $ this ->assertInstanceOf (\Grimzy \LaravelMysqlSpatial \Eloquent \Builder::class, $ query );
369+ $ q = $ query ->getQuery ();
370+ $ this ->assertNotEmpty ($ q ->wheres );
371+ $ this ->assertContains ("st_equals(`point`, GeomFromText('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))')) " , $ q ->wheres [0 ]['sql ' ]);
372+ }
373+
374+ public function testScopeIntersects ()
375+ {
376+ $ query = TestModel::Intersects ('point ' ,$ this ->buildTestPolygon ());
377+
378+ $ this ->assertInstanceOf (\Grimzy \LaravelMysqlSpatial \Eloquent \Builder::class, $ query );
379+ $ q = $ query ->getQuery ();
380+ $ this ->assertNotEmpty ($ q ->wheres );
381+ $ this ->assertContains ("st_intersects(`point`, GeomFromText('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))')) " , $ q ->wheres [0 ]['sql ' ]);
382+ }
383+
384+ public function testScopeOverlaps ()
385+ {
386+ $ query = TestModel::Overlaps ('point ' ,$ this ->buildTestPolygon ());
387+
388+ $ this ->assertInstanceOf (\Grimzy \LaravelMysqlSpatial \Eloquent \Builder::class, $ query );
389+ $ q = $ query ->getQuery ();
390+ $ this ->assertNotEmpty ($ q ->wheres );
391+ $ this ->assertContains ("st_overlaps(`point`, GeomFromText('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))')) " , $ q ->wheres [0 ]['sql ' ]);
392+ }
393+
394+ public function testScopeTouches ()
395+ {
396+ $ query = TestModel::Touches ('point ' ,$ this ->buildTestPolygon ());
397+
398+ $ this ->assertInstanceOf (\Grimzy \LaravelMysqlSpatial \Eloquent \Builder::class, $ query );
399+ $ q = $ query ->getQuery ();
400+ $ this ->assertNotEmpty ($ q ->wheres );
401+ $ this ->assertContains ("st_touches(`point`, GeomFromText('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))')) " , $ q ->wheres [0 ]['sql ' ]);
402+ }
333403}
334404
335405class TestModel extends Model
0 commit comments