From ac69ee9d2b7c87914b4155ab97e0d6eb0d53c205 Mon Sep 17 00:00:00 2001 From: Joseph Estefane Date: Sun, 8 Mar 2020 20:58:58 -0400 Subject: [PATCH 1/2] Fix issue where the WKB of empty GeometryCollections was not getting parsed --- src/Eloquent/SpatialTrait.php | 2 +- tests/Integration/Models/GeometryModel.php | 2 +- tests/Integration/SpatialTest.php | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Eloquent/SpatialTrait.php b/src/Eloquent/SpatialTrait.php index e08a476d..da6c2a95 100755 --- a/src/Eloquent/SpatialTrait.php +++ b/src/Eloquent/SpatialTrait.php @@ -104,7 +104,7 @@ public function setRawAttributes(array $attributes, $sync = false) $spatial_fields = $this->getSpatialFields(); foreach ($attributes as $attribute => &$value) { - if (in_array($attribute, $spatial_fields) && is_string($value) && strlen($value) >= 15) { + if (in_array($attribute, $spatial_fields) && is_string($value) && strlen($value) >= 13) { $value = Geometry::fromWKB($value); } } diff --git a/tests/Integration/Models/GeometryModel.php b/tests/Integration/Models/GeometryModel.php index 0b08186a..0565fd35 100644 --- a/tests/Integration/Models/GeometryModel.php +++ b/tests/Integration/Models/GeometryModel.php @@ -9,5 +9,5 @@ class GeometryModel extends Model protected $table = 'geometry'; - protected $spatialFields = ['location', 'line']; + protected $spatialFields = ['location', 'line', 'multi_geometries']; } diff --git a/tests/Integration/SpatialTest.php b/tests/Integration/SpatialTest.php index 415d8557..9fbb6a3b 100644 --- a/tests/Integration/SpatialTest.php +++ b/tests/Integration/SpatialTest.php @@ -251,6 +251,9 @@ public function testInsertEmptyGeometryCollection() $geo->multi_geometries = new GeometryCollection([]); $geo->save(); $this->assertDatabaseHas('geometry', ['id' => $geo->id]); + + $geo2 = GeometryModel::find($geo->id); + $this->assertInstanceOf(GeometryCollection::class, $geo2->multi_geometries); } public function testUpdate() From 8818d7a0eb3140354678f2f6b8f36ad1f816eafb Mon Sep 17 00:00:00 2001 From: Joseph Estefane Date: Sun, 8 Mar 2020 21:35:01 -0400 Subject: [PATCH 2/2] Asserting empty multi geometry count --- tests/Integration/SpatialTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Integration/SpatialTest.php b/tests/Integration/SpatialTest.php index 9fbb6a3b..87f92a2b 100644 --- a/tests/Integration/SpatialTest.php +++ b/tests/Integration/SpatialTest.php @@ -254,6 +254,7 @@ public function testInsertEmptyGeometryCollection() $geo2 = GeometryModel::find($geo->id); $this->assertInstanceOf(GeometryCollection::class, $geo2->multi_geometries); + $this->assertEquals(0, count($geo2->multi_geometries)); } public function testUpdate()