From 845c70b3b8b112b439feb91a87547c3d326e3804 Mon Sep 17 00:00:00 2001 From: Vlad Yarysh Date: Mon, 4 Dec 2023 16:46:47 +0200 Subject: [PATCH] Add GeoJSON type constants (#42) Co-authored-by: Jeremy Mikola --- src/Feature/Feature.php | 2 +- src/Feature/FeatureCollection.php | 2 +- src/GeoJson.php | 28 +++++++++++++++-------- src/Geometry/GeometryCollection.php | 2 +- src/Geometry/LineString.php | 2 +- src/Geometry/MultiLineString.php | 2 +- src/Geometry/MultiPoint.php | 2 +- src/Geometry/MultiPolygon.php | 2 +- src/Geometry/Point.php | 2 +- src/Geometry/Polygon.php | 2 +- tests/Feature/FeatureCollectionTest.php | 14 ++++++------ tests/Feature/FeatureTest.php | 12 +++++----- tests/GeoJsonTest.php | 22 +++++++++--------- tests/Geometry/GeometryCollectionTest.php | 12 +++++----- tests/Geometry/LineStringTest.php | 6 ++--- tests/Geometry/LinearRingTest.php | 5 ++-- tests/Geometry/MultiLineStringTest.php | 6 ++--- tests/Geometry/MultiPointTest.php | 6 ++--- tests/Geometry/MultiPolygonTest.php | 6 ++--- tests/Geometry/PointTest.php | 6 ++--- tests/Geometry/PolygonTest.php | 6 ++--- 21 files changed, 79 insertions(+), 68 deletions(-) diff --git a/src/Feature/Feature.php b/src/Feature/Feature.php index 4d67554..b6ad2d9 100644 --- a/src/Feature/Feature.php +++ b/src/Feature/Feature.php @@ -18,7 +18,7 @@ */ class Feature extends GeoJson { - protected string $type = 'Feature'; + protected string $type = self::TYPE_FEATURE; protected ?Geometry $geometry; diff --git a/src/Feature/FeatureCollection.php b/src/Feature/FeatureCollection.php index 497762b..a9fd4aa 100644 --- a/src/Feature/FeatureCollection.php +++ b/src/Feature/FeatureCollection.php @@ -26,7 +26,7 @@ */ class FeatureCollection extends GeoJson implements Countable, IteratorAggregate { - protected string $type = 'FeatureCollection'; + protected string $type = self::TYPE_FEATURE_COLLECTION; /** * @var array diff --git a/src/GeoJson.php b/src/GeoJson.php index ba3aa75..5f82dcb 100644 --- a/src/GeoJson.php +++ b/src/GeoJson.php @@ -23,6 +23,16 @@ */ abstract class GeoJson implements JsonSerializable, JsonUnserializable { + public const TYPE_LINE_STRING = 'LineString'; + public const TYPE_MULTI_LINE_STRING = 'MultiLineString'; + public const TYPE_MULTI_POINT = 'MultiPoint'; + public const TYPE_MULTI_POLYGON = 'MultiPolygon'; + public const TYPE_POINT = 'Point'; + public const TYPE_POLYGON = 'Polygon'; + public const TYPE_FEATURE = 'Feature'; + public const TYPE_FEATURE_COLLECTION = 'FeatureCollection'; + public const TYPE_GEOMETRY_COLLECTION = 'GeometryCollection'; + protected ?BoundingBox $boundingBox = null; protected ?CoordinateReferenceSystem $crs = null; @@ -87,12 +97,12 @@ final public static function jsonUnserialize($json): self $args = []; switch ($type) { - case 'LineString': - case 'MultiLineString': - case 'MultiPoint': - case 'MultiPolygon': - case 'Point': - case 'Polygon': + case self::TYPE_LINE_STRING: + case self::TYPE_MULTI_LINE_STRING: + case self::TYPE_MULTI_POINT: + case self::TYPE_MULTI_POLYGON: + case self::TYPE_POINT: + case self::TYPE_POLYGON: if (! $json->offsetExists('coordinates')) { throw UnserializationException::missingProperty($type, 'coordinates', 'array'); } @@ -104,7 +114,7 @@ final public static function jsonUnserialize($json): self $args[] = $json['coordinates']; break; - case 'Feature': + case self::TYPE_FEATURE: $geometry = $json['geometry'] ?? null; $properties = $json['properties'] ?? null; $id = $json['id'] ?? null; @@ -124,7 +134,7 @@ final public static function jsonUnserialize($json): self $args[] = $id; break; - case 'FeatureCollection': + case self::TYPE_FEATURE_COLLECTION: if (! $json->offsetExists('features')) { throw UnserializationException::missingProperty($type, 'features', 'array'); } @@ -136,7 +146,7 @@ final public static function jsonUnserialize($json): self $args[] = array_map([self::class, 'jsonUnserialize'], $json['features']); break; - case 'GeometryCollection': + case self::TYPE_GEOMETRY_COLLECTION: if (! $json->offsetExists('geometries')) { throw UnserializationException::missingProperty($type, 'geometries', 'array'); } diff --git a/src/Geometry/GeometryCollection.php b/src/Geometry/GeometryCollection.php index 29ae695..e52beeb 100644 --- a/src/Geometry/GeometryCollection.php +++ b/src/Geometry/GeometryCollection.php @@ -25,7 +25,7 @@ */ class GeometryCollection extends Geometry implements Countable, IteratorAggregate { - protected string $type = 'GeometryCollection'; + protected string $type = self::TYPE_GEOMETRY_COLLECTION; /** * @var array diff --git a/src/Geometry/LineString.php b/src/Geometry/LineString.php index 4158e5b..c41951c 100644 --- a/src/Geometry/LineString.php +++ b/src/Geometry/LineString.php @@ -20,7 +20,7 @@ */ class LineString extends MultiPoint { - protected string $type = 'LineString'; + protected string $type = self::TYPE_LINE_STRING; /** * @param array> $positions diff --git a/src/Geometry/MultiLineString.php b/src/Geometry/MultiLineString.php index 4fd3aa1..d267e0a 100644 --- a/src/Geometry/MultiLineString.php +++ b/src/Geometry/MultiLineString.php @@ -19,7 +19,7 @@ */ class MultiLineString extends Geometry { - protected string $type = 'MultiLineString'; + protected string $type = self::TYPE_MULTI_LINE_STRING; /** * @param array>> $lineStrings diff --git a/src/Geometry/MultiPoint.php b/src/Geometry/MultiPoint.php index e84731e..65bdbbf 100644 --- a/src/Geometry/MultiPoint.php +++ b/src/Geometry/MultiPoint.php @@ -19,7 +19,7 @@ */ class MultiPoint extends Geometry { - protected string $type = 'MultiPoint'; + protected string $type = self::TYPE_MULTI_POINT; /** * @param array> $positions diff --git a/src/Geometry/MultiPolygon.php b/src/Geometry/MultiPolygon.php index 9ea247a..dc51292 100644 --- a/src/Geometry/MultiPolygon.php +++ b/src/Geometry/MultiPolygon.php @@ -19,7 +19,7 @@ */ class MultiPolygon extends Geometry { - protected string $type = 'MultiPolygon'; + protected string $type = self::TYPE_MULTI_POLYGON; /** * @param array>>> $polygons diff --git a/src/Geometry/Point.php b/src/Geometry/Point.php index cab3699..4e9c810 100644 --- a/src/Geometry/Point.php +++ b/src/Geometry/Point.php @@ -22,7 +22,7 @@ */ class Point extends Geometry { - protected string $type = 'Point'; + protected string $type = self::TYPE_POINT; /** * @param array $position diff --git a/src/Geometry/Polygon.php b/src/Geometry/Polygon.php index f60c98d..aaf0259 100644 --- a/src/Geometry/Polygon.php +++ b/src/Geometry/Polygon.php @@ -17,7 +17,7 @@ */ class Polygon extends Geometry { - protected string $type = 'Polygon'; + protected string $type = self::TYPE_POLYGON; /** * @param array>> $linearRings diff --git a/tests/Feature/FeatureCollectionTest.php b/tests/Feature/FeatureCollectionTest.php index c134329..b4cfc87 100644 --- a/tests/Feature/FeatureCollectionTest.php +++ b/tests/Feature/FeatureCollectionTest.php @@ -92,11 +92,11 @@ public function testSerialization(): void $collection = new FeatureCollection($features); $expected = [ - 'type' => 'FeatureCollection', + 'type' => GeoJson::TYPE_FEATURE_COLLECTION, 'features' => [['feature1'], ['feature2']], ]; - $this->assertSame('FeatureCollection', $collection->getType()); + $this->assertSame(GeoJson::TYPE_FEATURE_COLLECTION, $collection->getType()); $this->assertSame($features, $collection->getFeatures()); $this->assertSame($expected, $collection->jsonSerialize()); } @@ -127,21 +127,21 @@ public function testUnserialization($assoc): void $collection = GeoJson::jsonUnserialize($json); $this->assertInstanceOf(FeatureCollection::class, $collection); - $this->assertSame('FeatureCollection', $collection->getType()); + $this->assertSame(GeoJson::TYPE_FEATURE_COLLECTION, $collection->getType()); $this->assertCount(1, $collection); $features = iterator_to_array($collection); $feature = $features[0]; $this->assertInstanceOf(Feature::class, $feature); - $this->assertSame('Feature', $feature->getType()); + $this->assertSame(GeoJson::TYPE_FEATURE, $feature->getType()); $this->assertSame('test.feature.1', $feature->getId()); $this->assertNull($feature->getProperties()); $geometry = $feature->getGeometry(); $this->assertInstanceOf(Point::class, $geometry); - $this->assertSame('Point', $geometry->getType()); + $this->assertSame(GeoJson::TYPE_POINT, $geometry->getType()); $this->assertSame([1, 1], $geometry->getCoordinates()); } @@ -158,7 +158,7 @@ public function testUnserializationShouldRequireFeaturesProperty(): void $this->expectException(UnserializationException::class); $this->expectExceptionMessage('FeatureCollection expected "features" property of type array, none given'); - GeoJson::jsonUnserialize(['type' => 'FeatureCollection']); + GeoJson::jsonUnserialize(['type' => GeoJson::TYPE_FEATURE_COLLECTION]); } public function testUnserializationShouldRequireFeaturesArray(): void @@ -166,6 +166,6 @@ public function testUnserializationShouldRequireFeaturesArray(): void $this->expectException(UnserializationException::class); $this->expectExceptionMessage('FeatureCollection expected "features" property of type array'); - GeoJson::jsonUnserialize(['type' => 'FeatureCollection', 'features' => null]); + GeoJson::jsonUnserialize(['type' => GeoJson::TYPE_FEATURE_COLLECTION, 'features' => null]); } } diff --git a/tests/Feature/FeatureTest.php b/tests/Feature/FeatureTest.php index 7c3ec00..b3a5d9f 100644 --- a/tests/Feature/FeatureTest.php +++ b/tests/Feature/FeatureTest.php @@ -37,13 +37,13 @@ public function testSerialization(): void $feature = new Feature($geometry, $properties, $id); $expected = [ - 'type' => 'Feature', + 'type' => GeoJson::TYPE_FEATURE, 'geometry' => ['geometry'], 'properties' => $properties, 'id' => 'identifier', ]; - $this->assertSame('Feature', $feature->getType()); + $this->assertSame(GeoJson::TYPE_FEATURE, $feature->getType()); $this->assertSame($geometry, $feature->getGeometry()); $this->assertSame($id, $feature->getId()); $this->assertSame($properties, $feature->getProperties()); @@ -55,7 +55,7 @@ public function testSerializationWithNullConstructorArguments(): void $feature = new Feature(); $expected = [ - 'type' => 'Feature', + 'type' => GeoJson::TYPE_FEATURE, 'geometry' => null, 'properties' => null, ]; @@ -68,7 +68,7 @@ public function testSerializationShouldConvertEmptyPropertiesArrayToObject(): vo $feature = new Feature(null, []); $expected = [ - 'type' => 'Feature', + 'type' => GeoJson::TYPE_FEATURE, 'geometry' => null, 'properties' => new stdClass(), ]; @@ -100,14 +100,14 @@ public function testUnserialization($assoc): void $feature = GeoJson::jsonUnserialize($json); $this->assertInstanceOf(Feature::class, $feature); - $this->assertSame('Feature', $feature->getType()); + $this->assertSame(GeoJson::TYPE_FEATURE, $feature->getType()); $this->assertSame('test.feature.1', $feature->getId()); $this->assertSame(['key' => 'value'], $feature->getProperties()); $geometry = $feature->getGeometry(); $this->assertInstanceOf(Point::class, $geometry); - $this->assertSame('Point', $geometry->getType()); + $this->assertSame(GeoJson::TYPE_POINT, $geometry->getType()); $this->assertSame([1, 1], $geometry->getCoordinates()); } diff --git a/tests/GeoJsonTest.php b/tests/GeoJsonTest.php index c4496e7..e0ccedc 100644 --- a/tests/GeoJsonTest.php +++ b/tests/GeoJsonTest.php @@ -48,7 +48,7 @@ public function testUnserializationWithBoundingBox($assoc): void $point = GeoJson::jsonUnserialize($json); $this->assertInstanceOf(Point::class, $point); - $this->assertSame('Point', $point->getType()); + $this->assertSame(GeoJson::TYPE_POINT, $point->getType()); $this->assertSame([1, 1], $point->getCoordinates()); $boundingBox = $point->getBoundingBox(); @@ -80,7 +80,7 @@ public function testUnserializationWithCrs($assoc): void $point = GeoJson::jsonUnserialize($json); $this->assertInstanceOf(Point::class, $point); - $this->assertSame('Point', $point->getType()); + $this->assertSame(GeoJson::TYPE_POINT, $point->getType()); $this->assertSame([1, 1], $point->getCoordinates()); $crs = $point->getCrs(); @@ -142,7 +142,7 @@ public function testUnserializationWithInvalidCoordinates($value): void $this->expectExceptionMessage('Point expected "coordinates" property of type array, ' . $valueType . ' given'); GeoJson::jsonUnserialize([ - 'type' => 'Point', + 'type' => GeoJson::TYPE_POINT, 'coordinates' => $value, ]); } @@ -153,7 +153,7 @@ public function testFeatureUnserializationWithInvalidGeometry(): void $this->expectExceptionMessage('Feature expected "geometry" property of type array or object, string given'); GeoJson::jsonUnserialize([ - 'type' => 'Feature', + 'type' => GeoJson::TYPE_FEATURE, 'geometry' => 'must be array or object, but this is a string', ]); } @@ -164,7 +164,7 @@ public function testFeatureUnserializationWithInvalidProperties(): void $this->expectExceptionMessage('Feature expected "properties" property of type array or object, string given'); GeoJson::jsonUnserialize([ - 'type' => 'Feature', + 'type' => GeoJson::TYPE_FEATURE, 'properties' => 'must be array or object, but this is a string', ]); } @@ -180,12 +180,12 @@ public function provideJsonDecodeAssocOptions() public function provideGeoJsonTypesWithCoordinates() { return [ - 'LineString' => ['LineString'], - 'MultiLineString' => ['MultiLineString'], - 'MultiPoint' => ['MultiPoint'], - 'MultiPolygon' => ['MultiPolygon'], - 'Point' => ['Point'], - 'Polygon' => ['Polygon'], + GeoJson::TYPE_LINE_STRING => [GeoJson::TYPE_LINE_STRING], + GeoJson::TYPE_MULTI_LINE_STRING => [GeoJson::TYPE_MULTI_LINE_STRING], + GeoJson::TYPE_MULTI_POINT => [GeoJson::TYPE_MULTI_POINT], + GeoJson::TYPE_MULTI_POLYGON => [GeoJson::TYPE_MULTI_POLYGON], + GeoJson::TYPE_POINT => [GeoJson::TYPE_POINT], + GeoJson::TYPE_POLYGON => [GeoJson::TYPE_POLYGON], ]; } diff --git a/tests/Geometry/GeometryCollectionTest.php b/tests/Geometry/GeometryCollectionTest.php index fb7bf03..df6892a 100644 --- a/tests/Geometry/GeometryCollectionTest.php +++ b/tests/Geometry/GeometryCollectionTest.php @@ -90,11 +90,11 @@ public function testSerialization(): void $collection = new GeometryCollection($geometries); $expected = [ - 'type' => 'GeometryCollection', + 'type' => GeoJson::TYPE_GEOMETRY_COLLECTION, 'geometries' => [['geometry1'], ['geometry2']], ]; - $this->assertSame('GeometryCollection', $collection->getType()); + $this->assertSame(GeoJson::TYPE_GEOMETRY_COLLECTION, $collection->getType()); $this->assertSame($geometries, $collection->getGeometries()); $this->assertSame($expected, $collection->jsonSerialize()); } @@ -121,14 +121,14 @@ public function testUnserialization($assoc): void $collection = GeoJson::jsonUnserialize($json); $this->assertInstanceOf(GeometryCollection::class, $collection); - $this->assertSame('GeometryCollection', $collection->getType()); + $this->assertSame(GeoJson::TYPE_GEOMETRY_COLLECTION, $collection->getType()); $this->assertCount(1, $collection); $geometries = iterator_to_array($collection); $geometry = $geometries[0]; $this->assertInstanceOf(Point::class, $geometry); - $this->assertSame('Point', $geometry->getType()); + $this->assertSame(GeoJson::TYPE_POINT, $geometry->getType()); $this->assertSame([1, 1], $geometry->getCoordinates()); } @@ -145,7 +145,7 @@ public function testUnserializationShouldRequireGeometriesProperty(): void $this->expectException(UnserializationException::class); $this->expectExceptionMessage('GeometryCollection expected "geometries" property of type array, none given'); - GeoJson::jsonUnserialize(['type' => 'GeometryCollection']); + GeoJson::jsonUnserialize(['type' => GeoJson::TYPE_GEOMETRY_COLLECTION]); } public function testUnserializationShouldRequireGeometriesArray(): void @@ -153,6 +153,6 @@ public function testUnserializationShouldRequireGeometriesArray(): void $this->expectException(UnserializationException::class); $this->expectExceptionMessage('GeometryCollection expected "geometries" property of type array'); - GeoJson::jsonUnserialize(['type' => 'GeometryCollection', 'geometries' => null]); + GeoJson::jsonUnserialize(['type' => GeoJson::TYPE_GEOMETRY_COLLECTION, 'geometries' => null]); } } diff --git a/tests/Geometry/LineStringTest.php b/tests/Geometry/LineStringTest.php index a33c84f..fdea349 100644 --- a/tests/Geometry/LineStringTest.php +++ b/tests/Geometry/LineStringTest.php @@ -42,11 +42,11 @@ public function testSerialization(): void $lineString = new LineString($coordinates); $expected = [ - 'type' => 'LineString', + 'type' => GeoJson::TYPE_LINE_STRING, 'coordinates' => $coordinates, ]; - $this->assertSame('LineString', $lineString->getType()); + $this->assertSame(GeoJson::TYPE_LINE_STRING, $lineString->getType()); $this->assertSame($coordinates, $lineString->getCoordinates()); $this->assertSame($expected, $lineString->jsonSerialize()); } @@ -73,7 +73,7 @@ public function testUnserialization($assoc): void $expectedCoordinates = [[1, 1], [2, 2]]; $this->assertInstanceOf(LineString::class, $lineString); - $this->assertSame('LineString', $lineString->getType()); + $this->assertSame(GeoJson::TYPE_LINE_STRING, $lineString->getType()); $this->assertSame($expectedCoordinates, $lineString->getCoordinates()); } diff --git a/tests/Geometry/LinearRingTest.php b/tests/Geometry/LinearRingTest.php index a52613e..e59106e 100644 --- a/tests/Geometry/LinearRingTest.php +++ b/tests/Geometry/LinearRingTest.php @@ -4,6 +4,7 @@ namespace GeoJson\Tests\Geometry; +use GeoJson\GeoJson; use GeoJson\Geometry\LinearRing; use GeoJson\Geometry\LineString; use GeoJson\Geometry\Point; @@ -71,11 +72,11 @@ public function testSerialization(): void $linearRing = new LinearRing($coordinates); $expected = [ - 'type' => 'LineString', + 'type' => GeoJson::TYPE_LINE_STRING, 'coordinates' => $coordinates, ]; - $this->assertSame('LineString', $linearRing->getType()); + $this->assertSame(GeoJson::TYPE_LINE_STRING, $linearRing->getType()); $this->assertSame($coordinates, $linearRing->getCoordinates()); $this->assertSame($expected, $linearRing->jsonSerialize()); } diff --git a/tests/Geometry/MultiLineStringTest.php b/tests/Geometry/MultiLineStringTest.php index 78a3811..d4f1a1b 100644 --- a/tests/Geometry/MultiLineStringTest.php +++ b/tests/Geometry/MultiLineStringTest.php @@ -50,11 +50,11 @@ public function testSerialization(): void $multiLineString = new MultiLineString($coordinates); $expected = [ - 'type' => 'MultiLineString', + 'type' => GeoJson::TYPE_MULTI_LINE_STRING, 'coordinates' => $coordinates, ]; - $this->assertSame('MultiLineString', $multiLineString->getType()); + $this->assertSame(GeoJson::TYPE_MULTI_LINE_STRING, $multiLineString->getType()); $this->assertSame($coordinates, $multiLineString->getCoordinates()); $this->assertSame($expected, $multiLineString->jsonSerialize()); } @@ -84,7 +84,7 @@ public function testUnserialization($assoc): void ]; $this->assertInstanceOf(MultiLineString::class, $multiLineString); - $this->assertSame('MultiLineString', $multiLineString->getType()); + $this->assertSame(GeoJson::TYPE_MULTI_LINE_STRING, $multiLineString->getType()); $this->assertSame($expectedCoordinates, $multiLineString->getCoordinates()); } diff --git a/tests/Geometry/MultiPointTest.php b/tests/Geometry/MultiPointTest.php index d8fd376..30a5266 100644 --- a/tests/Geometry/MultiPointTest.php +++ b/tests/Geometry/MultiPointTest.php @@ -46,11 +46,11 @@ public function testSerialization(): void $multiPoint = new MultiPoint($coordinates); $expected = [ - 'type' => 'MultiPoint', + 'type' => GeoJson::TYPE_MULTI_POINT, 'coordinates' => $coordinates, ]; - $this->assertSame('MultiPoint', $multiPoint->getType()); + $this->assertSame(GeoJson::TYPE_MULTI_POINT, $multiPoint->getType()); $this->assertSame($coordinates, $multiPoint->getCoordinates()); $this->assertSame($expected, $multiPoint->jsonSerialize()); } @@ -77,7 +77,7 @@ public function testUnserialization($assoc): void $expectedCoordinates = [[1, 1], [2, 2]]; $this->assertInstanceOf(MultiPoint::class, $multiPoint); - $this->assertSame('MultiPoint', $multiPoint->getType()); + $this->assertSame(GeoJson::TYPE_MULTI_POINT, $multiPoint->getType()); $this->assertSame($expectedCoordinates, $multiPoint->getCoordinates()); } diff --git a/tests/Geometry/MultiPolygonTest.php b/tests/Geometry/MultiPolygonTest.php index 779abf4..58ad275 100644 --- a/tests/Geometry/MultiPolygonTest.php +++ b/tests/Geometry/MultiPolygonTest.php @@ -50,11 +50,11 @@ public function testSerialization(): void $multiPolygon = new MultiPolygon($coordinates); $expected = [ - 'type' => 'MultiPolygon', + 'type' => GeoJson::TYPE_MULTI_POLYGON, 'coordinates' => $coordinates, ]; - $this->assertSame('MultiPolygon', $multiPolygon->getType()); + $this->assertSame(GeoJson::TYPE_MULTI_POLYGON, $multiPolygon->getType()); $this->assertSame($coordinates, $multiPolygon->getCoordinates()); $this->assertSame($expected, $multiPolygon->jsonSerialize()); } @@ -84,7 +84,7 @@ public function testUnserialization($assoc): void ]; $this->assertInstanceOf(MultiPolygon::class, $multiPolygon); - $this->assertSame('MultiPolygon', $multiPolygon->getType()); + $this->assertSame(GeoJson::TYPE_MULTI_POLYGON, $multiPolygon->getType()); $this->assertSame($expectedCoordinates, $multiPolygon->getCoordinates()); } diff --git a/tests/Geometry/PointTest.php b/tests/Geometry/PointTest.php index 28baed9..d5df870 100644 --- a/tests/Geometry/PointTest.php +++ b/tests/Geometry/PointTest.php @@ -68,11 +68,11 @@ public function testSerialization(): void $point = new Point($coordinates); $expected = [ - 'type' => 'Point', + 'type' => GeoJson::TYPE_POINT, 'coordinates' => $coordinates, ]; - $this->assertSame('Point', $point->getType()); + $this->assertSame(GeoJson::TYPE_POINT, $point->getType()); $this->assertSame($coordinates, $point->getCoordinates()); $this->assertSame($expected, $point->jsonSerialize()); } @@ -94,7 +94,7 @@ public function testUnserialization($assoc): void $point = GeoJson::jsonUnserialize($json); $this->assertInstanceOf(Point::class, $point); - $this->assertSame('Point', $point->getType()); + $this->assertSame(GeoJson::TYPE_POINT, $point->getType()); $this->assertSame([1, 1], $point->getCoordinates()); } diff --git a/tests/Geometry/PolygonTest.php b/tests/Geometry/PolygonTest.php index f30fba3..c71d393 100644 --- a/tests/Geometry/PolygonTest.php +++ b/tests/Geometry/PolygonTest.php @@ -56,11 +56,11 @@ public function testSerialization(): void $polygon = new Polygon($coordinates); $expected = [ - 'type' => 'Polygon', + 'type' => GeoJson::TYPE_POLYGON, 'coordinates' => $coordinates, ]; - $this->assertSame('Polygon', $polygon->getType()); + $this->assertSame(GeoJson::TYPE_POLYGON, $polygon->getType()); $this->assertSame($coordinates, $polygon->getCoordinates()); $this->assertSame($expected, $polygon->jsonSerialize()); } @@ -90,7 +90,7 @@ public function testUnserialization($assoc): void ]; $this->assertInstanceOf(Polygon::class, $polygon); - $this->assertSame('Polygon', $polygon->getType()); + $this->assertSame(GeoJson::TYPE_POLYGON, $polygon->getType()); $this->assertSame($expectedCoordinates, $polygon->getCoordinates()); }