Skip to content

Commit d7751bb

Browse files
committed
Removed scopeBounding() in favor of scopeIntersects(). Adjusted tests for MySQL 5.6.
Also cleaned up unneeded Dockerfile.
1 parent b3473de commit d7751bb

File tree

6 files changed

+11
-91
lines changed

6 files changed

+11
-91
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
.idea/
22
vendor/
33
composer.lock
4-
_db/
4+
_db-*/

Dockerfile

Lines changed: 0 additions & 17 deletions
This file was deleted.

php.ini

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/Eloquent/SpatialTrait.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,6 @@ public function scopeDistanceValue($query, $geometry, $column_name)
9393
$query->selectRaw("st_distance(`{$column_name}`, GeomFromText('{$geometry->toWkt()}')) as distance");
9494
}
9595

96-
public function scopeBounding($query, Geometry $bounds, $column_name)
97-
{
98-
return $query->whereRaw("st_intersects(GeomFromText('{$bounds->toWkt()}'), `{$column_name}`)");
99-
}
100-
10196
public function scopeComparison($query, $geometryColumn, $geometry, $relationship)
10297
{
10398
$query->whereRaw("st_{$relationship}(`{$geometryColumn}`, GeomFromText('{$geometry->toWkt()}'))");

tests/Integration/SpatialTest.php

Lines changed: 9 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -194,37 +194,22 @@ public function testDistance()
194194

195195
$a = GeometryModel::distance(2, $loc1->location, 'location')->get();
196196
$this->assertCount(2, $a);
197-
$this->assertTrue($a->contains($loc1));
198-
$this->assertTrue($a->contains($loc2));
199-
$this->assertFalse($a->contains($loc3));
197+
$this->assertTrue($a->contains('location', $loc1->location));
198+
$this->assertTrue($a->contains('location', $loc2->location));
199+
$this->assertFalse($a->contains('location', $loc3->location));
200200

201201
// Excluding self
202202
$b = GeometryModel::distance(2, $loc1->location, 'location', true)->get();
203203
$this->assertCount(1, $b);
204-
$this->assertFalse($b->contains($loc1));
205-
$this->assertTrue($b->contains($loc2));
206-
$this->assertFalse($b->contains($loc3));
204+
$this->assertFalse($b->contains('location',$loc1->location));
205+
$this->assertTrue($b->contains('location',$loc2->location));
206+
$this->assertFalse($b->contains('location',$loc3->location));
207207

208208
$c = GeometryModel::distance(1, $loc1->location, 'location')->get();
209209
$this->assertCount(1, $c);
210-
$this->assertTrue($c->contains($loc1));
211-
$this->assertFalse($c->contains($loc2));
212-
$this->assertFalse($c->contains($loc3));
213-
}
214-
215-
public function testDistanceSphere()
216-
{
217-
$loc1 = new GeometryModel();
218-
$loc1->location = new Point(40.767864, -73.971732);
219-
$loc1->save();
220-
221-
$loc2 = new GeometryModel();
222-
$loc2->location = new Point(40.767664, -73.971271); // Distance from loc1: 44.741406484588
223-
$loc2->save();
224-
225-
$loc3 = new GeometryModel();
226-
$loc3->location = new Point(40.761434, -73.977619); // Distance from loc1: 870.06424066202
227-
$loc3->save();
210+
$this->assertTrue($c->contains('location', $loc1->location));
211+
$this->assertFalse($c->contains('location', $loc2->location));
212+
$this->assertFalse($c->contains('location', $loc3->location));
228213
}
229214

230215
public function testDistanceValue()
@@ -242,36 +227,4 @@ public function testDistanceValue()
242227
$this->assertEquals(0, $a[0]->distance);
243228
$this->assertEquals(1.4142135623, $a[1]->distance); // PHP floats' 11th+ digits don't matter
244229
}
245-
246-
public function testBounding() {
247-
$point = new Point(0, 0);
248-
249-
$linestring1 = \Grimzy\LaravelMysqlSpatial\Types\LineString::fromWkt("LINESTRING(1 1, 2 2)");
250-
$linestring2 = \Grimzy\LaravelMysqlSpatial\Types\LineString::fromWkt("LINESTRING(20 20, 24 24)");
251-
$linestring3 = \Grimzy\LaravelMysqlSpatial\Types\LineString::fromWkt("LINESTRING(0 10, 10 10)");
252-
253-
$geo1 = new GeometryModel();
254-
$geo1->location = $point;
255-
$geo1->line = $linestring1;
256-
$geo1->save();
257-
258-
$geo2 = new GeometryModel();
259-
$geo2->location = $point;
260-
$geo2->line = $linestring2;
261-
$geo2->save();
262-
263-
$geo3 = new GeometryModel();
264-
$geo3->location = $point;
265-
$geo3->line = $linestring3;
266-
$geo3->save();
267-
268-
$polygon = Polygon::fromWKT("POLYGON((0 10,10 10,10 0,0 0,0 10))");
269-
270-
$result = GeometryModel::Bounding($polygon, 'line')->get();
271-
$this->assertCount(2, $result);
272-
$this->assertTrue($result->contains($geo1));
273-
$this->assertFalse($result->contains($geo2));
274-
$this->assertTrue($result->contains($geo3));
275-
276-
}
277230
}

tests/Unit/Eloquent/SpatialTraitTest.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -253,15 +253,6 @@ private function buildTestPolygon(){
253253
return new \Grimzy\LaravelMysqlSpatial\Types\Polygon([$linestring1, $linestring2, $linestring3]);
254254
}
255255

256-
public function testScopeBounding()
257-
{
258-
$query = TestModel::Bounding($this->buildTestPolygon(), 'point');
259-
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
260-
$q = $query->getQuery();
261-
$this->assertNotEmpty($q->wheres);
262-
$this->assertContains("st_intersects(GeomFromText('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))'), `point`)", $q->wheres[0]['sql']);
263-
}
264-
265256
public function testScopeComparison()
266257
{
267258
$query = TestModel::Comparison('point',$this->buildTestPolygon(),'within');
@@ -357,7 +348,7 @@ class TestModel extends Model
357348
{
358349
use \Grimzy\LaravelMysqlSpatial\Eloquent\SpatialTrait;
359350

360-
protected $spatialFields = ['point']; // TODO: only required when fetching, not saving
351+
protected $spatialFields = ['point']; // only required when fetching, not saving
361352

362353
public $timestamps = false;
363354

0 commit comments

Comments
 (0)