Skip to content

Commit c8ba1a9

Browse files
committed
Within Test
1 parent 2496491 commit c8ba1a9

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tests/Unit/Eloquent/SpatialTraitTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,27 @@ public function testScopeBounding()
309309
$this->assertNotEmpty($q->wheres);
310310
$this->assertContains("st_intersects(GeomFromText('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))'), `point`)", $q->wheres[0]['sql']);
311311
}
312+
313+
public function testScopeWithin()
314+
{
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]);
324+
325+
$polygon = new \Grimzy\LaravelMysqlSpatial\Types\Polygon([$linestring1, $linestring2, $linestring3]);
326+
$query = TestModel::Within('point',$polygon);
327+
328+
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
329+
$q = $query->getQuery();
330+
$this->assertNotEmpty($q->wheres);
331+
$this->assertContains("st_within(`point`, GeomFromText('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))'))", $q->wheres[0]['sql']);
332+
}
312333
}
313334

314335
class TestModel extends Model

0 commit comments

Comments
 (0)