diff --git a/AGENTS.md b/AGENTS.md index dc59f15..2c6d38e 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,16 +1,16 @@ # Repository Guidelines -This file defines the repository-specific development rules and the operating boundaries for AI agents working on `longitude-one/spatial-writer`. +This file defines the repository-specific development rules and the operating boundaries for AI agents working on `longitude-one/spatial-encoder`. ## Project Structure & Module Organization -This PHP library converts spatial objects to WKB, EWKB, MySQL binary formats, and WKT text. +This PHP library encodes spatial objects to WKB, EWKB, MySQL binary formats, and WKT text. -Source lives in `lib/LongitudeOne/SpatialWriter/`, using Composer PSR-0 autoloading. `Writer` delegates conversion to `Strategy/StrategyInterface`; MySQL encoding helpers live in `Strategy/MySQL/`. +Source lives in `lib/LongitudeOne/SpatialEncoder/`, using Composer PSR-0 autoloading. `Encoder` delegates conversion to `Strategy/StrategyInterface`; MySQL encoding helpers live in `Strategy/MySQL/`. Strategies preserve X/Y coordinate order. SRIDs do not trigger axis swapping. -Tests mirror the source under `tests/LongitudeOne/SpatialWriter/Tests/Unit/`. +Tests mirror the source under `tests/LongitudeOne/SpatialEncoder/Tests/Unit/`. Quality tools have separate Composer installations and configuration under `quality/`. CI workflows live in `.github/workflows/`. @@ -347,15 +347,15 @@ Breaking changes MUST follow Conventional Commits notation and MUST also satisfy A breaking change MAY be indicated with `!`: ```text -feat!: change public writer API +feat!: change public encoder API ``` or with a `BREAKING CHANGE:` footer: ```text -feat: change public writer API +feat: change public encoder API -BREAKING CHANGE: Writer::write() now requires an explicit format. +BREAKING CHANGE: Encoder::encode() now requires an explicit format. ``` Both MAY be used together when appropriate. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1591132..7dc30d8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,4 +1,4 @@ -# How to contribute to spatial-writer +# How to contribute to spatial-encoder This library is open to contributions. It comes with a set of quality tools to help you to maintain the quality of the code and pass the CI's tests. diff --git a/README.md b/README.md index ad744dd..0044c7b 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,18 @@ -# Spatial Writer +# Spatial Encoder -The writer module provide an interface to convert any SpatialInterfaces to other formats. +The encoder module provides an interface for encoding any `SpatialInterface` into other formats. -This library provides five strategies to convert spatial interfaces to other formats: - * A strategy to convert any spatial interfaces to extended well known binary (EWKB). - * Another one to convert any spatial interfaces to ISO well known binary (WKB). - * A strategy to convert spatial interfaces to the internal MySQL storage format. - * A strategy to convert spatial interfaces to well-known text (WKT). - * A strategy to convert spatial interfaces to extended well-known text (EWKT), including a nonzero SRID. +This library provides five strategies for encoding spatial interfaces into other formats: -Feel free to provide any other strategy to convert spatial interfaces to other formats. +* A strategy for encoding any spatial interface into Extended Well-Known Binary (EWKB). +* A strategy for encoding any spatial interface into ISO Well-Known Binary (WKB). +* A strategy for encoding spatial interfaces into the internal MySQL storage format. +* A strategy for encoding spatial interfaces into Well-Known Text (WKT). +* A strategy for encoding spatial interfaces into Extended Well-Known Text (EWKT), including a non-zero SRID. -See the [strategy guide](docs/strategies.md) for a comparison of the five formats, -usage examples, implementation limits, and links to reference documentation. +Feel free to provide additional strategies for encoding spatial interfaces into other formats. +See the [strategy guide](docs/strategies.md) for a comparison of the five formats, usage examples, implementation limitations, and links to reference documentation. ## Current status ![longitude-one/spatial--writer](https://img.shields.io/badge/longitude--one-spatial--writer-blue) @@ -31,4 +30,3 @@ usage examples, implementation limits, and links to reference documentation. ```bash composer require longitude-one/spatial-writer:0.0.0 ``` - diff --git a/composer.json b/composer.json index 2b34305..6fcbaf7 100644 --- a/composer.json +++ b/composer.json @@ -1,8 +1,8 @@ { - "name": "longitude-one/spatial-writer", + "name": "longitude-one/spatial-encoder", "type": "library", - "description": "This library convert any spatial interfaces to different binary and/or string format.", - "keywords": ["opengis", "postgis", "gis", "spatial", "geometry", "geography", "iso-13249", "ewkb", "php"], + "description": "This library encode any spatial interfaces into different binary or string format.", + "keywords": ["encode", "opengis", "postgis", "gis", "spatial", "geometry", "geography", "iso-13249", "ewkb", "wkt", "ewkt", "wkd", "php"], "authors": [ { "name": "Alexandre Tranchant", @@ -27,8 +27,8 @@ "minimum-stability": "dev", "autoload": { "psr-0": { - "LongitudeOne\\SpatialWriter": "lib/", - "LongitudeOne\\SpatialWriter\\Tests": "tests/" + "LongitudeOne\\SpatialEncoder": "lib/", + "LongitudeOne\\SpatialEncoder\\Tests": "tests/" } }, "scripts": { diff --git a/docs/strategies.md b/docs/strategies.md index d1031c1..90f394c 100644 --- a/docs/strategies.md +++ b/docs/strategies.md @@ -1,10 +1,10 @@ # Serialization Strategies -Spatial Writer converts `spatial-types` objects into text or binary data. +Spatial Encoder encodes `spatial-types` objects into text or binary data. All strategies implement -[`StrategyInterface`](../lib/LongitudeOne/SpatialWriter/Strategy/StrategyInterface.php) -and expose `executeStrategy(SpatialInterface $spatial): string`. -[`Writer`](../lib/LongitudeOne/SpatialWriter/Writer.php) delegates conversion to +[`StrategyInterface`](../lib/LongitudeOne/SpatialEncoder/Strategy/StrategyInterface.php) +and expose `encode(SpatialInterface $spatial): string`. +[`Encoder`](../lib/LongitudeOne/SpatialEncoder/Encoder.php) delegates conversion to the selected strategy. Conversion does not perform any reprojection. ## Choosing a Strategy @@ -13,7 +13,7 @@ This table describes the capabilities of the repository's current implementation | Class. | Output | SRID in output | Dimensions written | Usage | | --------------------- | ------------------------------- | ----------------- | ------------------ | ---------------------------------------------------------------- | -| `GeoJsonStrategy` | GeoJSON geometry text | No | XY, XYZ | Point, LineString, MultiPoint, MultiLineString, Polygon, MultiPolygon and GeometryCollection encoding according to RFC 7946 | +| `GeoJsonStrategy` | GeoJSON geometry text | No | XY, XYZ | Point, LineString, MultiPoint, MultiLineString, Polygon, MultiPolygon, and GeometryCollection encoding according to RFC 7946 | | `WktTextStrategy` | WKT Well Known Text | No | XY, XYZ, XYM, XYZM | Display, text exchanges, functions accepting WKT | | `EwktTextStrategy` | EWKT Extended Well Known Text. | Yes, when nonzero | XY, XYZ, XYM, XYZM | Text exchanges that include the spatial reference | | `WkbBinaryStrategy` | ISO WKB Well Known Binary. | No | XY, XYZ, XYM, XYZM | Exchanges with a standard WKB consumer | @@ -22,41 +22,41 @@ This table describes the capabilities of the repository's current implementation The binary and WKT/EWKT strategies support `Point`, `LineString`, `Polygon`, `MultiPoint`, `MultiLineString`, `MultiPolygon`, and geometry collections. -WKB, EWKB, WKT and EWKT also support `Triangle` and `PolyhedralSurface`. Classes in the Geometry +WKB, EWKB, WKT, and EWKT also support `Triangle` and `PolyhedralSurface`. Classes in the Geometry and Geography families use the same output type names; for example, `GeographyCollection` becomes `GEOMETRYCOLLECTION`. ## Common Usage -The examples in the following sections reuse the imports, point, and writer +The examples in the following sections reuse the imports, point, and encoder below. The SRID is passed to the spatial object's constructor. ```php require 'vendor/autoload.php'; use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Point; -use LongitudeOne\SpatialWriter\Strategy\EwkbBinaryStrategy; -use LongitudeOne\SpatialWriter\Strategy\EwktTextStrategy; -use LongitudeOne\SpatialWriter\Strategy\MySQLBinaryStrategy; -use LongitudeOne\SpatialWriter\Strategy\WkbBinaryStrategy; -use LongitudeOne\SpatialWriter\Strategy\WktTextStrategy; -use LongitudeOne\SpatialWriter\Writer; +use LongitudeOne\SpatialEncoder\Strategy\EwkbBinaryStrategy; +use LongitudeOne\SpatialEncoder\Strategy\EwktTextStrategy; +use LongitudeOne\SpatialEncoder\Strategy\MySQLBinaryStrategy; +use LongitudeOne\SpatialEncoder\Strategy\WkbBinaryStrategy; +use LongitudeOne\SpatialEncoder\Strategy\WktTextStrategy; +use LongitudeOne\SpatialEncoder\Encoder; $point = new Point(1, 2, 4326); -$writer = new Writer(new WktTextStrategy()); +$encoder = new Encoder(new WktTextStrategy()); -echo $writer->convert($point); +echo $encoder->encode($point); // POINT (1 2) ``` The strategy can also be called directly: -`(new WktTextStrategy())->executeStrategy($point)`. +`(new WktTextStrategy())->encode($point)`. Binary outputs are PHP byte strings. `bin2hex()` is used to display them; it is not part of their serialization format. ## WKT — `WktTextStrategy` -[This strategy](../lib/LongitudeOne/SpatialWriter/Strategy/WktTextStrategy.php) +[This strategy](../lib/LongitudeOne/SpatialEncoder/Strategy/WktTextStrategy.php) produces a readable representation with parentheses and space-separated coordinates. It preserves X Y order, followed by Z and M when present. It writes the `Z`, `M`, or `ZM` markers, including for empty values such as @@ -77,14 +77,14 @@ References: [GEOS WKT syntax and examples](https://libgeos.org/specifications/wk ## EWKT — `EwktTextStrategy` -[This strategy](../lib/LongitudeOne/SpatialWriter/Strategy/EwktTextStrategy.php) +[This strategy](../lib/LongitudeOne/SpatialEncoder/Strategy/EwktTextStrategy.php) extends `WktTextStrategy`. It adds `SRID=;` before the WKT when the object's SRID is nonzero. A default or explicit SRID of zero produces plain WKT with no prefix. ```php -$writer->setStrategy(new EwktTextStrategy()); -echo $writer->convert($point); +$encoder->setStrategy(new EwktTextStrategy()); +echo $encoder->encode($point); // SRID=4326;POINT (1 2) ``` @@ -101,14 +101,14 @@ Reference: [PostGIS EWKT output: ST_AsEWKT](https://postgis.net/docs/ST_AsEWKT.h ## WKB — `WkbBinaryStrategy` -[This strategy](../lib/LongitudeOne/SpatialWriter/Strategy/WkbBinaryStrategy.php) +[This strategy](../lib/LongitudeOne/SpatialEncoder/Strategy/WkbBinaryStrategy.php) writes the byte-order indicator, the type identifier, then the coordinates and counts required for composite objects. It preserves X Y order and ignores the SRID. The recipient must therefore know the reference system separately. ```php -$writer->setStrategy(new WkbBinaryStrategy()); -echo bin2hex($writer->convert($point)); +$encoder->setStrategy(new WkbBinaryStrategy()); +echo bin2hex($encoder->encode($point)); // 0101000000000000000000f03f0000000000000040 ``` @@ -125,7 +125,7 @@ The SRID is omitted from both the outer geometry and its members. ```php $pointZ = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\Point(1, 2, 3, 4326); -echo bin2hex($writer->convert($pointZ)); +echo bin2hex($encoder->encode($pointZ)); // 01e9030000000000000000f03f00000000000000400000000000000840 ``` @@ -141,7 +141,7 @@ References: [GEOS WKB structure](https://libgeos.org/specifications/wkb/#iso-wkb ## EWKB — `EwkbBinaryStrategy` -[This strategy](../lib/LongitudeOne/SpatialWriter/Strategy/EwkbBinaryStrategy.php) +[This strategy](../lib/LongitudeOne/SpatialEncoder/Strategy/EwkbBinaryStrategy.php) uses the PostGIS extension of WKB to include the SRID. When the SRID is nonzero, it sets the type's `0x20000000` flag and writes the SRID after the type. An SRID of zero omits this field and flag. Coordinate order is X Y, @@ -150,8 +150,8 @@ a zero SRID: `0x80000000` for Z, `0x40000000` for M, or both for ZM. These flags differ from ISO WKB dimensional offsets. ```php -$writer->setStrategy(new EwkbBinaryStrategy()); -echo bin2hex($writer->convert($point)); +$encoder->setStrategy(new EwkbBinaryStrategy()); +echo bin2hex($encoder->encode($point)); // 0101000020e6100000000000000000f03f0000000000000040 ``` @@ -161,7 +161,7 @@ one quiet NaN per ordinate; other empty geometries contain a zero count. All integers and coordinates are explicitly little-endian. The SRID is written only in the outermost geometry, including when empty. -Members of multi-geometries, collections and polyhedral surfaces inherit it; +Members of multi-geometries, collections, and polyhedral surfaces inherit it; their individual headers retain their type and dimension flags. This also applies to nested collections. Earlier versions repeated the SRID in some multi-geometry members; output now follows PostGIS's single outer SRID. @@ -176,7 +176,7 @@ References: [GEOS EWKB flags and structure](https://libgeos.org/specifications/w ## Internal MySQL Format — `MySQLBinaryStrategy` -[This strategy](../lib/LongitudeOne/SpatialWriter/Strategy/MySQLBinaryStrategy.php) +[This strategy](../lib/LongitudeOne/SpatialEncoder/Strategy/MySQLBinaryStrategy.php) writes a four-byte SRID prefix followed by a binary representation of the geometry. This prefix belongs to MySQL's internal format: do not pass this output unchanged to a function that expects WKB alone. @@ -194,18 +194,18 @@ This input convention differs from the internal storage order. classified as latitude-first. That swap and the unused SRID axis-order lookup resources are removed. Callers that previously reversed their coordinates to compensate should now pass -X/longitude first and Y/latitude second. Changing the writer does not repair +X/longitude first and Y/latitude second. Changing the encoder does not repair previously stored coordinates. ```php -$writer->setStrategy(new MySQLBinaryStrategy()); -echo bin2hex($writer->convert($point)); +$encoder->setStrategy(new MySQLBinaryStrategy()); +echo bin2hex($encoder->encode($point)); // e61000000101000000000000000000f03f0000000000000040 ``` -Only XY objects are accepted. Z, M and ZM inputs throw +Only XY objects are accepted. Z, M, and ZM inputs throw `UnsupportedDimensionException`, including empty collections with those -dimensions. Empty points, lines, polygons and multi-geometries throw +dimensions. Empty points, lines, polygons, and multi-geometries throw `UnsupportedSpatialTypeException`; only XY `GeometryCollection` (including `GeographyCollection`) may be empty. These checks also apply to nested members. @@ -215,10 +215,10 @@ Reference: [MySQL 8.4 spatial formats and internal storage](https://dev.mysql.co The MySQL encoder rejects additional dimensions and unsupported empty values. Use XY objects, with empty values limited to geometry collections. WKB, EWKB, -WKT and EWKT support additional dimensions and other empty geometry types. +WKT, and EWKT support additional dimensions and other empty geometry types. The MySQL strategy declares little-endian byte order (`01`) and explicitly -uses it for SRIDs, type identifiers, counts and coordinates. Its output is +uses it for SRIDs, type identifiers, counts, and coordinates. Its output is independent of the machine's native byte order. Curved geometries and TIN have no concrete classes in the current dependency @@ -227,41 +227,41 @@ An unrecognized spatial interface may throw an `UnsupportedSpatialInterfaceException`. For complete inputs and outputs, see the -[explicit EWKB examples](../tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Ewkb/Examples/), -[explicit WKB examples](../tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkb/Examples/), -[explicit WKT examples](../tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkt/Examples/) +[explicit EWKB examples](../tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Ewkb/Examples/), +[explicit WKB examples](../tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkb/Examples/), +[explicit WKT examples](../tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkt/Examples/) and the [testing guide](../tests/README.md). To add a format, implement -`StrategyInterface` and pass the new strategy to `Writer`. +`StrategyInterface` and pass the new strategy to `Encoder`. ## GeoJSON — `GeoJsonStrategy` This strategy supports Geometry and Geography Points, LineStrings, MultiPoints, -MultiLineStrings, Polygons, MultiPolygons and collections in XY and XYZ, including +MultiLineStrings, Polygons, MultiPolygons, and collections in XY and XYZ, including EMPTY. Types outside the seven RFC 7946 geometry types are rejected. Feature and FeatureCollection composition belongs to the consuming application. ```php -$writer->setStrategy(new \LongitudeOne\SpatialWriter\Strategy\GeoJsonStrategy()); -echo $writer->convert($point); +$encoder->setStrategy(new \LongitudeOne\SpatialEncoder\Strategy\GeoJsonStrategy()); +echo $encoder->encode($point); // {"type":"Point","coordinates":[1,2]} ``` XYZ produces positions `[X,Y,Z]`; EMPTY XY and XYZ produce `{"type":"Point","coordinates":[]}`. No artificial dimension metadata is added. -Measured XYM and XYZM inputs throw `UnsupportedDimensionException`, even EMPTY: +Measured XYM and XYZM inputs throw `UnsupportedDimensionException`, even when EMPTY: M is neither discarded nor written as altitude or a fourth ordinate. The caller supplies WGS 84 longitude/latitude in degrees and, when present, -ellipsoidal height in metres. The writer preserves the coordinates without -reprojection, axis swapping or unit conversion. It does not validate that -reference from SRID or authority metadata: zero, unknown and non-4326 identifiers +ellipsoidal height in metres. The encoder preserves the coordinates without +reprojection, axis swapping, or unit conversion. It does not validate the +reference using SRID or authority metadata: zero, unknown, and non-4326 identifiers are not reasons for rejection and are not serialized as a coordinate-system extension. An absent reference uses the model's default SRID of zero. `UnsupportedSpatialTypeException` is now explicitly public, with its existing `\Exception` inheritance and constructor unchanged. It implements `ExceptionInterface` and reports a type unsupported by the selected strategy, -including Triangle instead of silently converting it to Polygon. +including `Triangle` instead of silently encoding it as `Polygon`. `UnsupportedSpatialInterfaceException` remains internal and unchanged. The shared public `UnsupportedGeometryStructureException` extends @@ -275,26 +275,26 @@ position dimensions at construction; fixtures do not bypass these invariants. `\JsonException` as `previous`. No partial JSON is returned. The installed spatial-types model accepts non-finite floats through Geometry Point constructors; these encounter the ordinary JSON encoding failure path, without a separate -writer validation policy. +encoder validation policy. Numeric encoding uses PHP's `serialize_precision` setting; retain its default `-1` for floating-point round trips. Whitespace and object-property ordering are -not a canonical serialization contract. +not part of a canonical serialization contract. LineStrings retain every position in its supplied order, including Z: ```php $line = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\LineString([[1, 2, 3], [4, 5, 6]]); -echo $writer->convert($line); +echo $encoder->encode($line); // {"type":"LineString","coordinates":[[1,2,3],[4,5,6]]} ``` EMPTY XY and XYZ LineStrings produce `{"type":"LineString","coordinates":[]}`. XYM and XYZM lines are rejected even when EMPTY. LineStrings crossing the antimeridian, such as `[[170,45],[-170,45]]`, are encoded unchanged, without -cutting or detection for rejection. This deliberately does not apply the SHOULD +cutting or rejection. This deliberately does not apply the SHOULD in RFC 7946 section 3.1.9: consumers may interpret or display an uncut line as -crossing the long way around the globe. Callers must prepare any cutting required +crossing the long way around the globe. Callers must perform any cutting required by their consumers before encoding. MultiPoints preserve the number and order of their positions, including duplicates @@ -302,7 +302,7 @@ and Z. A singleton remains a MultiPoint rather than becoming a Point: ```php $multiPoint = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\MultiPoint([[1, 2, 3], [4, 5, 6]]); -echo $writer->convert($multiPoint); +echo $encoder->encode($multiPoint); // {"type":"MultiPoint","coordinates":[[1,2,3],[4,5,6]]} ``` @@ -314,7 +314,7 @@ under the same caller responsibilities described above. The approved MultiPoint contract rejects any EMPTY Point member with `UnsupportedGeometryStructureException`, including an aggregate made entirely of EMPTY members. No member is omitted or replaced. The required spatial-types -`0.0.1-alpha.2` model supports constructing these aggregates, so the writer rejects +`0.0.1-alpha.2` model supports constructing these aggregates, so the encoder rejects them through its public structural exception. An empty aggregate with no members remains supported. @@ -326,7 +326,7 @@ $multiLine = new \LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiLineS [[1, 2], [3, 4]], [[5, 6], [7, 8]], ]); -echo $writer->convert($multiLine); +echo $encoder->encode($multiLine); // {"type":"MultiLineString","coordinates":[[[1,2],[3,4]],[[5,6],[7,8]]]} ``` @@ -335,22 +335,22 @@ An XY or XYZ MultiLineString with no members produces including an aggregate containing only EMPTY members, throws `UnsupportedGeometryStructureException`. A member with only one position also throws that exception, as a GeoJSON line requires at least two positions. -The model permits these line members; the writer rejects them without omitting, -flattening or repairing them, and never returns partial output or nested empty +The model permits these line members; the encoder rejects them without omitting, +flattening, or repairing them, and never returns partial output or nested empty coordinate arrays. XYM and XYZM are rejected even with no members. Antimeridian-crossing members are preserved unchanged under the deliberate non-application of RFC 7946 section 3.1.9 described above. The same caller -responsibilities, reference omission and JSON failure contract apply. +responsibilities, reference omission, and JSON failure contract apply. -Polygons preserve exterior and interior ring order, all positions and Z: +Polygons preserve exterior and interior ring order, all positions, and Z: ```php $polygon = new \LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Polygon([ [[0, 0], [4, 0], [4, 4], [0, 4], [0, 0]], [[1, 1], [1, 2], [2, 2], [2, 1], [1, 1]], ]); -echo $writer->convert($polygon); +echo $encoder->encode($polygon); // {"type":"Polygon","coordinates":[[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[1,2],[2,2],[2,1],[1,1]]]} ``` @@ -361,27 +361,27 @@ failure contracts apply to Polygons. Every exterior ring must have strictly positive signed XY area (counterclockwise) and every interior ring strictly negative signed XY area (clockwise). Incompatible orientation, including zero signed area, throws -`UnsupportedGeometryStructureException`. The writer never reverses, closes or +`UnsupportedGeometryStructureException`. The encoder never reverses, closes, or repairs a ring and never returns partial output. Z is preserved but does not participate in the orientation calculation. The signed-area algorithm and -zero-area rejection are the [approved LongitudeOne encoding policy](https://github.com/longitude-one/spatial-writer/issues/13#issuecomment-5765188095); +zero-area rejection are the [approved LongitudeOne encoding policy](https://github.com/longitude-one/spatial-encoder/issues/13#issuecomment-5765188095); RFC 7946 section 3.1.6 requires winding but does not prescribe that algorithm or explicitly prescribe zero-area rejection. -The installed model already enforces at least four positions, closure and the +The installed model already enforces at least four positions, closure, and the absence of consecutive duplicate positions. It permits collinear and crossed -rings. The writer rejects a crossed ring if its signed area is zero, but does not -separately check simplicity, self-intersections, hole containment or other topology. +rings. The encoder rejects a crossed ring if its signed area is zero, but does not +separately check simplicity, self-intersections, hole containment, or other topology. A nonzero signed area is not proof of topological validity; the caller remains responsible for that validation. Antimeridian-crossing Polygon coordinates are preserved without unwrapping, -detection for rejection or cutting; orientation uses the supplied XY coordinates. +rejection, or cutting; orientation uses the supplied XY coordinates. This deliberately does not apply the SHOULD in RFC 7946 section 3.1.9. Consumers may display an uncut polygon across the long way around the globe, so callers -must prepare any required cutting before encoding. +must perform any required cutting before encoding. -MultiPolygons preserve Polygon order, ring order, position order and Z. A singleton +MultiPolygons preserve Polygon order, ring order, position order, and Z. A singleton remains a MultiPolygon. Every member uses the same Polygon orientation checks above, with no second validation policy: @@ -390,7 +390,7 @@ $multiPolygon = new \LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiPo [[[0, 0], [2, 0], [0, 2], [0, 0]]], [[[3, 0], [5, 0], [3, 2], [3, 0]]], ]); -echo $writer->convert($multiPolygon); +echo $encoder->encode($multiPolygon); // {"type":"MultiPolygon","coordinates":[[[[0,0],[2,0],[0,2],[0,0]]],[[[3,0],[5,0],[3,2],[3,0]]]]} ``` @@ -398,16 +398,16 @@ An XY or XYZ MultiPolygon with no members produces `{"type":"MultiPolygon","coordinates":[]}`. Any EMPTY Polygon member throws `UnsupportedGeometryStructureException`, including when all members are EMPTY. An incompatible exterior or interior ring also rejects the whole conversion. -No member is omitted, repaired, reoriented or replaced, and no partial output is +No member is omitted, repaired, reoriented, or replaced, and no partial output is returned. Measured XYM and XYZM aggregates are rejected even with no members. -The same reference omission, caller responsibilities and JSON failure contract +The same reference omission, caller responsibilities, and JSON failure contract apply. Antimeridian-crossing members retain their supplied coordinates under the deliberate non-application of RFC 7946 section 3.1.9 described above, with the same possible long-way-around interpretation by consumers. The approved contracts for later geometry contributions preserve nested, -singleton and homogeneous GeometryCollections. These deliberately do not apply +singleton, and homogeneous GeometryCollections. These deliberately do not apply the SHOULD guidance of RFC 7946 section 3.1.8. Consumers may have limited support for these collection forms; preparation remains the caller's responsibility. Those types are not enabled by @@ -421,7 +421,7 @@ References: [RFC 7946 geometry objects and positions](https://www.rfc-editor.org [coordinate reference system](https://www.rfc-editor.org/rfc/rfc7946.html#section-4), [non-extensible types](https://www.rfc-editor.org/rfc/rfc7946.html#section-7). -GeometryCollections recursively preserve each member's type, coordinates, order +GeometryCollections recursively preserve each member's type, coordinates, order, and nesting. GeographyCollection uses the same GeoJSON `GeometryCollection` type: ```php @@ -429,7 +429,7 @@ $collection = new \LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\GeometryC new \LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Point(1, 2, 4326), new \LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineString([[3, 4], [5, 6]], 4326), ]); -echo $writer->convert($collection); +echo $encoder->encode($collection); // {"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[1,2]},{"type":"LineString","coordinates":[[3,4],[5,6]]}]} ``` @@ -440,8 +440,8 @@ their own empty `coordinates` arrays; nested collections retain their XYZ are supported, preserving Z; XYM and XYZM are rejected even when EMPTY. Reference metadata is omitted throughout, under the caller responsibilities above. -The approved policy deliberately preserves nested, singleton and homogeneous -collections instead of flattening them or converting them to another type. +The approved policy deliberately preserves nested, singleton, and homogeneous +collections instead of flattening them or encoding them as another type. This does not apply the SHOULD guidance in [RFC 7946 section 3.1.8](https://datatracker.ietf.org/doc/html/rfc7946#section-3.1.8). Consumers that expect simplified forms may not handle or display these collections @@ -453,4 +453,4 @@ collection. A non-RFC member throws `UnsupportedSpatialTypeException`; an incompatible member structure throws `UnsupportedGeometryStructureException`. Failures propagate through every collection level: no member is omitted and no partial result is returned. JSON failures retain the shared `JsonEncodingException` -contract and original exception. +contract and original exception. \ No newline at end of file diff --git a/lib/LongitudeOne/SpatialWriter/Writer.php b/lib/LongitudeOne/SpatialEncoder/Encoder.php similarity index 64% rename from lib/LongitudeOne/SpatialWriter/Writer.php rename to lib/LongitudeOne/SpatialEncoder/Encoder.php index f97a770..23a8459 100644 --- a/lib/LongitudeOne/SpatialWriter/Writer.php +++ b/lib/LongitudeOne/SpatialEncoder/Encoder.php @@ -1,6 +1,6 @@ strategy->executeStrategy($spatial); + return $this->strategy->encode($spatial); } /** diff --git a/lib/LongitudeOne/SpatialWriter/WriterInterface.php b/lib/LongitudeOne/SpatialEncoder/EncoderInterface.php similarity index 76% rename from lib/LongitudeOne/SpatialWriter/WriterInterface.php rename to lib/LongitudeOne/SpatialEncoder/EncoderInterface.php index d518672..6679d1e 100644 --- a/lib/LongitudeOne/SpatialWriter/WriterInterface.php +++ b/lib/LongitudeOne/SpatialEncoder/EncoderInterface.php @@ -1,6 +1,6 @@ writeGeometry($spatial, true); } diff --git a/lib/LongitudeOne/SpatialWriter/Strategy/EwktTextStrategy.php b/lib/LongitudeOne/SpatialEncoder/Strategy/EwktTextStrategy.php similarity index 72% rename from lib/LongitudeOne/SpatialWriter/Strategy/EwktTextStrategy.php rename to lib/LongitudeOne/SpatialEncoder/Strategy/EwktTextStrategy.php index f474160..73e4594 100644 --- a/lib/LongitudeOne/SpatialWriter/Strategy/EwktTextStrategy.php +++ b/lib/LongitudeOne/SpatialEncoder/Strategy/EwktTextStrategy.php @@ -1,6 +1,6 @@ getSrid(); return 0 === $srid ? $wkt : sprintf('SRID=%d;%s', $srid, $wkt); diff --git a/lib/LongitudeOne/SpatialWriter/Strategy/GeoJson/GeometryEncoder.php b/lib/LongitudeOne/SpatialEncoder/Strategy/GeoJson/GeometryEncoder.php similarity index 96% rename from lib/LongitudeOne/SpatialWriter/Strategy/GeoJson/GeometryEncoder.php rename to lib/LongitudeOne/SpatialEncoder/Strategy/GeoJson/GeometryEncoder.php index 1ed47ce..c83262e 100644 --- a/lib/LongitudeOne/SpatialWriter/Strategy/GeoJson/GeometryEncoder.php +++ b/lib/LongitudeOne/SpatialEncoder/Strategy/GeoJson/GeometryEncoder.php @@ -1,6 +1,6 @@ hasM()) { throw new UnsupportedDimensionException('GeoJSON does not support measured coordinates.'); diff --git a/lib/LongitudeOne/SpatialWriter/Strategy/MySQL/MySQLGeometryEncoder.php b/lib/LongitudeOne/SpatialEncoder/Strategy/MySQL/MySQLGeometryEncoder.php similarity index 97% rename from lib/LongitudeOne/SpatialWriter/Strategy/MySQL/MySQLGeometryEncoder.php rename to lib/LongitudeOne/SpatialEncoder/Strategy/MySQL/MySQLGeometryEncoder.php index 9f29191..0df593c 100644 --- a/lib/LongitudeOne/SpatialWriter/Strategy/MySQL/MySQLGeometryEncoder.php +++ b/lib/LongitudeOne/SpatialEncoder/Strategy/MySQL/MySQLGeometryEncoder.php @@ -1,6 +1,6 @@ headerEncoder->writeSrid($spatial->getSrid()) .$this->headerEncoder->writeByteOrder() diff --git a/lib/LongitudeOne/SpatialWriter/Strategy/StrategyInterface.php b/lib/LongitudeOne/SpatialEncoder/Strategy/StrategyInterface.php similarity index 53% rename from lib/LongitudeOne/SpatialWriter/Strategy/StrategyInterface.php rename to lib/LongitudeOne/SpatialEncoder/Strategy/StrategyInterface.php index 717f332..f1281f6 100644 --- a/lib/LongitudeOne/SpatialWriter/Strategy/StrategyInterface.php +++ b/lib/LongitudeOne/SpatialEncoder/Strategy/StrategyInterface.php @@ -1,6 +1,6 @@ writeByteOrder(); $wkb .= (new WkbTypeEncoder())->writeType($spatial); @@ -83,7 +83,7 @@ private function writeCollection(CollectionInterface $collection): string $wkb = pack('V', count($collection->getElements())); foreach ($collection->getElements() as $element) { - $wkb .= $this->executeStrategy($element); + $wkb .= $this->encode($element); } return $wkb; @@ -144,7 +144,7 @@ private function writeMultiLineString(MultiLineStringInterface $multiLineString) { $wkb = pack('V', count($multiLineString->getLineStrings())); foreach ($multiLineString->getLineStrings() as $lineString) { - $wkb .= $this->executeStrategy($lineString); + $wkb .= $this->encode($lineString); } return $wkb; @@ -164,7 +164,7 @@ private function writeMultiPoint(MultiPointInterface $multiPoint): string $wkb = pack('V', count($multiPoint->getPoints())); foreach ($multiPoint->getPoints() as $point) { - $wkb .= $this->executeStrategy($point); + $wkb .= $this->encode($point); } return $wkb; @@ -183,7 +183,7 @@ private function writeMultiPolygon(MultiPolygonInterface $multiPolygon): string { $wkb = pack('V', count($multiPolygon->getPolygons())); foreach ($multiPolygon->getPolygons() as $polygon) { - $wkb .= $this->executeStrategy($polygon); + $wkb .= $this->encode($polygon); } return $wkb; @@ -235,7 +235,7 @@ private function writePolyhedralSurface(PolyhedralSurfaceInterface $surface): st { $wkb = pack('V', count($surface->getPatches())); foreach ($surface->getPatches() as $patch) { - $wkb .= $this->executeStrategy($patch); + $wkb .= $this->encode($patch); } return $wkb; diff --git a/lib/LongitudeOne/SpatialWriter/Strategy/Wkt/WktTypeEncoder.php b/lib/LongitudeOne/SpatialEncoder/Strategy/Wkt/WktTypeEncoder.php similarity index 86% rename from lib/LongitudeOne/SpatialWriter/Strategy/Wkt/WktTypeEncoder.php rename to lib/LongitudeOne/SpatialEncoder/Strategy/Wkt/WktTypeEncoder.php index a395ddd..92db3cc 100644 --- a/lib/LongitudeOne/SpatialWriter/Strategy/Wkt/WktTypeEncoder.php +++ b/lib/LongitudeOne/SpatialEncoder/Strategy/Wkt/WktTypeEncoder.php @@ -1,6 +1,6 @@ writeGeometry($spatial); } @@ -51,7 +51,7 @@ public function executeStrategy(SpatialInterface $spatial): string /** * Write a geometry body, including its surrounding parentheses. * - * @param SpatialInterface $spatial the spatial object to convert + * @param SpatialInterface $spatial the spatial object to encode */ private function writeBody(SpatialInterface $spatial): string { @@ -80,7 +80,7 @@ private function writeCoordinate(float|int $coordinate): string /** * Write the contents of a nonempty geometry body. * - * @param SpatialInterface $spatial the spatial object to convert + * @param SpatialInterface $spatial the spatial object to encode */ private function writeCoordinates(SpatialInterface $spatial): string { @@ -100,7 +100,7 @@ private function writeCoordinates(SpatialInterface $spatial): string /** * Write a complete WKT geometry, keeping collection members free of prefixes. * - * @param SpatialInterface $spatial the spatial object to convert + * @param SpatialInterface $spatial the spatial object to encode */ private function writeGeometry(SpatialInterface $spatial): string { @@ -110,7 +110,7 @@ private function writeGeometry(SpatialInterface $spatial): string /** * Write the bodies of homogeneous geometry members. * - * @param SpatialInterface[] $members the members to convert + * @param SpatialInterface[] $members the members to encode */ private function writeMembers(array $members): string { @@ -120,7 +120,7 @@ private function writeMembers(array $members): string /** * Write the ordinates of a nonempty point in its declared dimension. * - * @param PointInterface $point the point to convert + * @param PointInterface $point the point to encode */ private function writePoint(PointInterface $point): string { diff --git a/phpunit.dist.xml b/phpunit.dist.xml index b69d5a5..79b6d9b 100644 --- a/phpunit.dist.xml +++ b/phpunit.dist.xml @@ -8,8 +8,8 @@ displayDetailsOnTestsThatTriggerErrors="true" displayDetailsOnPhpunitDeprecations="true"> - - tests/LongitudeOne/SpatialWriter/Tests + + tests/LongitudeOne/SpatialEncoder/Tests diff --git a/quality/commit-and-tag-version/readme-version-updater.cjs b/quality/commit-and-tag-version/readme-version-updater.cjs index a642c20..48cbaae 100644 --- a/quality/commit-and-tag-version/readme-version-updater.cjs +++ b/quality/commit-and-tag-version/readme-version-updater.cjs @@ -4,14 +4,14 @@ const SEMVER_PATTERN = '\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z.-]+)?(?:\\+[0-9A-Za-z.-]+)?'; const PACKAGE_VERSION_PATTERN = new RegExp( - `(composer require longitude-one/spatial-writer:)(${SEMVER_PATTERN})(?=\\s|$)`, + `(composer require longitude-one/spatial-encoder:)(${SEMVER_PATTERN})(?=\\s|$)`, ); module.exports.readVersion = function (contents) { const match = contents.match(PACKAGE_VERSION_PATTERN); if (!match) { - throw new Error('readme-version-updater: No Spatial Writer installation version found in README.md.'); + throw new Error('readme-version-updater: No Spatial Encoder installation version found in README.md.'); } return match[2]; diff --git a/quality/php-cs-fixer/headers.txt b/quality/php-cs-fixer/headers.txt index 8a1594f..8f8136d 100644 --- a/quality/php-cs-fixer/headers.txt +++ b/quality/php-cs-fixer/headers.txt @@ -1,4 +1,4 @@ -This file is part of the binary-writer project. +This file is part of the spatial-encoder project. PHP 8.4 | 8.5 diff --git a/quality/php-mess-detector/codeclimate-ruleset.xml b/quality/php-mess-detector/codeclimate-ruleset.xml index 848fd1e..ec34cbe 100644 --- a/quality/php-mess-detector/codeclimate-ruleset.xml +++ b/quality/php-mess-detector/codeclimate-ruleset.xml @@ -5,7 +5,7 @@ http://pmd.sf.net/ruleset_xml_schema.xsd" xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"> - Specific custom rule set that checks longitude-one/spatial-writer test code. + Specific custom rule set that checks longitude-one/spatial-encoder test code. diff --git a/tests/LongitudeOne/SpatialEncoder/Tests/Unit/EncoderTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/EncoderTest.php new file mode 100644 index 0000000..7ee9275 --- /dev/null +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/EncoderTest.php @@ -0,0 +1,97 @@ + 2024-2026 + * Copyright Longitude One 2024-2026 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + */ + +declare(strict_types=1); + +namespace LongitudeOne\SpatialEncoder\Tests\Unit; + +use LongitudeOne\SpatialEncoder\Encoder; +use LongitudeOne\SpatialEncoder\Strategy\EwkbBinaryStrategy; +use LongitudeOne\SpatialEncoder\Strategy\MySQLBinaryStrategy; +use LongitudeOne\SpatialEncoder\Strategy\WkbBinaryStrategy; +use LongitudeOne\SpatialEncoder\Strategy\WktTextStrategy; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Point; +use PHPUnit\Framework\TestCase; + +/** + * @internal + * + * @covers \LongitudeOne\SpatialEncoder\Encoder + */ +class EncoderTest extends TestCase +{ + /** + * Test the binary encoder with a mysql strategy. + */ + public function testBinaryEncoderWithMysqlStrategy(): void + { + $strategy = new MySQLBinaryStrategy(); + $encoder = new Encoder($strategy); + $point = new Point(1, 2, 4326); + static::assertSame( + $strategy->encode($point), + $encoder->encode($point) + ); + } + + /** + * Test the binary encoder with the Well-Known Binary strategy. + */ + public function testBinaryEncoderWithWkbStrategy(): void + { + $strategy = new WkbBinaryStrategy(); + $encoder = new Encoder($strategy); + $point = new Point(1, 2, 4326); + static::assertSame( + $strategy->encode($point), + $encoder->encode($point) + ); + } + + /** + * Test the binary encoder with the Well-Known Binary strategy. + */ + public function testEwkbEncoderWithEwkbStrategy(): void + { + $badStrategy = new MySQLBinaryStrategy(); + $strategy = new EwkbBinaryStrategy(); + $encoder = new Encoder($badStrategy); + static::assertSame($badStrategy, $encoder->getStrategy()); + $encoder->setStrategy($strategy); + $point = new Point(1, 2, 4326); + static::assertSame( + $strategy->encode($point), + $encoder->encode($point) + ); + static::assertNotSame( + $badStrategy->encode($point), + $encoder->encode($point) + ); + } + + /** Test text strategies can be supplied and exchanged with binary strategies. */ + public function testTextEncoder(): void + { + $point = new Point(1, 2, 4326); + $textStrategy = new WktTextStrategy(); + $binaryStrategy = new WkbBinaryStrategy(); + $encoder = new Encoder($textStrategy); + static::assertSame($textStrategy, $encoder->getStrategy()); + static::assertSame('POINT (1 2)', $encoder->encode($point)); + static::assertSame($encoder, $encoder->setStrategy($binaryStrategy)); + static::assertSame($binaryStrategy->encode($point), $encoder->encode($point)); + $encoder->setStrategy($textStrategy); + static::assertSame('POINT (1 2)', $encoder->encode($point)); + } +} diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Exception/ExceptionTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Exception/ExceptionTest.php similarity index 63% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Exception/ExceptionTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Exception/ExceptionTest.php index 378c93a..b0b9a82 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Exception/ExceptionTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Exception/ExceptionTest.php @@ -1,6 +1,6 @@ executeStrategy($collection)) + bin2hex((new EwkbBinaryStrategy())->encode($collection)) ); } @@ -63,7 +63,7 @@ public function testUnsupportedInterface(): void $spatial = static::createStub(SpatialInterface::class); $spatial->method('getType')->willReturn(GeometryTypeEnum::POINT); $this->expectException(UnsupportedSpatialInterfaceException::class); - (new EwkbBinaryStrategy())->executeStrategy($spatial); + (new EwkbBinaryStrategy())->encode($spatial); } /** Reject enum cases without concrete supported spatial types. */ @@ -73,7 +73,7 @@ public function testUnsupportedType(): void $spatial->method('getType')->willReturn(GeometryTypeEnum::CIRCULARSTRING); $this->expectException(UnsupportedSpatialTypeException::class); $this->expectExceptionMessage('EWKB adapter does not support spatial type CircularString'); - (new EwkbBinaryStrategy())->executeStrategy($spatial); + (new EwkbBinaryStrategy())->encode($spatial); } /** Preserve dimension flags even when the SRID is zero. */ @@ -82,7 +82,7 @@ public function testXyEmptyWithoutSrid(): void $point = new \LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Point(srid: 0); static::assertSame( '0101000000000000000000f87f000000000000f87f', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($point)) + bin2hex((new EwkbBinaryStrategy())->encode($point)) ); } @@ -92,7 +92,7 @@ public function testXymEmptyWithoutSrid(): void $point = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\Point(srid: 0); static::assertSame( '0101000040000000000000f87f000000000000f87f000000000000f87f', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($point)) + bin2hex((new EwkbBinaryStrategy())->encode($point)) ); } @@ -102,7 +102,7 @@ public function testXymPointWithoutSrid(): void $point = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\Point(1, 2, 4, 0); static::assertSame( '0101000040000000000000f03f00000000000000400000000000001040', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($point)) + bin2hex((new EwkbBinaryStrategy())->encode($point)) ); } @@ -112,7 +112,7 @@ public function testXyPointWithoutSrid(): void $point = new \LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Point(1, 2, 0); static::assertSame( '0101000000000000000000f03f0000000000000040', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($point)) + bin2hex((new EwkbBinaryStrategy())->encode($point)) ); } @@ -122,7 +122,7 @@ public function testXyzEmptyWithoutSrid(): void $point = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\Point(srid: 0); static::assertSame( '0101000080000000000000f87f000000000000f87f000000000000f87f', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($point)) + bin2hex((new EwkbBinaryStrategy())->encode($point)) ); } @@ -132,7 +132,7 @@ public function testXyzmEmptyWithoutSrid(): void $point = new Point(srid: 0); static::assertSame( '01010000c0000000000000f87f000000000000f87f000000000000f87f000000000000f87f', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($point)) + bin2hex((new EwkbBinaryStrategy())->encode($point)) ); } @@ -142,7 +142,7 @@ public function testXyzmPointWithoutSrid(): void $point = new Point(1, 2, 3, 4, 0); static::assertSame( '01010000c0000000000000f03f000000000000004000000000000008400000000000001040', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($point)) + bin2hex((new EwkbBinaryStrategy())->encode($point)) ); } @@ -152,7 +152,7 @@ public function testXyzPointWithoutSrid(): void $point = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\Point(1, 2, 3, 0); static::assertSame( '0101000080000000000000f03f00000000000000400000000000000840', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($point)) + bin2hex((new EwkbBinaryStrategy())->encode($point)) ); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Ewkb/Examples/GeographyXyTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Ewkb/Examples/GeographyXyTest.php similarity index 84% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Ewkb/Examples/GeographyXyTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Ewkb/Examples/GeographyXyTest.php index 77b6513..6a1e920 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Ewkb/Examples/GeographyXyTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Ewkb/Examples/GeographyXyTest.php @@ -1,6 +1,6 @@ executeStrategy($collection)) + bin2hex((new EwkbBinaryStrategy())->encode($collection)) ); } @@ -61,7 +61,7 @@ public function testGeographyCollectionEmpty(): void // Reference geometry in WKT: GEOMETRYCOLLECTION EMPTY static::assertSame( '0107000020e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($collection)) + bin2hex((new EwkbBinaryStrategy())->encode($collection)) ); } @@ -73,7 +73,7 @@ public function testLineString(): void // Reference geometry in WKT: LINESTRING (0 0, 2 3, 4 1) static::assertSame( '0102000020e61000000300000000000000000000000000000000000000000000000000004000000000000008400000000000001040000000000000f03f', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($line)) + bin2hex((new EwkbBinaryStrategy())->encode($line)) ); } @@ -85,7 +85,7 @@ public function testLineStringEmpty(): void // Reference geometry in WKT: LINESTRING EMPTY static::assertSame( '0102000020e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($line)) + bin2hex((new EwkbBinaryStrategy())->encode($line)) ); } @@ -100,7 +100,7 @@ public function testMultiLineString(): void // Reference geometry in WKT: MULTILINESTRING ((0 0, 2 3), (4 1, 5 2)) static::assertSame( '0105000020e61000000200000001020000000200000000000000000000000000000000000000000000000000004000000000000008400102000000020000000000000000001040000000000000f03f00000000000014400000000000000040', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($lines)) + bin2hex((new EwkbBinaryStrategy())->encode($lines)) ); } @@ -112,7 +112,7 @@ public function testMultiLineStringEmpty(): void // Reference geometry in WKT: MULTILINESTRING EMPTY static::assertSame( '0105000020e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($lines)) + bin2hex((new EwkbBinaryStrategy())->encode($lines)) ); } @@ -124,7 +124,7 @@ public function testMultiPoint(): void // Reference geometry in WKT: MULTIPOINT ((1 2), (3 4)) static::assertSame( '0104000020e6100000020000000101000000000000000000f03f0000000000000040010100000000000000000008400000000000001040', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($points)) + bin2hex((new EwkbBinaryStrategy())->encode($points)) ); } @@ -136,7 +136,7 @@ public function testMultiPointEmpty(): void // Reference geometry in WKT: MULTIPOINT EMPTY static::assertSame( '0104000020e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($points)) + bin2hex((new EwkbBinaryStrategy())->encode($points)) ); } @@ -151,7 +151,7 @@ public function testMultiPolygon(): void // Reference geometry in WKT: MULTIPOLYGON (((0 0, 2 0, 0 2, 0 0)), ((3 3, 5 3, 3 5, 3 3))) static::assertSame( '0106000020e61000000200000001030000000100000004000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000040000000000000000000000000000000000103000000010000000400000000000000000008400000000000000840000000000000144000000000000008400000000000000840000000000000144000000000000008400000000000000840', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($polygons)) + bin2hex((new EwkbBinaryStrategy())->encode($polygons)) ); } @@ -163,7 +163,7 @@ public function testMultiPolygonEmpty(): void // Reference geometry in WKT: MULTIPOLYGON EMPTY static::assertSame( '0106000020e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($polygons)) + bin2hex((new EwkbBinaryStrategy())->encode($polygons)) ); } @@ -175,7 +175,7 @@ public function testPoint(): void // Reference geometry in WKT: POINT (2.5 -3) static::assertSame( '0101000020e6100000000000000000044000000000000008c0', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($point)) + bin2hex((new EwkbBinaryStrategy())->encode($point)) ); } @@ -187,7 +187,7 @@ public function testPointEmpty(): void // Reference geometry in WKT: POINT EMPTY static::assertSame( '0101000020e6100000000000000000f87f000000000000f87f', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($point)) + bin2hex((new EwkbBinaryStrategy())->encode($point)) ); } @@ -202,7 +202,7 @@ public function testPolygon(): void // Reference geometry in WKT: POLYGON ((0 0, 4 0, 4 4, 0 4, 0 0), (1 1, 1 2, 2 2, 2 1, 1 1)) static::assertSame( '0103000020e61000000200000005000000000000000000000000000000000000000000000000001040000000000000000000000000000010400000000000001040000000000000000000000000000010400000000000000000000000000000000005000000000000000000f03f000000000000f03f000000000000f03f0000000000000040000000000000004000000000000000400000000000000040000000000000f03f000000000000f03f000000000000f03f', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($polygon)) + bin2hex((new EwkbBinaryStrategy())->encode($polygon)) ); } @@ -214,7 +214,7 @@ public function testPolygonEmpty(): void // Reference geometry in WKT: POLYGON EMPTY static::assertSame( '0103000020e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($polygon)) + bin2hex((new EwkbBinaryStrategy())->encode($polygon)) ); } @@ -226,7 +226,7 @@ public function testTriangle(): void // Reference geometry in WKT: TRIANGLE ((0 0, 2 0, 0 2, 0 0)) static::assertSame( '0111000020e6100000010000000400000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000004000000000000000000000000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($triangle)) + bin2hex((new EwkbBinaryStrategy())->encode($triangle)) ); } @@ -238,7 +238,7 @@ public function testTriangleEmpty(): void // Reference geometry in WKT: TRIANGLE EMPTY static::assertSame( '0111000020e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($triangle)) + bin2hex((new EwkbBinaryStrategy())->encode($triangle)) ); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Ewkb/Examples/GeographyXymTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Ewkb/Examples/GeographyXymTest.php similarity index 86% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Ewkb/Examples/GeographyXymTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Ewkb/Examples/GeographyXymTest.php index cbf72e4..dd47e7f 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Ewkb/Examples/GeographyXymTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Ewkb/Examples/GeographyXymTest.php @@ -1,6 +1,6 @@ executeStrategy($collection)) + bin2hex((new EwkbBinaryStrategy())->encode($collection)) ); } @@ -64,7 +64,7 @@ public function testGeographyCollectionEmpty(): void // Reference geometry in WKT: GEOMETRYCOLLECTION M EMPTY static::assertSame( '0107000060e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($collection)) + bin2hex((new EwkbBinaryStrategy())->encode($collection)) ); } @@ -76,7 +76,7 @@ public function testLineString(): void // Reference geometry in WKT: LINESTRING M (0 0 10, 2 3 20, 4 1 30) static::assertSame( '0102000060e6100000030000000000000000000000000000000000000000000000000024400000000000000040000000000000084000000000000034400000000000001040000000000000f03f0000000000003e40', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($line)) + bin2hex((new EwkbBinaryStrategy())->encode($line)) ); } @@ -88,7 +88,7 @@ public function testLineStringEmpty(): void // Reference geometry in WKT: LINESTRING M EMPTY static::assertSame( '0102000060e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($line)) + bin2hex((new EwkbBinaryStrategy())->encode($line)) ); } @@ -103,7 +103,7 @@ public function testMultiLineString(): void // Reference geometry in WKT: MULTILINESTRING M ((0 0 10, 2 3 20), (4 1 30, 5 2 40)) static::assertSame( '0105000060e6100000020000000102000040020000000000000000000000000000000000000000000000000024400000000000000040000000000000084000000000000034400102000040020000000000000000001040000000000000f03f0000000000003e40000000000000144000000000000000400000000000004440', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($lines)) + bin2hex((new EwkbBinaryStrategy())->encode($lines)) ); } @@ -115,7 +115,7 @@ public function testMultiLineStringEmpty(): void // Reference geometry in WKT: MULTILINESTRING M EMPTY static::assertSame( '0105000060e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($lines)) + bin2hex((new EwkbBinaryStrategy())->encode($lines)) ); } @@ -127,7 +127,7 @@ public function testMultiPoint(): void // Reference geometry in WKT: MULTIPOINT M ((1 2 10), (3 4 20)) static::assertSame( '0104000060e6100000020000000101000040000000000000f03f000000000000004000000000000024400101000040000000000000084000000000000010400000000000003440', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($points)) + bin2hex((new EwkbBinaryStrategy())->encode($points)) ); } @@ -139,7 +139,7 @@ public function testMultiPointEmpty(): void // Reference geometry in WKT: MULTIPOINT M EMPTY static::assertSame( '0104000060e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($points)) + bin2hex((new EwkbBinaryStrategy())->encode($points)) ); } @@ -154,7 +154,7 @@ public function testMultiPolygon(): void // Reference geometry in WKT: MULTIPOLYGON M (((0 0 10, 2 0 10, 0 2 10, 0 0 10)), ((3 3 20, 5 3 20, 3 5 20, 3 3 20))) static::assertSame( '0106000060e6100000020000000103000040010000000400000000000000000000000000000000000000000000000000244000000000000000400000000000000000000000000000244000000000000000000000000000000040000000000000244000000000000000000000000000000000000000000000244001030000400100000004000000000000000000084000000000000008400000000000003440000000000000144000000000000008400000000000003440000000000000084000000000000014400000000000003440000000000000084000000000000008400000000000003440', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($polygons)) + bin2hex((new EwkbBinaryStrategy())->encode($polygons)) ); } @@ -166,7 +166,7 @@ public function testMultiPolygonEmpty(): void // Reference geometry in WKT: MULTIPOLYGON M EMPTY static::assertSame( '0106000060e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($polygons)) + bin2hex((new EwkbBinaryStrategy())->encode($polygons)) ); } @@ -178,7 +178,7 @@ public function testPoint(): void // Reference geometry in WKT: POINT M (2.5 -3 10) static::assertSame( '0101000060e6100000000000000000044000000000000008c00000000000002440', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($point)) + bin2hex((new EwkbBinaryStrategy())->encode($point)) ); } @@ -190,7 +190,7 @@ public function testPointEmpty(): void // Reference geometry in WKT: POINT M EMPTY static::assertSame( '0101000060e6100000000000000000f87f000000000000f87f000000000000f87f', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($point)) + bin2hex((new EwkbBinaryStrategy())->encode($point)) ); } @@ -205,7 +205,7 @@ public function testPolygon(): void // Reference geometry in WKT: POLYGON M ((0 0 10, 4 0 10, 4 4 10, 0 4 10, 0 0 10), (1 1 10, 1 2 10, 2 2 10, 2 1 10, 1 1 10)) static::assertSame( '0103000060e6100000020000000500000000000000000000000000000000000000000000000000244000000000000010400000000000000000000000000000244000000000000010400000000000001040000000000000244000000000000000000000000000001040000000000000244000000000000000000000000000000000000000000000244005000000000000000000f03f000000000000f03f0000000000002440000000000000f03f000000000000004000000000000024400000000000000040000000000000004000000000000024400000000000000040000000000000f03f0000000000002440000000000000f03f000000000000f03f0000000000002440', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($polygon)) + bin2hex((new EwkbBinaryStrategy())->encode($polygon)) ); } @@ -217,7 +217,7 @@ public function testPolygonEmpty(): void // Reference geometry in WKT: POLYGON M EMPTY static::assertSame( '0103000060e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($polygon)) + bin2hex((new EwkbBinaryStrategy())->encode($polygon)) ); } @@ -229,7 +229,7 @@ public function testTriangle(): void // Reference geometry in WKT: TRIANGLE M ((0 0 10, 2 0 10, 0 2 10, 0 0 10)) static::assertSame( '0111000060e61000000100000004000000000000000000000000000000000000000000000000002440000000000000004000000000000000000000000000002440000000000000000000000000000000400000000000002440000000000000000000000000000000000000000000002440', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($triangle)) + bin2hex((new EwkbBinaryStrategy())->encode($triangle)) ); } @@ -241,7 +241,7 @@ public function testTriangleEmpty(): void // Reference geometry in WKT: TRIANGLE M EMPTY static::assertSame( '0111000060e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($triangle)) + bin2hex((new EwkbBinaryStrategy())->encode($triangle)) ); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Ewkb/Examples/GeographyXyzTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Ewkb/Examples/GeographyXyzTest.php similarity index 86% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Ewkb/Examples/GeographyXyzTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Ewkb/Examples/GeographyXyzTest.php index 7e37f76..7ec6a02 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Ewkb/Examples/GeographyXyzTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Ewkb/Examples/GeographyXyzTest.php @@ -1,6 +1,6 @@ executeStrategy($collection)) + bin2hex((new EwkbBinaryStrategy())->encode($collection)) ); } @@ -62,7 +62,7 @@ public function testGeographyCollectionEmpty(): void // Reference geometry in WKT: GEOMETRYCOLLECTION Z EMPTY static::assertSame( '01070000a0e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($collection)) + bin2hex((new EwkbBinaryStrategy())->encode($collection)) ); } @@ -74,7 +74,7 @@ public function testLineString(): void // Reference geometry in WKT: LINESTRING Z (0 0 5, 2 3 6, 4 1 7) static::assertSame( '01020000a0e6100000030000000000000000000000000000000000000000000000000014400000000000000040000000000000084000000000000018400000000000001040000000000000f03f0000000000001c40', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($line)) + bin2hex((new EwkbBinaryStrategy())->encode($line)) ); } @@ -86,7 +86,7 @@ public function testLineStringEmpty(): void // Reference geometry in WKT: LINESTRING Z EMPTY static::assertSame( '01020000a0e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($line)) + bin2hex((new EwkbBinaryStrategy())->encode($line)) ); } @@ -101,7 +101,7 @@ public function testMultiLineString(): void // Reference geometry in WKT: MULTILINESTRING Z ((0 0 5, 2 3 6), (4 1 7, 5 2 8)) static::assertSame( '01050000a0e6100000020000000102000080020000000000000000000000000000000000000000000000000014400000000000000040000000000000084000000000000018400102000080020000000000000000001040000000000000f03f0000000000001c40000000000000144000000000000000400000000000002040', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($lines)) + bin2hex((new EwkbBinaryStrategy())->encode($lines)) ); } @@ -113,7 +113,7 @@ public function testMultiLineStringEmpty(): void // Reference geometry in WKT: MULTILINESTRING Z EMPTY static::assertSame( '01050000a0e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($lines)) + bin2hex((new EwkbBinaryStrategy())->encode($lines)) ); } @@ -125,7 +125,7 @@ public function testMultiPoint(): void // Reference geometry in WKT: MULTIPOINT Z ((1 2 5), (3 4 6)) static::assertSame( '01040000a0e6100000020000000101000080000000000000f03f000000000000004000000000000014400101000080000000000000084000000000000010400000000000001840', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($points)) + bin2hex((new EwkbBinaryStrategy())->encode($points)) ); } @@ -137,7 +137,7 @@ public function testMultiPointEmpty(): void // Reference geometry in WKT: MULTIPOINT Z EMPTY static::assertSame( '01040000a0e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($points)) + bin2hex((new EwkbBinaryStrategy())->encode($points)) ); } @@ -152,7 +152,7 @@ public function testMultiPolygon(): void // Reference geometry in WKT: MULTIPOLYGON Z (((0 0 5, 2 0 5, 0 2 5, 0 0 5)), ((3 3 6, 5 3 6, 3 5 6, 3 3 6))) static::assertSame( '01060000a0e6100000020000000103000080010000000400000000000000000000000000000000000000000000000000144000000000000000400000000000000000000000000000144000000000000000000000000000000040000000000000144000000000000000000000000000000000000000000000144001030000800100000004000000000000000000084000000000000008400000000000001840000000000000144000000000000008400000000000001840000000000000084000000000000014400000000000001840000000000000084000000000000008400000000000001840', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($polygons)) + bin2hex((new EwkbBinaryStrategy())->encode($polygons)) ); } @@ -164,7 +164,7 @@ public function testMultiPolygonEmpty(): void // Reference geometry in WKT: MULTIPOLYGON Z EMPTY static::assertSame( '01060000a0e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($polygons)) + bin2hex((new EwkbBinaryStrategy())->encode($polygons)) ); } @@ -176,7 +176,7 @@ public function testPoint(): void // Reference geometry in WKT: POINT Z (2.5 -3 5) static::assertSame( '01010000a0e6100000000000000000044000000000000008c00000000000001440', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($point)) + bin2hex((new EwkbBinaryStrategy())->encode($point)) ); } @@ -188,7 +188,7 @@ public function testPointEmpty(): void // Reference geometry in WKT: POINT Z EMPTY static::assertSame( '01010000a0e6100000000000000000f87f000000000000f87f000000000000f87f', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($point)) + bin2hex((new EwkbBinaryStrategy())->encode($point)) ); } @@ -203,7 +203,7 @@ public function testPolygon(): void // Reference geometry in WKT: POLYGON Z ((0 0 5, 4 0 5, 4 4 5, 0 4 5, 0 0 5), (1 1 5, 1 2 5, 2 2 5, 2 1 5, 1 1 5)) static::assertSame( '01030000a0e6100000020000000500000000000000000000000000000000000000000000000000144000000000000010400000000000000000000000000000144000000000000010400000000000001040000000000000144000000000000000000000000000001040000000000000144000000000000000000000000000000000000000000000144005000000000000000000f03f000000000000f03f0000000000001440000000000000f03f000000000000004000000000000014400000000000000040000000000000004000000000000014400000000000000040000000000000f03f0000000000001440000000000000f03f000000000000f03f0000000000001440', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($polygon)) + bin2hex((new EwkbBinaryStrategy())->encode($polygon)) ); } @@ -215,7 +215,7 @@ public function testPolygonEmpty(): void // Reference geometry in WKT: POLYGON Z EMPTY static::assertSame( '01030000a0e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($polygon)) + bin2hex((new EwkbBinaryStrategy())->encode($polygon)) ); } @@ -230,7 +230,7 @@ public function testPolyhedralSurface(): void // Reference geometry in WKT: POLYHEDRALSURFACE Z (((0 0 5, 1 0 5, 1 1 5, 0 1 5, 0 0 5)), ((1 0 5, 2 0 5, 2 1 5, 1 1 5, 1 0 5))) static::assertSame( '010f0000a0e61000000200000001030000800100000005000000000000000000000000000000000000000000000000001440000000000000f03f00000000000000000000000000001440000000000000f03f000000000000f03f00000000000014400000000000000000000000000000f03f000000000000144000000000000000000000000000000000000000000000144001030000800100000005000000000000000000f03f000000000000000000000000000014400000000000000040000000000000000000000000000014400000000000000040000000000000f03f0000000000001440000000000000f03f000000000000f03f0000000000001440000000000000f03f00000000000000000000000000001440', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($surface)) + bin2hex((new EwkbBinaryStrategy())->encode($surface)) ); } @@ -242,7 +242,7 @@ public function testPolyhedralSurfaceEmpty(): void // Reference geometry in WKT: POLYHEDRALSURFACE Z EMPTY static::assertSame( '010f0000a0e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($surface)) + bin2hex((new EwkbBinaryStrategy())->encode($surface)) ); } @@ -254,7 +254,7 @@ public function testTriangle(): void // Reference geometry in WKT: TRIANGLE Z ((0 0 5, 2 0 5, 0 2 5, 0 0 5)) static::assertSame( '01110000a0e61000000100000004000000000000000000000000000000000000000000000000001440000000000000004000000000000000000000000000001440000000000000000000000000000000400000000000001440000000000000000000000000000000000000000000001440', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($triangle)) + bin2hex((new EwkbBinaryStrategy())->encode($triangle)) ); } @@ -266,7 +266,7 @@ public function testTriangleEmpty(): void // Reference geometry in WKT: TRIANGLE Z EMPTY static::assertSame( '01110000a0e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($triangle)) + bin2hex((new EwkbBinaryStrategy())->encode($triangle)) ); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Ewkb/Examples/GeographyXyzmTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Ewkb/Examples/GeographyXyzmTest.php similarity index 87% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Ewkb/Examples/GeographyXyzmTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Ewkb/Examples/GeographyXyzmTest.php index 3226396..e02e7b4 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Ewkb/Examples/GeographyXyzmTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Ewkb/Examples/GeographyXyzmTest.php @@ -1,6 +1,6 @@ executeStrategy($collection)) + bin2hex((new EwkbBinaryStrategy())->encode($collection)) ); } @@ -62,7 +62,7 @@ public function testGeographyCollectionEmpty(): void // Reference geometry in WKT: GEOMETRYCOLLECTION ZM EMPTY static::assertSame( '01070000e0e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($collection)) + bin2hex((new EwkbBinaryStrategy())->encode($collection)) ); } @@ -74,7 +74,7 @@ public function testLineString(): void // Reference geometry in WKT: LINESTRING ZM (0 0 5 10, 2 3 6 20, 4 1 7 30) static::assertSame( '01020000e0e610000003000000000000000000000000000000000000000000000000001440000000000000244000000000000000400000000000000840000000000000184000000000000034400000000000001040000000000000f03f0000000000001c400000000000003e40', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($line)) + bin2hex((new EwkbBinaryStrategy())->encode($line)) ); } @@ -86,7 +86,7 @@ public function testLineStringEmpty(): void // Reference geometry in WKT: LINESTRING ZM EMPTY static::assertSame( '01020000e0e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($line)) + bin2hex((new EwkbBinaryStrategy())->encode($line)) ); } @@ -101,7 +101,7 @@ public function testMultiLineString(): void // Reference geometry in WKT: MULTILINESTRING ZM ((0 0 5 10, 2 3 6 20), (4 1 7 30, 5 2 8 40)) static::assertSame( '01050000e0e61000000200000001020000c0020000000000000000000000000000000000000000000000000014400000000000002440000000000000004000000000000008400000000000001840000000000000344001020000c0020000000000000000001040000000000000f03f0000000000001c400000000000003e400000000000001440000000000000004000000000000020400000000000004440', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($lines)) + bin2hex((new EwkbBinaryStrategy())->encode($lines)) ); } @@ -113,7 +113,7 @@ public function testMultiLineStringEmpty(): void // Reference geometry in WKT: MULTILINESTRING ZM EMPTY static::assertSame( '01050000e0e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($lines)) + bin2hex((new EwkbBinaryStrategy())->encode($lines)) ); } @@ -125,7 +125,7 @@ public function testMultiPoint(): void // Reference geometry in WKT: MULTIPOINT ZM ((1 2 5 10), (3 4 6 20)) static::assertSame( '01040000e0e61000000200000001010000c0000000000000f03f00000000000000400000000000001440000000000000244001010000c00000000000000840000000000000104000000000000018400000000000003440', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($points)) + bin2hex((new EwkbBinaryStrategy())->encode($points)) ); } @@ -137,7 +137,7 @@ public function testMultiPointEmpty(): void // Reference geometry in WKT: MULTIPOINT ZM EMPTY static::assertSame( '01040000e0e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($points)) + bin2hex((new EwkbBinaryStrategy())->encode($points)) ); } @@ -152,7 +152,7 @@ public function testMultiPolygon(): void // Reference geometry in WKT: MULTIPOLYGON ZM (((0 0 5 10, 2 0 5 10, 0 2 5 10, 0 0 5 10)), ((3 3 6 20, 5 3 6 20, 3 5 6 20, 3 3 6 20))) static::assertSame( '01060000e0e61000000200000001030000c00100000004000000000000000000000000000000000000000000000000001440000000000000244000000000000000400000000000000000000000000000144000000000000024400000000000000000000000000000004000000000000014400000000000002440000000000000000000000000000000000000000000001440000000000000244001030000c001000000040000000000000000000840000000000000084000000000000018400000000000003440000000000000144000000000000008400000000000001840000000000000344000000000000008400000000000001440000000000000184000000000000034400000000000000840000000000000084000000000000018400000000000003440', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($polygons)) + bin2hex((new EwkbBinaryStrategy())->encode($polygons)) ); } @@ -164,7 +164,7 @@ public function testMultiPolygonEmpty(): void // Reference geometry in WKT: MULTIPOLYGON ZM EMPTY static::assertSame( '01060000e0e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($polygons)) + bin2hex((new EwkbBinaryStrategy())->encode($polygons)) ); } @@ -176,7 +176,7 @@ public function testPoint(): void // Reference geometry in WKT: POINT ZM (2.5 -3 5 10) static::assertSame( '01010000e0e6100000000000000000044000000000000008c000000000000014400000000000002440', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($point)) + bin2hex((new EwkbBinaryStrategy())->encode($point)) ); } @@ -188,7 +188,7 @@ public function testPointEmpty(): void // Reference geometry in WKT: POINT ZM EMPTY static::assertSame( '01010000e0e6100000000000000000f87f000000000000f87f000000000000f87f000000000000f87f', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($point)) + bin2hex((new EwkbBinaryStrategy())->encode($point)) ); } @@ -203,7 +203,7 @@ public function testPolygon(): void // Reference geometry in WKT: POLYGON ZM ((0 0 5 10, 4 0 5 10, 4 4 5 10, 0 4 5 10, 0 0 5 10), (1 1 5 10, 1 2 5 10, 2 2 5 10, 2 1 5 10, 1 1 5 10)) static::assertSame( '01030000e0e610000002000000050000000000000000000000000000000000000000000000000014400000000000002440000000000000104000000000000000000000000000001440000000000000244000000000000010400000000000001040000000000000144000000000000024400000000000000000000000000000104000000000000014400000000000002440000000000000000000000000000000000000000000001440000000000000244005000000000000000000f03f000000000000f03f00000000000014400000000000002440000000000000f03f00000000000000400000000000001440000000000000244000000000000000400000000000000040000000000000144000000000000024400000000000000040000000000000f03f00000000000014400000000000002440000000000000f03f000000000000f03f00000000000014400000000000002440', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($polygon)) + bin2hex((new EwkbBinaryStrategy())->encode($polygon)) ); } @@ -215,7 +215,7 @@ public function testPolygonEmpty(): void // Reference geometry in WKT: POLYGON ZM EMPTY static::assertSame( '01030000e0e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($polygon)) + bin2hex((new EwkbBinaryStrategy())->encode($polygon)) ); } @@ -230,7 +230,7 @@ public function testPolyhedralSurface(): void // Reference geometry in WKT: POLYHEDRALSURFACE ZM (((0 0 5 10, 1 0 5 10, 1 1 5 10, 0 1 5 10, 0 0 5 10)), ((1 0 5 10, 2 0 5 10, 2 1 5 10, 1 1 5 10, 1 0 5 10))) static::assertSame( '010f0000e0e61000000200000001030000c001000000050000000000000000000000000000000000000000000000000014400000000000002440000000000000f03f000000000000000000000000000014400000000000002440000000000000f03f000000000000f03f000000000000144000000000000024400000000000000000000000000000f03f00000000000014400000000000002440000000000000000000000000000000000000000000001440000000000000244001030000c00100000005000000000000000000f03f00000000000000000000000000001440000000000000244000000000000000400000000000000000000000000000144000000000000024400000000000000040000000000000f03f00000000000014400000000000002440000000000000f03f000000000000f03f00000000000014400000000000002440000000000000f03f000000000000000000000000000014400000000000002440', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($surface)) + bin2hex((new EwkbBinaryStrategy())->encode($surface)) ); } @@ -242,7 +242,7 @@ public function testPolyhedralSurfaceEmpty(): void // Reference geometry in WKT: POLYHEDRALSURFACE ZM EMPTY static::assertSame( '010f0000e0e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($surface)) + bin2hex((new EwkbBinaryStrategy())->encode($surface)) ); } @@ -254,7 +254,7 @@ public function testTriangle(): void // Reference geometry in WKT: TRIANGLE ZM ((0 0 5 10, 2 0 5 10, 0 2 5 10, 0 0 5 10)) static::assertSame( '01110000e0e610000001000000040000000000000000000000000000000000000000000000000014400000000000002440000000000000004000000000000000000000000000001440000000000000244000000000000000000000000000000040000000000000144000000000000024400000000000000000000000000000000000000000000014400000000000002440', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($triangle)) + bin2hex((new EwkbBinaryStrategy())->encode($triangle)) ); } @@ -266,7 +266,7 @@ public function testTriangleEmpty(): void // Reference geometry in WKT: TRIANGLE ZM EMPTY static::assertSame( '01110000e0e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($triangle)) + bin2hex((new EwkbBinaryStrategy())->encode($triangle)) ); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Ewkb/Examples/GeometryXyTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Ewkb/Examples/GeometryXyTest.php similarity index 84% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Ewkb/Examples/GeometryXyTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Ewkb/Examples/GeometryXyTest.php index 6e0ae56..a8c2ef4 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Ewkb/Examples/GeometryXyTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Ewkb/Examples/GeometryXyTest.php @@ -1,6 +1,6 @@ executeStrategy($collection)) + bin2hex((new EwkbBinaryStrategy())->encode($collection)) ); } @@ -61,7 +61,7 @@ public function testGeometryCollectionEmpty(): void // Reference geometry in WKT: GEOMETRYCOLLECTION EMPTY static::assertSame( '0107000020e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($collection)) + bin2hex((new EwkbBinaryStrategy())->encode($collection)) ); } @@ -73,7 +73,7 @@ public function testLineString(): void // Reference geometry in WKT: LINESTRING (0 0, 2 3, 4 1) static::assertSame( '0102000020e61000000300000000000000000000000000000000000000000000000000004000000000000008400000000000001040000000000000f03f', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($line)) + bin2hex((new EwkbBinaryStrategy())->encode($line)) ); } @@ -85,7 +85,7 @@ public function testLineStringEmpty(): void // Reference geometry in WKT: LINESTRING EMPTY static::assertSame( '0102000020e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($line)) + bin2hex((new EwkbBinaryStrategy())->encode($line)) ); } @@ -100,7 +100,7 @@ public function testMultiLineString(): void // Reference geometry in WKT: MULTILINESTRING ((0 0, 2 3), (4 1, 5 2)) static::assertSame( '0105000020e61000000200000001020000000200000000000000000000000000000000000000000000000000004000000000000008400102000000020000000000000000001040000000000000f03f00000000000014400000000000000040', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($lines)) + bin2hex((new EwkbBinaryStrategy())->encode($lines)) ); } @@ -112,7 +112,7 @@ public function testMultiLineStringEmpty(): void // Reference geometry in WKT: MULTILINESTRING EMPTY static::assertSame( '0105000020e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($lines)) + bin2hex((new EwkbBinaryStrategy())->encode($lines)) ); } @@ -124,7 +124,7 @@ public function testMultiPoint(): void // Reference geometry in WKT: MULTIPOINT ((1 2), (3 4)) static::assertSame( '0104000020e6100000020000000101000000000000000000f03f0000000000000040010100000000000000000008400000000000001040', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($points)) + bin2hex((new EwkbBinaryStrategy())->encode($points)) ); } @@ -136,7 +136,7 @@ public function testMultiPointEmpty(): void // Reference geometry in WKT: MULTIPOINT EMPTY static::assertSame( '0104000020e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($points)) + bin2hex((new EwkbBinaryStrategy())->encode($points)) ); } @@ -151,7 +151,7 @@ public function testMultiPolygon(): void // Reference geometry in WKT: MULTIPOLYGON (((0 0, 2 0, 0 2, 0 0)), ((3 3, 5 3, 3 5, 3 3))) static::assertSame( '0106000020e61000000200000001030000000100000004000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000040000000000000000000000000000000000103000000010000000400000000000000000008400000000000000840000000000000144000000000000008400000000000000840000000000000144000000000000008400000000000000840', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($polygons)) + bin2hex((new EwkbBinaryStrategy())->encode($polygons)) ); } @@ -163,7 +163,7 @@ public function testMultiPolygonEmpty(): void // Reference geometry in WKT: MULTIPOLYGON EMPTY static::assertSame( '0106000020e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($polygons)) + bin2hex((new EwkbBinaryStrategy())->encode($polygons)) ); } @@ -175,7 +175,7 @@ public function testPoint(): void // Reference geometry in WKT: POINT (2.5 -3) static::assertSame( '0101000020e6100000000000000000044000000000000008c0', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($point)) + bin2hex((new EwkbBinaryStrategy())->encode($point)) ); } @@ -187,7 +187,7 @@ public function testPointEmpty(): void // Reference geometry in WKT: POINT EMPTY static::assertSame( '0101000020e6100000000000000000f87f000000000000f87f', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($point)) + bin2hex((new EwkbBinaryStrategy())->encode($point)) ); } @@ -202,7 +202,7 @@ public function testPolygon(): void // Reference geometry in WKT: POLYGON ((0 0, 4 0, 4 4, 0 4, 0 0), (1 1, 1 2, 2 2, 2 1, 1 1)) static::assertSame( '0103000020e61000000200000005000000000000000000000000000000000000000000000000001040000000000000000000000000000010400000000000001040000000000000000000000000000010400000000000000000000000000000000005000000000000000000f03f000000000000f03f000000000000f03f0000000000000040000000000000004000000000000000400000000000000040000000000000f03f000000000000f03f000000000000f03f', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($polygon)) + bin2hex((new EwkbBinaryStrategy())->encode($polygon)) ); } @@ -214,7 +214,7 @@ public function testPolygonEmpty(): void // Reference geometry in WKT: POLYGON EMPTY static::assertSame( '0103000020e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($polygon)) + bin2hex((new EwkbBinaryStrategy())->encode($polygon)) ); } @@ -226,7 +226,7 @@ public function testTriangle(): void // Reference geometry in WKT: TRIANGLE ((0 0, 2 0, 0 2, 0 0)) static::assertSame( '0111000020e6100000010000000400000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000004000000000000000000000000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($triangle)) + bin2hex((new EwkbBinaryStrategy())->encode($triangle)) ); } @@ -238,7 +238,7 @@ public function testTriangleEmpty(): void // Reference geometry in WKT: TRIANGLE EMPTY static::assertSame( '0111000020e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($triangle)) + bin2hex((new EwkbBinaryStrategy())->encode($triangle)) ); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Ewkb/Examples/GeometryXymTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Ewkb/Examples/GeometryXymTest.php similarity index 86% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Ewkb/Examples/GeometryXymTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Ewkb/Examples/GeometryXymTest.php index 9dff09b..566b402 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Ewkb/Examples/GeometryXymTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Ewkb/Examples/GeometryXymTest.php @@ -1,6 +1,6 @@ executeStrategy($collection)) + bin2hex((new EwkbBinaryStrategy())->encode($collection)) ); } @@ -61,7 +61,7 @@ public function testGeometryCollectionEmpty(): void // Reference geometry in WKT: GEOMETRYCOLLECTION M EMPTY static::assertSame( '0107000060e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($collection)) + bin2hex((new EwkbBinaryStrategy())->encode($collection)) ); } @@ -73,7 +73,7 @@ public function testLineString(): void // Reference geometry in WKT: LINESTRING M (0 0 10, 2 3 20, 4 1 30) static::assertSame( '0102000060e6100000030000000000000000000000000000000000000000000000000024400000000000000040000000000000084000000000000034400000000000001040000000000000f03f0000000000003e40', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($line)) + bin2hex((new EwkbBinaryStrategy())->encode($line)) ); } @@ -85,7 +85,7 @@ public function testLineStringEmpty(): void // Reference geometry in WKT: LINESTRING M EMPTY static::assertSame( '0102000060e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($line)) + bin2hex((new EwkbBinaryStrategy())->encode($line)) ); } @@ -100,7 +100,7 @@ public function testMultiLineString(): void // Reference geometry in WKT: MULTILINESTRING M ((0 0 10, 2 3 20), (4 1 30, 5 2 40)) static::assertSame( '0105000060e6100000020000000102000040020000000000000000000000000000000000000000000000000024400000000000000040000000000000084000000000000034400102000040020000000000000000001040000000000000f03f0000000000003e40000000000000144000000000000000400000000000004440', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($lines)) + bin2hex((new EwkbBinaryStrategy())->encode($lines)) ); } @@ -112,7 +112,7 @@ public function testMultiLineStringEmpty(): void // Reference geometry in WKT: MULTILINESTRING M EMPTY static::assertSame( '0105000060e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($lines)) + bin2hex((new EwkbBinaryStrategy())->encode($lines)) ); } @@ -124,7 +124,7 @@ public function testMultiPoint(): void // Reference geometry in WKT: MULTIPOINT M ((1 2 10), (3 4 20)) static::assertSame( '0104000060e6100000020000000101000040000000000000f03f000000000000004000000000000024400101000040000000000000084000000000000010400000000000003440', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($points)) + bin2hex((new EwkbBinaryStrategy())->encode($points)) ); } @@ -136,7 +136,7 @@ public function testMultiPointEmpty(): void // Reference geometry in WKT: MULTIPOINT M EMPTY static::assertSame( '0104000060e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($points)) + bin2hex((new EwkbBinaryStrategy())->encode($points)) ); } @@ -151,7 +151,7 @@ public function testMultiPolygon(): void // Reference geometry in WKT: MULTIPOLYGON M (((0 0 10, 2 0 10, 0 2 10, 0 0 10)), ((3 3 20, 5 3 20, 3 5 20, 3 3 20))) static::assertSame( '0106000060e6100000020000000103000040010000000400000000000000000000000000000000000000000000000000244000000000000000400000000000000000000000000000244000000000000000000000000000000040000000000000244000000000000000000000000000000000000000000000244001030000400100000004000000000000000000084000000000000008400000000000003440000000000000144000000000000008400000000000003440000000000000084000000000000014400000000000003440000000000000084000000000000008400000000000003440', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($polygons)) + bin2hex((new EwkbBinaryStrategy())->encode($polygons)) ); } @@ -163,7 +163,7 @@ public function testMultiPolygonEmpty(): void // Reference geometry in WKT: MULTIPOLYGON M EMPTY static::assertSame( '0106000060e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($polygons)) + bin2hex((new EwkbBinaryStrategy())->encode($polygons)) ); } @@ -175,7 +175,7 @@ public function testPoint(): void // Reference geometry in WKT: POINT M (2.5 -3 10) static::assertSame( '0101000060e6100000000000000000044000000000000008c00000000000002440', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($point)) + bin2hex((new EwkbBinaryStrategy())->encode($point)) ); } @@ -187,7 +187,7 @@ public function testPointEmpty(): void // Reference geometry in WKT: POINT M EMPTY static::assertSame( '0101000060e6100000000000000000f87f000000000000f87f000000000000f87f', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($point)) + bin2hex((new EwkbBinaryStrategy())->encode($point)) ); } @@ -202,7 +202,7 @@ public function testPolygon(): void // Reference geometry in WKT: POLYGON M ((0 0 10, 4 0 10, 4 4 10, 0 4 10, 0 0 10), (1 1 10, 1 2 10, 2 2 10, 2 1 10, 1 1 10)) static::assertSame( '0103000060e6100000020000000500000000000000000000000000000000000000000000000000244000000000000010400000000000000000000000000000244000000000000010400000000000001040000000000000244000000000000000000000000000001040000000000000244000000000000000000000000000000000000000000000244005000000000000000000f03f000000000000f03f0000000000002440000000000000f03f000000000000004000000000000024400000000000000040000000000000004000000000000024400000000000000040000000000000f03f0000000000002440000000000000f03f000000000000f03f0000000000002440', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($polygon)) + bin2hex((new EwkbBinaryStrategy())->encode($polygon)) ); } @@ -214,7 +214,7 @@ public function testPolygonEmpty(): void // Reference geometry in WKT: POLYGON M EMPTY static::assertSame( '0103000060e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($polygon)) + bin2hex((new EwkbBinaryStrategy())->encode($polygon)) ); } @@ -226,7 +226,7 @@ public function testTriangle(): void // Reference geometry in WKT: TRIANGLE M ((0 0 10, 2 0 10, 0 2 10, 0 0 10)) static::assertSame( '0111000060e61000000100000004000000000000000000000000000000000000000000000000002440000000000000004000000000000000000000000000002440000000000000000000000000000000400000000000002440000000000000000000000000000000000000000000002440', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($triangle)) + bin2hex((new EwkbBinaryStrategy())->encode($triangle)) ); } @@ -238,7 +238,7 @@ public function testTriangleEmpty(): void // Reference geometry in WKT: TRIANGLE M EMPTY static::assertSame( '0111000060e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($triangle)) + bin2hex((new EwkbBinaryStrategy())->encode($triangle)) ); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Ewkb/Examples/GeometryXyzTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Ewkb/Examples/GeometryXyzTest.php similarity index 86% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Ewkb/Examples/GeometryXyzTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Ewkb/Examples/GeometryXyzTest.php index a3d561b..b7fb384 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Ewkb/Examples/GeometryXyzTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Ewkb/Examples/GeometryXyzTest.php @@ -1,6 +1,6 @@ executeStrategy($collection)) + bin2hex((new EwkbBinaryStrategy())->encode($collection)) ); } @@ -62,7 +62,7 @@ public function testGeometryCollectionEmpty(): void // Reference geometry in WKT: GEOMETRYCOLLECTION Z EMPTY static::assertSame( '01070000a0e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($collection)) + bin2hex((new EwkbBinaryStrategy())->encode($collection)) ); } @@ -74,7 +74,7 @@ public function testLineString(): void // Reference geometry in WKT: LINESTRING Z (0 0 5, 2 3 6, 4 1 7) static::assertSame( '01020000a0e6100000030000000000000000000000000000000000000000000000000014400000000000000040000000000000084000000000000018400000000000001040000000000000f03f0000000000001c40', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($line)) + bin2hex((new EwkbBinaryStrategy())->encode($line)) ); } @@ -86,7 +86,7 @@ public function testLineStringEmpty(): void // Reference geometry in WKT: LINESTRING Z EMPTY static::assertSame( '01020000a0e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($line)) + bin2hex((new EwkbBinaryStrategy())->encode($line)) ); } @@ -101,7 +101,7 @@ public function testMultiLineString(): void // Reference geometry in WKT: MULTILINESTRING Z ((0 0 5, 2 3 6), (4 1 7, 5 2 8)) static::assertSame( '01050000a0e6100000020000000102000080020000000000000000000000000000000000000000000000000014400000000000000040000000000000084000000000000018400102000080020000000000000000001040000000000000f03f0000000000001c40000000000000144000000000000000400000000000002040', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($lines)) + bin2hex((new EwkbBinaryStrategy())->encode($lines)) ); } @@ -113,7 +113,7 @@ public function testMultiLineStringEmpty(): void // Reference geometry in WKT: MULTILINESTRING Z EMPTY static::assertSame( '01050000a0e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($lines)) + bin2hex((new EwkbBinaryStrategy())->encode($lines)) ); } @@ -125,7 +125,7 @@ public function testMultiPoint(): void // Reference geometry in WKT: MULTIPOINT Z ((1 2 5), (3 4 6)) static::assertSame( '01040000a0e6100000020000000101000080000000000000f03f000000000000004000000000000014400101000080000000000000084000000000000010400000000000001840', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($points)) + bin2hex((new EwkbBinaryStrategy())->encode($points)) ); } @@ -137,7 +137,7 @@ public function testMultiPointEmpty(): void // Reference geometry in WKT: MULTIPOINT Z EMPTY static::assertSame( '01040000a0e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($points)) + bin2hex((new EwkbBinaryStrategy())->encode($points)) ); } @@ -152,7 +152,7 @@ public function testMultiPolygon(): void // Reference geometry in WKT: MULTIPOLYGON Z (((0 0 5, 2 0 5, 0 2 5, 0 0 5)), ((3 3 6, 5 3 6, 3 5 6, 3 3 6))) static::assertSame( '01060000a0e6100000020000000103000080010000000400000000000000000000000000000000000000000000000000144000000000000000400000000000000000000000000000144000000000000000000000000000000040000000000000144000000000000000000000000000000000000000000000144001030000800100000004000000000000000000084000000000000008400000000000001840000000000000144000000000000008400000000000001840000000000000084000000000000014400000000000001840000000000000084000000000000008400000000000001840', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($polygons)) + bin2hex((new EwkbBinaryStrategy())->encode($polygons)) ); } @@ -164,7 +164,7 @@ public function testMultiPolygonEmpty(): void // Reference geometry in WKT: MULTIPOLYGON Z EMPTY static::assertSame( '01060000a0e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($polygons)) + bin2hex((new EwkbBinaryStrategy())->encode($polygons)) ); } @@ -176,7 +176,7 @@ public function testPoint(): void // Reference geometry in WKT: POINT Z (2.5 -3 5) static::assertSame( '01010000a0e6100000000000000000044000000000000008c00000000000001440', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($point)) + bin2hex((new EwkbBinaryStrategy())->encode($point)) ); } @@ -188,7 +188,7 @@ public function testPointEmpty(): void // Reference geometry in WKT: POINT Z EMPTY static::assertSame( '01010000a0e6100000000000000000f87f000000000000f87f000000000000f87f', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($point)) + bin2hex((new EwkbBinaryStrategy())->encode($point)) ); } @@ -203,7 +203,7 @@ public function testPolygon(): void // Reference geometry in WKT: POLYGON Z ((0 0 5, 4 0 5, 4 4 5, 0 4 5, 0 0 5), (1 1 5, 1 2 5, 2 2 5, 2 1 5, 1 1 5)) static::assertSame( '01030000a0e6100000020000000500000000000000000000000000000000000000000000000000144000000000000010400000000000000000000000000000144000000000000010400000000000001040000000000000144000000000000000000000000000001040000000000000144000000000000000000000000000000000000000000000144005000000000000000000f03f000000000000f03f0000000000001440000000000000f03f000000000000004000000000000014400000000000000040000000000000004000000000000014400000000000000040000000000000f03f0000000000001440000000000000f03f000000000000f03f0000000000001440', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($polygon)) + bin2hex((new EwkbBinaryStrategy())->encode($polygon)) ); } @@ -215,7 +215,7 @@ public function testPolygonEmpty(): void // Reference geometry in WKT: POLYGON Z EMPTY static::assertSame( '01030000a0e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($polygon)) + bin2hex((new EwkbBinaryStrategy())->encode($polygon)) ); } @@ -230,7 +230,7 @@ public function testPolyhedralSurface(): void // Reference geometry in WKT: POLYHEDRALSURFACE Z (((0 0 5, 1 0 5, 1 1 5, 0 1 5, 0 0 5)), ((1 0 5, 2 0 5, 2 1 5, 1 1 5, 1 0 5))) static::assertSame( '010f0000a0e61000000200000001030000800100000005000000000000000000000000000000000000000000000000001440000000000000f03f00000000000000000000000000001440000000000000f03f000000000000f03f00000000000014400000000000000000000000000000f03f000000000000144000000000000000000000000000000000000000000000144001030000800100000005000000000000000000f03f000000000000000000000000000014400000000000000040000000000000000000000000000014400000000000000040000000000000f03f0000000000001440000000000000f03f000000000000f03f0000000000001440000000000000f03f00000000000000000000000000001440', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($surface)) + bin2hex((new EwkbBinaryStrategy())->encode($surface)) ); } @@ -242,7 +242,7 @@ public function testPolyhedralSurfaceEmpty(): void // Reference geometry in WKT: POLYHEDRALSURFACE Z EMPTY static::assertSame( '010f0000a0e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($surface)) + bin2hex((new EwkbBinaryStrategy())->encode($surface)) ); } @@ -254,7 +254,7 @@ public function testTriangle(): void // Reference geometry in WKT: TRIANGLE Z ((0 0 5, 2 0 5, 0 2 5, 0 0 5)) static::assertSame( '01110000a0e61000000100000004000000000000000000000000000000000000000000000000001440000000000000004000000000000000000000000000001440000000000000000000000000000000400000000000001440000000000000000000000000000000000000000000001440', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($triangle)) + bin2hex((new EwkbBinaryStrategy())->encode($triangle)) ); } @@ -266,7 +266,7 @@ public function testTriangleEmpty(): void // Reference geometry in WKT: TRIANGLE Z EMPTY static::assertSame( '01110000a0e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($triangle)) + bin2hex((new EwkbBinaryStrategy())->encode($triangle)) ); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Ewkb/Examples/GeometryXyzmTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Ewkb/Examples/GeometryXyzmTest.php similarity index 87% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Ewkb/Examples/GeometryXyzmTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Ewkb/Examples/GeometryXyzmTest.php index 00f1ccb..e038eab 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Ewkb/Examples/GeometryXyzmTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Ewkb/Examples/GeometryXyzmTest.php @@ -1,6 +1,6 @@ executeStrategy($collection)) + bin2hex((new EwkbBinaryStrategy())->encode($collection)) ); } @@ -62,7 +62,7 @@ public function testGeometryCollectionEmpty(): void // Reference geometry in WKT: GEOMETRYCOLLECTION ZM EMPTY static::assertSame( '01070000e0e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($collection)) + bin2hex((new EwkbBinaryStrategy())->encode($collection)) ); } @@ -74,7 +74,7 @@ public function testLineString(): void // Reference geometry in WKT: LINESTRING ZM (0 0 5 10, 2 3 6 20, 4 1 7 30) static::assertSame( '01020000e0e610000003000000000000000000000000000000000000000000000000001440000000000000244000000000000000400000000000000840000000000000184000000000000034400000000000001040000000000000f03f0000000000001c400000000000003e40', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($line)) + bin2hex((new EwkbBinaryStrategy())->encode($line)) ); } @@ -86,7 +86,7 @@ public function testLineStringEmpty(): void // Reference geometry in WKT: LINESTRING ZM EMPTY static::assertSame( '01020000e0e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($line)) + bin2hex((new EwkbBinaryStrategy())->encode($line)) ); } @@ -101,7 +101,7 @@ public function testMultiLineString(): void // Reference geometry in WKT: MULTILINESTRING ZM ((0 0 5 10, 2 3 6 20), (4 1 7 30, 5 2 8 40)) static::assertSame( '01050000e0e61000000200000001020000c0020000000000000000000000000000000000000000000000000014400000000000002440000000000000004000000000000008400000000000001840000000000000344001020000c0020000000000000000001040000000000000f03f0000000000001c400000000000003e400000000000001440000000000000004000000000000020400000000000004440', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($lines)) + bin2hex((new EwkbBinaryStrategy())->encode($lines)) ); } @@ -113,7 +113,7 @@ public function testMultiLineStringEmpty(): void // Reference geometry in WKT: MULTILINESTRING ZM EMPTY static::assertSame( '01050000e0e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($lines)) + bin2hex((new EwkbBinaryStrategy())->encode($lines)) ); } @@ -125,7 +125,7 @@ public function testMultiPoint(): void // Reference geometry in WKT: MULTIPOINT ZM ((1 2 5 10), (3 4 6 20)) static::assertSame( '01040000e0e61000000200000001010000c0000000000000f03f00000000000000400000000000001440000000000000244001010000c00000000000000840000000000000104000000000000018400000000000003440', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($points)) + bin2hex((new EwkbBinaryStrategy())->encode($points)) ); } @@ -137,7 +137,7 @@ public function testMultiPointEmpty(): void // Reference geometry in WKT: MULTIPOINT ZM EMPTY static::assertSame( '01040000e0e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($points)) + bin2hex((new EwkbBinaryStrategy())->encode($points)) ); } @@ -152,7 +152,7 @@ public function testMultiPolygon(): void // Reference geometry in WKT: MULTIPOLYGON ZM (((0 0 5 10, 2 0 5 10, 0 2 5 10, 0 0 5 10)), ((3 3 6 20, 5 3 6 20, 3 5 6 20, 3 3 6 20))) static::assertSame( '01060000e0e61000000200000001030000c00100000004000000000000000000000000000000000000000000000000001440000000000000244000000000000000400000000000000000000000000000144000000000000024400000000000000000000000000000004000000000000014400000000000002440000000000000000000000000000000000000000000001440000000000000244001030000c001000000040000000000000000000840000000000000084000000000000018400000000000003440000000000000144000000000000008400000000000001840000000000000344000000000000008400000000000001440000000000000184000000000000034400000000000000840000000000000084000000000000018400000000000003440', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($polygons)) + bin2hex((new EwkbBinaryStrategy())->encode($polygons)) ); } @@ -164,7 +164,7 @@ public function testMultiPolygonEmpty(): void // Reference geometry in WKT: MULTIPOLYGON ZM EMPTY static::assertSame( '01060000e0e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($polygons)) + bin2hex((new EwkbBinaryStrategy())->encode($polygons)) ); } @@ -176,7 +176,7 @@ public function testPoint(): void // Reference geometry in WKT: POINT ZM (2.5 -3 5 10) static::assertSame( '01010000e0e6100000000000000000044000000000000008c000000000000014400000000000002440', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($point)) + bin2hex((new EwkbBinaryStrategy())->encode($point)) ); } @@ -188,7 +188,7 @@ public function testPointEmpty(): void // Reference geometry in WKT: POINT ZM EMPTY static::assertSame( '01010000e0e6100000000000000000f87f000000000000f87f000000000000f87f000000000000f87f', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($point)) + bin2hex((new EwkbBinaryStrategy())->encode($point)) ); } @@ -203,7 +203,7 @@ public function testPolygon(): void // Reference geometry in WKT: POLYGON ZM ((0 0 5 10, 4 0 5 10, 4 4 5 10, 0 4 5 10, 0 0 5 10), (1 1 5 10, 1 2 5 10, 2 2 5 10, 2 1 5 10, 1 1 5 10)) static::assertSame( '01030000e0e610000002000000050000000000000000000000000000000000000000000000000014400000000000002440000000000000104000000000000000000000000000001440000000000000244000000000000010400000000000001040000000000000144000000000000024400000000000000000000000000000104000000000000014400000000000002440000000000000000000000000000000000000000000001440000000000000244005000000000000000000f03f000000000000f03f00000000000014400000000000002440000000000000f03f00000000000000400000000000001440000000000000244000000000000000400000000000000040000000000000144000000000000024400000000000000040000000000000f03f00000000000014400000000000002440000000000000f03f000000000000f03f00000000000014400000000000002440', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($polygon)) + bin2hex((new EwkbBinaryStrategy())->encode($polygon)) ); } @@ -215,7 +215,7 @@ public function testPolygonEmpty(): void // Reference geometry in WKT: POLYGON ZM EMPTY static::assertSame( '01030000e0e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($polygon)) + bin2hex((new EwkbBinaryStrategy())->encode($polygon)) ); } @@ -230,7 +230,7 @@ public function testPolyhedralSurface(): void // Reference geometry in WKT: POLYHEDRALSURFACE ZM (((0 0 5 10, 1 0 5 10, 1 1 5 10, 0 1 5 10, 0 0 5 10)), ((1 0 5 10, 2 0 5 10, 2 1 5 10, 1 1 5 10, 1 0 5 10))) static::assertSame( '010f0000e0e61000000200000001030000c001000000050000000000000000000000000000000000000000000000000014400000000000002440000000000000f03f000000000000000000000000000014400000000000002440000000000000f03f000000000000f03f000000000000144000000000000024400000000000000000000000000000f03f00000000000014400000000000002440000000000000000000000000000000000000000000001440000000000000244001030000c00100000005000000000000000000f03f00000000000000000000000000001440000000000000244000000000000000400000000000000000000000000000144000000000000024400000000000000040000000000000f03f00000000000014400000000000002440000000000000f03f000000000000f03f00000000000014400000000000002440000000000000f03f000000000000000000000000000014400000000000002440', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($surface)) + bin2hex((new EwkbBinaryStrategy())->encode($surface)) ); } @@ -242,7 +242,7 @@ public function testPolyhedralSurfaceEmpty(): void // Reference geometry in WKT: POLYHEDRALSURFACE ZM EMPTY static::assertSame( '010f0000e0e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($surface)) + bin2hex((new EwkbBinaryStrategy())->encode($surface)) ); } @@ -254,7 +254,7 @@ public function testTriangle(): void // Reference geometry in WKT: TRIANGLE ZM ((0 0 5 10, 2 0 5 10, 0 2 5 10, 0 0 5 10)) static::assertSame( '01110000e0e610000001000000040000000000000000000000000000000000000000000000000014400000000000002440000000000000004000000000000000000000000000001440000000000000244000000000000000000000000000000040000000000000144000000000000024400000000000000000000000000000000000000000000014400000000000002440', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($triangle)) + bin2hex((new EwkbBinaryStrategy())->encode($triangle)) ); } @@ -266,7 +266,7 @@ public function testTriangleEmpty(): void // Reference geometry in WKT: TRIANGLE ZM EMPTY static::assertSame( '01110000e0e610000000000000', - bin2hex((new EwkbBinaryStrategy())->executeStrategy($triangle)) + bin2hex((new EwkbBinaryStrategy())->encode($triangle)) ); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/EwkbStrategyTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/EwkbStrategyTest.php similarity index 96% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/EwkbStrategyTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/EwkbStrategyTest.php index 0b4dc48..fd94bdf 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/EwkbStrategyTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/EwkbStrategyTest.php @@ -1,6 +1,6 @@ strategy->executeStrategy($collection)))); + static::assertSame($expected, mb_strtoupper(bin2hex($this->strategy->encode($collection)))); } /** @@ -172,7 +172,7 @@ public static function collectionProvider(): \Generator #[DataProvider('lineStringProvider')] public function testLineString(LineStringInterface $lineString, string $expected): void { - static::assertSame(mb_strtolower($expected), bin2hex($this->strategy->executeStrategy($lineString))); + static::assertSame(mb_strtolower($expected), bin2hex($this->strategy->encode($lineString))); } /** @@ -225,7 +225,7 @@ public static function lineStringProvider(): \Generator #[DataProvider('multiLineStringProvider')] public function testMultiLineString(MultiLineStringInterface $multiLineString, string $expected): void { - static::assertSame(mb_strtolower($expected), bin2hex($this->strategy->executeStrategy($multiLineString))); + static::assertSame(mb_strtolower($expected), bin2hex($this->strategy->encode($multiLineString))); } /** @@ -270,7 +270,7 @@ public static function multiLineStringProvider(): \Generator #[DataProvider('multiPointProvider')] public function testMultiPoint(MultiPointInterface $multiPoint, string $expected): void { - static::assertSame(mb_strtolower($expected), bin2hex($this->strategy->executeStrategy($multiPoint))); + static::assertSame(mb_strtolower($expected), bin2hex($this->strategy->encode($multiPoint))); } /** @@ -305,7 +305,7 @@ public static function multiPointProvider(): \Generator #[DataProvider('multiPolygonProvider')] public function testMultiPolygon(MultiPolygonInterface $multiPolygon, string $expected): void { - static::assertSame(mb_strtolower($expected), bin2hex($this->strategy->executeStrategy($multiPolygon))); + static::assertSame(mb_strtolower($expected), bin2hex($this->strategy->encode($multiPolygon))); } /** @@ -353,7 +353,7 @@ public static function multiPolygonProvider(): \Generator #[DataProvider('pointProvider')] public function testPoint(PointInterface $point, string $expected): void { - static::assertSame(mb_strtolower($expected), bin2hex($this->strategy->executeStrategy($point))); + static::assertSame(mb_strtolower($expected), bin2hex($this->strategy->encode($point))); } /** @@ -426,7 +426,7 @@ public static function pointProvider(): \Generator #[DataProvider('polygonProvider')] public function testPolygon(PolygonInterface $polygon, string $expected): void { - static::assertSame(mb_strtolower($expected), bin2hex($this->strategy->executeStrategy($polygon))); + static::assertSame(mb_strtolower($expected), bin2hex($this->strategy->encode($polygon))); } /** diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/EwktStrategyTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/EwktStrategyTest.php similarity index 78% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/EwktStrategyTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/EwktStrategyTest.php index 350554c..02d49d9 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/EwktStrategyTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/EwktStrategyTest.php @@ -1,6 +1,6 @@ executeStrategy($collection) + (new EwktTextStrategy())->encode($collection) ); } @@ -61,7 +61,7 @@ public function testCollectionZm(): void static::assertSame( 'SRID=4326;GEOMETRYCOLLECTION ZM (POINT ZM (1 2 3 4))', - (new EwktTextStrategy())->executeStrategy($collection) + (new EwktTextStrategy())->encode($collection) ); } @@ -70,7 +70,7 @@ public function testEmptyCollection(): void { $collection = new GeometryCollection(4326); - static::assertSame('SRID=4326;GEOMETRYCOLLECTION EMPTY', (new EwktTextStrategy())->executeStrategy($collection)); + static::assertSame('SRID=4326;GEOMETRYCOLLECTION EMPTY', (new EwktTextStrategy())->encode($collection)); } /** An empty geometry with SRID zero has no prefix. */ @@ -78,7 +78,7 @@ public function testEmptyPointWithoutSrid(): void { $point = new Point(); - static::assertSame('POINT EMPTY', (new EwktTextStrategy())->executeStrategy($point)); + static::assertSame('POINT EMPTY', (new EwktTextStrategy())->encode($point)); } /** An empty geometry still carries its nonzero SRID. */ @@ -86,7 +86,7 @@ public function testEmptyPointWithSrid(): void { $point = new Point(srid: 4326); - static::assertSame('SRID=4326;POINT EMPTY', (new EwktTextStrategy())->executeStrategy($point)); + static::assertSame('SRID=4326;POINT EMPTY', (new EwktTextStrategy())->encode($point)); } /** Preserve the dimension of an empty point. */ @@ -94,7 +94,18 @@ public function testEmptyPointZm(): void { $point = new PointZm(srid: 4326); - static::assertSame('SRID=4326;POINT ZM EMPTY', (new EwktTextStrategy())->executeStrategy($point)); + static::assertSame('SRID=4326;POINT ZM EMPTY', (new EwktTextStrategy())->encode($point)); + } + + /** The encoder can switch between EWKT and plain WKT. */ + public function testEncoderIntegration(): void + { + $point = new Point(1, 2, 4326); + $encoder = new Encoder(new EwktTextStrategy()); + + static::assertSame('SRID=4326;POINT (1 2)', $encoder->encode($point)); + $encoder->setStrategy(new WktTextStrategy()); + static::assertSame('POINT (1 2)', $encoder->encode($point)); } /** Preserve geography coordinates and decimal formatting. */ @@ -102,7 +113,7 @@ public function testGeographicPoint(): void { $point = new GeographicPoint(2.5, -3, 4326); - static::assertSame('SRID=4326;POINT (2.5 -3)', (new EwktTextStrategy())->executeStrategy($point)); + static::assertSame('SRID=4326;POINT (2.5 -3)', (new EwktTextStrategy())->encode($point)); } /** Write the SRID once for a homogeneous collection. */ @@ -110,7 +121,7 @@ public function testMultiPoint(): void { $points = new MultiPoint([[1, 2], [3, 4]], 4326); - static::assertSame('SRID=4326;MULTIPOINT ((1 2), (3 4))', (new EwktTextStrategy())->executeStrategy($points)); + static::assertSame('SRID=4326;MULTIPOINT ((1 2), (3 4))', (new EwktTextStrategy())->encode($points)); } /** Nested collection members must never receive their own SRID prefixes. */ @@ -127,7 +138,7 @@ public function testNestedCollection(): void static::assertSame( 'SRID=4326;GEOMETRYCOLLECTION (POINT (1 2), GEOMETRYCOLLECTION (LINESTRING (0 0, 2 3), POINT EMPTY), GEOMETRYCOLLECTION EMPTY)', - (new EwktTextStrategy())->executeStrategy($collection) + (new EwktTextStrategy())->encode($collection) ); } @@ -136,7 +147,7 @@ public function testPointM(): void { $point = new PointM(1, 2, 4, 4326); - static::assertSame('SRID=4326;POINT M (1 2 4)', (new EwktTextStrategy())->executeStrategy($point)); + static::assertSame('SRID=4326;POINT M (1 2 4)', (new EwktTextStrategy())->encode($point)); } /** The default zero SRID produces plain WKT. */ @@ -144,7 +155,7 @@ public function testPointWithDefaultSrid(): void { $point = new Point(1, 2); - static::assertSame('POINT (1 2)', (new EwktTextStrategy())->executeStrategy($point)); + static::assertSame('POINT (1 2)', (new EwktTextStrategy())->encode($point)); } /** Prefix a point with its nonzero SRID. */ @@ -152,7 +163,7 @@ public function testPointWithSrid(): void { $point = new Point(1, 2, 4326); - static::assertSame('SRID=4326;POINT (1 2)', (new EwktTextStrategy())->executeStrategy($point)); + static::assertSame('SRID=4326;POINT (1 2)', (new EwktTextStrategy())->encode($point)); } /** An explicit zero SRID also produces plain WKT. */ @@ -160,7 +171,7 @@ public function testPointWithZeroSrid(): void { $point = new Point(1, 2, 0); - static::assertSame('POINT (1 2)', (new EwktTextStrategy())->executeStrategy($point)); + static::assertSame('POINT (1 2)', (new EwktTextStrategy())->encode($point)); } /** Preserve the elevation marker and ordinate. */ @@ -168,7 +179,7 @@ public function testPointZ(): void { $point = new PointZ(1, 2, 3, 4326); - static::assertSame('SRID=4326;POINT Z (1 2 3)', (new EwktTextStrategy())->executeStrategy($point)); + static::assertSame('SRID=4326;POINT Z (1 2 3)', (new EwktTextStrategy())->encode($point)); } /** Preserve elevation and measure in their original order. */ @@ -176,7 +187,7 @@ public function testPointZm(): void { $point = new PointZm(1, 2, 3, 4, 4326); - static::assertSame('SRID=4326;POINT ZM (1 2 3 4)', (new EwktTextStrategy())->executeStrategy($point)); + static::assertSame('SRID=4326;POINT ZM (1 2 3 4)', (new EwktTextStrategy())->encode($point)); } /** Reusing a strategy must read the SRID of each new geometry. */ @@ -184,19 +195,8 @@ public function testRepeatedConversions(): void { $strategy = new EwktTextStrategy(); - static::assertSame('SRID=4326;POINT (1 2)', $strategy->executeStrategy(new Point(1, 2, 4326))); - static::assertSame('POINT (3 4)', $strategy->executeStrategy(new Point(3, 4))); - static::assertSame('SRID=7035;POINT (5 6)', $strategy->executeStrategy(new Point(5, 6, 7035))); - } - - /** The writer can switch between EWKT and plain WKT. */ - public function testWriterIntegration(): void - { - $point = new Point(1, 2, 4326); - $writer = new Writer(new EwktTextStrategy()); - - static::assertSame('SRID=4326;POINT (1 2)', $writer->convert($point)); - $writer->setStrategy(new WktTextStrategy()); - static::assertSame('POINT (1 2)', $writer->convert($point)); + static::assertSame('SRID=4326;POINT (1 2)', $strategy->encode(new Point(1, 2, 4326))); + static::assertSame('POINT (3 4)', $strategy->encode(new Point(3, 4))); + static::assertSame('SRID=7035;POINT (5 6)', $strategy->encode(new Point(5, 6, 7035))); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/ExceptionContractTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/ExceptionContractTest.php similarity index 84% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/ExceptionContractTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/ExceptionContractTest.php index 186bf85..c3c52c8 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/ExceptionContractTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/ExceptionContractTest.php @@ -1,6 +1,6 @@ convert($collection); + (new Encoder(new GeoJsonStrategy()))->encode($collection); static::fail('JSON encoding must fail.'); } catch (JsonEncodingException $exception) { static::assertInstanceOf(\JsonException::class, $exception->getPrevious()); @@ -72,7 +72,7 @@ public function testInfinityEncodingFailure(): void $point = new Point(INF, 2); try { - (new GeoJsonStrategy())->executeStrategy($point); + (new GeoJsonStrategy())->encode($point); static::fail('JSON encoding must fail.'); } catch (JsonEncodingException $exception) { static::assertContains(ExceptionInterface::class, (new \ReflectionClass($exception))->getInterfaceNames()); @@ -102,7 +102,7 @@ public function testLineStringEncodingFailure(): void $line = new LineString([[1, 2], [INF, 3]]); try { - (new Writer(new GeoJsonStrategy()))->convert($line); + (new Encoder(new GeoJsonStrategy()))->encode($line); static::fail('JSON encoding must fail.'); } catch (JsonEncodingException $exception) { static::assertInstanceOf(\JsonException::class, $exception->getPrevious()); @@ -116,7 +116,7 @@ public function testMultiLineStringEncodingFailure(): void $multiLine = new MultiLineString([[[1, 2], [3, 4]], [[5, 6], [INF, 8]]]); try { - (new Writer(new GeoJsonStrategy()))->convert($multiLine); + (new Encoder(new GeoJsonStrategy()))->encode($multiLine); static::fail('JSON encoding must fail.'); } catch (JsonEncodingException $exception) { static::assertInstanceOf(\JsonException::class, $exception->getPrevious()); @@ -130,7 +130,7 @@ public function testMultiPointEncodingFailure(): void $multiPoint = new MultiPoint([[1, 2], [INF, 3]]); try { - (new Writer(new GeoJsonStrategy()))->convert($multiPoint); + (new Encoder(new GeoJsonStrategy()))->encode($multiPoint); static::fail('JSON encoding must fail.'); } catch (JsonEncodingException $exception) { static::assertInstanceOf(\JsonException::class, $exception->getPrevious()); @@ -144,7 +144,7 @@ public function testMultiPolygonEncodingFailure(): void $multiPolygon = new MultiPolygon([[[[0, 0, 1], [2, 0, INF], [0, 2, 3], [0, 0, 1]]]]); try { - (new Writer(new GeoJsonStrategy()))->convert($multiPolygon); + (new Encoder(new GeoJsonStrategy()))->encode($multiPolygon); static::fail('JSON encoding must fail.'); } catch (JsonEncodingException $exception) { static::assertInstanceOf(\JsonException::class, $exception->getPrevious()); @@ -158,7 +158,7 @@ public function testNanEncodingFailure(): void $point = new Point(NAN, 2); try { - (new GeoJsonStrategy())->executeStrategy($point); + (new GeoJsonStrategy())->encode($point); static::fail('JSON encoding must fail.'); } catch (JsonEncodingException $exception) { static::assertContains(ExceptionInterface::class, (new \ReflectionClass($exception))->getInterfaceNames()); @@ -173,7 +173,7 @@ public function testNegativeInfinityEncodingFailure(): void $point = new Point(-INF, 2); try { - (new GeoJsonStrategy())->executeStrategy($point); + (new GeoJsonStrategy())->encode($point); static::fail('JSON encoding must fail.'); } catch (JsonEncodingException $exception) { static::assertContains(ExceptionInterface::class, (new \ReflectionClass($exception))->getInterfaceNames()); @@ -188,7 +188,7 @@ public function testPolygonEncodingFailure(): void $polygon = new Polygon([[[0, 0, 1], [2, 0, INF], [0, 2, 3], [0, 0, 1]]]); try { - (new Writer(new GeoJsonStrategy()))->convert($polygon); + (new Encoder(new GeoJsonStrategy()))->encode($polygon); static::fail('JSON encoding must fail.'); } catch (JsonEncodingException $exception) { static::assertInstanceOf(\JsonException::class, $exception->getPrevious()); @@ -197,14 +197,14 @@ public function testPolygonEncodingFailure(): void } /** Preserve the internal exception for a missing collection interface. */ - public function testUnsupportedCollectionInterfaceThroughWriter(): void + public function testUnsupportedCollectionInterfaceThroughEncoder(): void { $spatial = static::createStub(SpatialInterface::class); $spatial->method('getType')->willReturn(GeometryTypeEnum::GEOMETRYCOLLECTION); $spatial->method('hasM')->willReturn(false); $this->expectException(UnsupportedSpatialInterfaceException::class); - (new Writer(new GeoJsonStrategy()))->convert($spatial); + (new Encoder(new GeoJsonStrategy()))->encode($spatial); } /** Preserve the approved public exception inheritance and constructor contract. */ @@ -238,70 +238,70 @@ public function testUnsupportedGeometryStructureExceptionContract(): void } /** Reject a declared LineString without its corresponding interface. */ - public function testUnsupportedLineStringInterfaceThroughWriter(): void + public function testUnsupportedLineStringInterfaceThroughEncoder(): void { $spatial = static::createStub(SpatialInterface::class); $spatial->method('getType')->willReturn(GeometryTypeEnum::LINESTRING); $spatial->method('hasM')->willReturn(false); $this->expectException(UnsupportedSpatialInterfaceException::class); - (new Writer(new GeoJsonStrategy()))->convert($spatial); + (new Encoder(new GeoJsonStrategy()))->encode($spatial); } /** Reject a declared MultiLineString without its corresponding interface. */ - public function testUnsupportedMultiLineStringInterfaceThroughWriter(): void + public function testUnsupportedMultiLineStringInterfaceThroughEncoder(): void { $spatial = static::createStub(SpatialInterface::class); $spatial->method('getType')->willReturn(GeometryTypeEnum::MULTILINESTRING); $spatial->method('hasM')->willReturn(false); $this->expectException(UnsupportedSpatialInterfaceException::class); - (new Writer(new GeoJsonStrategy()))->convert($spatial); + (new Encoder(new GeoJsonStrategy()))->encode($spatial); } /** Reject a declared MultiPoint without its corresponding interface. */ - public function testUnsupportedMultiPointInterfaceThroughWriter(): void + public function testUnsupportedMultiPointInterfaceThroughEncoder(): void { $spatial = static::createStub(SpatialInterface::class); $spatial->method('getType')->willReturn(GeometryTypeEnum::MULTIPOINT); $spatial->method('hasM')->willReturn(false); $this->expectException(UnsupportedSpatialInterfaceException::class); - (new Writer(new GeoJsonStrategy()))->convert($spatial); + (new Encoder(new GeoJsonStrategy()))->encode($spatial); } /** Preserve the internal exception for a missing MultiPolygon interface. */ - public function testUnsupportedMultiPolygonInterfaceThroughWriter(): void + public function testUnsupportedMultiPolygonInterfaceThroughEncoder(): void { $spatial = static::createStub(SpatialInterface::class); $spatial->method('getType')->willReturn(GeometryTypeEnum::MULTIPOLYGON); $spatial->method('hasM')->willReturn(false); $this->expectException(UnsupportedSpatialInterfaceException::class); - (new Writer(new GeoJsonStrategy()))->convert($spatial); + (new Encoder(new GeoJsonStrategy()))->encode($spatial); } - /** Reject a declared Point without its interface through the public writer. */ - public function testUnsupportedPointInterfaceThroughWriter(): void + /** Reject a declared Point without its interface through the public encoder. */ + public function testUnsupportedPointInterfaceThroughEncoder(): void { $spatial = static::createStub(SpatialInterface::class); $spatial->method('getType')->willReturn(GeometryTypeEnum::POINT); $spatial->method('hasM')->willReturn(false); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); $this->expectException(UnsupportedSpatialInterfaceException::class); - $writer->convert($spatial); + $encoder->encode($spatial); } /** Reject a declared Polygon without its corresponding interface. */ - public function testUnsupportedPolygonInterfaceThroughWriter(): void + public function testUnsupportedPolygonInterfaceThroughEncoder(): void { $spatial = static::createStub(SpatialInterface::class); $spatial->method('getType')->willReturn(GeometryTypeEnum::POLYGON); $spatial->method('hasM')->willReturn(false); $this->expectException(UnsupportedSpatialInterfaceException::class); - (new Writer(new GeoJsonStrategy()))->convert($spatial); + (new Encoder(new GeoJsonStrategy()))->encode($spatial); } /** Preserve the approved public exception inheritance and constructor contract. */ diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/GeographyCollectionTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/GeographyCollectionTest.php similarity index 75% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/GeographyCollectionTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/GeographyCollectionTest.php index 3d59506..56a666b 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/GeographyCollectionTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/GeographyCollectionTest.php @@ -1,6 +1,6 @@ convert($collection)); - static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[1,2]},{"type":"LineString","coordinates":[[3,4],[5,6]]},{"type":"MultiPoint","coordinates":[[7,8],[9,10]]},{"type":"MultiLineString","coordinates":[[[11,12],[13,14]]]},{"type":"Polygon","coordinates":[[[0,0],[2,0],[0,2],[0,0]]]},{"type":"MultiPolygon","coordinates":[[[[3,0],[5,0],[3,2],[3,0]]]]}]}', (new GeoJsonStrategy())->executeStrategy($collection)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($collection); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[1,2]},{"type":"LineString","coordinates":[[3,4],[5,6]]},{"type":"MultiPoint","coordinates":[[7,8],[9,10]]},{"type":"MultiLineString","coordinates":[[[11,12],[13,14]]]},{"type":"Polygon","coordinates":[[[0,0],[2,0],[0,2],[0,0]]]},{"type":"MultiPolygon","coordinates":[[[[3,0],[5,0],[3,2],[3,0]]]]}]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[1,2]},{"type":"LineString","coordinates":[[3,4],[5,6]]},{"type":"MultiPoint","coordinates":[[7,8],[9,10]]},{"type":"MultiLineString","coordinates":[[[11,12],[13,14]]]},{"type":"Polygon","coordinates":[[[0,0],[2,0],[0,2],[0,0]]]},{"type":"MultiPolygon","coordinates":[[[[3,0],[5,0],[3,2],[3,0]]]]}]}', (new GeoJsonStrategy())->encode($collection)); } /** Preserve the complete collection structure and values. */ @@ -58,8 +60,10 @@ public function testAntimeridian(): void { $collection = new GeographyCollection(0, [new LineString([[170, 45], [-170, 45]])]); - static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"LineString","coordinates":[[170,45],[-170,45]]}]}', (new Writer(new GeoJsonStrategy()))->convert($collection)); - static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"LineString","coordinates":[[170,45],[-170,45]]}]}', (new GeoJsonStrategy())->executeStrategy($collection)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($collection); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"LineString","coordinates":[[170,45],[-170,45]]}]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"LineString","coordinates":[[170,45],[-170,45]]}]}', (new GeoJsonStrategy())->encode($collection)); } /** Preserve the complete collection structure and values. */ @@ -67,8 +71,10 @@ public function testEmptyXy(): void { $collection = new GeographyCollection(0, []); - static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[]}', (new Writer(new GeoJsonStrategy()))->convert($collection)); - static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[]}', (new GeoJsonStrategy())->executeStrategy($collection)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($collection); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[]}', (new GeoJsonStrategy())->encode($collection)); } /** Preserve the complete collection structure and values. */ @@ -76,8 +82,10 @@ public function testEmptyXyz(): void { $collection = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\GeographyCollection(0, []); - static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[]}', (new Writer(new GeoJsonStrategy()))->convert($collection)); - static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[]}', (new GeoJsonStrategy())->executeStrategy($collection)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($collection); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[]}', (new GeoJsonStrategy())->encode($collection)); } /** Preserve the complete collection structure and values. */ @@ -85,8 +93,10 @@ public function testHomogeneous(): void { $collection = new GeographyCollection(0, [new Point(3, 4), new Point(1, 2), new Point(3, 4)]); - static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[3,4]},{"type":"Point","coordinates":[1,2]},{"type":"Point","coordinates":[3,4]}]}', (new Writer(new GeoJsonStrategy()))->convert($collection)); - static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[3,4]},{"type":"Point","coordinates":[1,2]},{"type":"Point","coordinates":[3,4]}]}', (new GeoJsonStrategy())->executeStrategy($collection)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($collection); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[3,4]},{"type":"Point","coordinates":[1,2]},{"type":"Point","coordinates":[3,4]}]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[3,4]},{"type":"Point","coordinates":[1,2]},{"type":"Point","coordinates":[3,4]}]}', (new GeoJsonStrategy())->encode($collection)); } /** Preserve the complete collection structure and values. */ @@ -94,8 +104,10 @@ public function testNestedEmpty(): void { $collection = new GeographyCollection(0, [new GeographyCollection(0, [new Point()]), new GeographyCollection(0, [])]); - static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[]}]},{"type":"GeometryCollection","geometries":[]}]}', (new Writer(new GeoJsonStrategy()))->convert($collection)); - static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[]}]},{"type":"GeometryCollection","geometries":[]}]}', (new GeoJsonStrategy())->executeStrategy($collection)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($collection); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[]}]},{"type":"GeometryCollection","geometries":[]}]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[]}]},{"type":"GeometryCollection","geometries":[]}]}', (new GeoJsonStrategy())->encode($collection)); } /** Propagate failure without returning a partial collection. */ @@ -104,7 +116,7 @@ public function testRejectClockwisePolygon(): void $collection = new GeographyCollection(0, [new Point(1, 2), new Polygon([[[0, 0], [0, 2], [2, 0], [0, 0]]])]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($collection); + (new Encoder(new GeoJsonStrategy()))->encode($collection); } /** Propagate failure without returning a partial collection. */ @@ -113,7 +125,7 @@ public function testRejectDimension3m(): void $collection = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\GeographyCollection(0, [new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\Point(1, 2, 3)]); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($collection); + (new Encoder(new GeoJsonStrategy()))->encode($collection); } /** Propagate failure without returning a partial collection. */ @@ -122,7 +134,7 @@ public function testRejectDimension4zm(): void $collection = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\GeographyCollection(0, [new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\Point(1, 2, 3, 4)]); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($collection); + (new Encoder(new GeoJsonStrategy()))->encode($collection); } /** Propagate failure without returning a partial collection. */ @@ -131,7 +143,7 @@ public function testRejectEmptyDimension3m(): void $collection = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\GeographyCollection(0, []); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($collection); + (new Encoder(new GeoJsonStrategy()))->encode($collection); } /** Propagate failure without returning a partial collection. */ @@ -140,7 +152,7 @@ public function testRejectEmptyDimension4zm(): void $collection = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\GeographyCollection(0, []); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($collection); + (new Encoder(new GeoJsonStrategy()))->encode($collection); } /** Propagate failure without returning a partial collection. */ @@ -149,7 +161,7 @@ public function testRejectEmptyMultiPointMember(): void $collection = new GeographyCollection(0, [new Point(1, 2), new MultiPoint([new Point()])]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($collection); + (new Encoder(new GeoJsonStrategy()))->encode($collection); } /** Propagate failure without returning a partial collection. */ @@ -158,7 +170,7 @@ public function testRejectNestedSingletonLine(): void $collection = new GeographyCollection(0, [new Point(1, 2), new GeographyCollection(0, [new LineString([[3, 4]])])]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($collection); + (new Encoder(new GeoJsonStrategy()))->encode($collection); } /** Propagate failure without returning a partial collection. */ @@ -167,7 +179,7 @@ public function testRejectNestedTriangle(): void $collection = new GeographyCollection(0, [new Point(1, 2), new GeographyCollection(0, [new Triangle([[[0, 0], [2, 0], [0, 2], [0, 0]]])])]); $this->expectException(UnsupportedSpatialTypeException::class); - (new Writer(new GeoJsonStrategy()))->convert($collection); + (new Encoder(new GeoJsonStrategy()))->encode($collection); } /** Preserve the complete collection structure and values. */ @@ -175,8 +187,10 @@ public function testXy(): void { $collection = new GeographyCollection(4326, [new Point(1, 2, 4326), new LineString([[3, 4], [5, 6]], 4326)]); - static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[1,2]},{"type":"LineString","coordinates":[[3,4],[5,6]]}]}', (new Writer(new GeoJsonStrategy()))->convert($collection)); - static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[1,2]},{"type":"LineString","coordinates":[[3,4],[5,6]]}]}', (new GeoJsonStrategy())->executeStrategy($collection)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($collection); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[1,2]},{"type":"LineString","coordinates":[[3,4],[5,6]]}]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[1,2]},{"type":"LineString","coordinates":[[3,4],[5,6]]}]}', (new GeoJsonStrategy())->encode($collection)); } /** Preserve the complete collection structure and values. */ @@ -184,7 +198,9 @@ public function testXyzSingleton(): void { $collection = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\GeographyCollection(new SpatialReference(999999, 'CUSTOM'), [new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\Point(1, 2, 3, new SpatialReference(999999, 'CUSTOM'))]); - static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[1,2,3]}]}', (new Writer(new GeoJsonStrategy()))->convert($collection)); - static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[1,2,3]}]}', (new GeoJsonStrategy())->executeStrategy($collection)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($collection); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[1,2,3]}]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[1,2,3]}]}', (new GeoJsonStrategy())->encode($collection)); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/GeographyLineStringTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/GeographyLineStringTest.php similarity index 68% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/GeographyLineStringTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/GeographyLineStringTest.php index e078a4b..1d8f536 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/GeographyLineStringTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/GeographyLineStringTest.php @@ -1,6 +1,6 @@ convert($line)); - static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[3.5,4.25],[1,2],[-7,8]]}', (new GeoJsonStrategy())->executeStrategy($line)); + $encoded = $encoder->encode($line); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[3.5,4.25],[1,2],[-7,8]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[3.5,4.25],[1,2],[-7,8]]}', (new GeoJsonStrategy())->encode($line)); } /** Preserve coordinates and their order without reference metadata. */ public function testAdditionalXyzPositions(): void { $line = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\LineString([[3, 4, 9.5], [1, 2, -2], [-7, 8, 0]]); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[3,4,9.5],[1,2,-2],[-7,8,0]]}', $writer->convert($line)); - static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[3,4,9.5],[1,2,-2],[-7,8,0]]}', (new GeoJsonStrategy())->executeStrategy($line)); + $encoded = $encoder->encode($line); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[3,4,9.5],[1,2,-2],[-7,8,0]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[3,4,9.5],[1,2,-2],[-7,8,0]]}', (new GeoJsonStrategy())->encode($line)); } /** Preserve coordinates and their order without reference metadata. */ public function testAntimeridian(): void { $line = new LineString([[170, 45], [-170, 45]], 4326); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[170,45],[-170,45]]}', $writer->convert($line)); - static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[170,45],[-170,45]]}', (new GeoJsonStrategy())->executeStrategy($line)); + $encoded = $encoder->encode($line); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[170,45],[-170,45]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[170,45],[-170,45]]}', (new GeoJsonStrategy())->encode($line)); } /** Preserve coordinates and their order without reference metadata. */ public function testDeclaredEpsg(): void { $line = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\LineString([[1, 2, 3], [4, 5, 6]], new SpatialReference(4326, 'EPSG')); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[1,2,3],[4,5,6]]}', $writer->convert($line)); - static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[1,2,3],[4,5,6]]}', (new GeoJsonStrategy())->executeStrategy($line)); + $encoded = $encoder->encode($line); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[1,2,3],[4,5,6]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[1,2,3],[4,5,6]]}', (new GeoJsonStrategy())->encode($line)); } /** Preserve coordinates and their order without reference metadata. */ public function testEmptyXy(): void { $line = new LineString([]); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[]}', $writer->convert($line)); - static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[]}', (new GeoJsonStrategy())->executeStrategy($line)); + $encoded = $encoder->encode($line); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[]}', (new GeoJsonStrategy())->encode($line)); } /** Preserve coordinates and their order without reference metadata. */ public function testEmptyXyz(): void { $line = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\LineString([]); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[]}', $writer->convert($line)); - static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[]}', (new GeoJsonStrategy())->executeStrategy($line)); + $encoded = $encoder->encode($line); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[]}', (new GeoJsonStrategy())->encode($line)); } /** Preserve coordinates and their order without reference metadata. */ public function testOtherSrid(): void { $line = new LineString([[1, 2], [3, 4]], 3857); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[1,2],[3,4]]}', $writer->convert($line)); - static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[1,2],[3,4]]}', (new GeoJsonStrategy())->executeStrategy($line)); + $encoded = $encoder->encode($line); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[1,2],[3,4]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[1,2],[3,4]]}', (new GeoJsonStrategy())->encode($line)); } /** Reject an incompatible concrete input without modifying it. */ @@ -111,7 +125,7 @@ public function testRejectEmptyXym(): void { $line = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\LineString([]); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($line); + (new Encoder(new GeoJsonStrategy()))->encode($line); } /** Reject an incompatible concrete input without modifying it. */ @@ -119,7 +133,7 @@ public function testRejectEmptyXyzm(): void { $line = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\LineString([]); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($line); + (new Encoder(new GeoJsonStrategy()))->encode($line); } /** Reject an incompatible concrete input without modifying it. */ @@ -127,7 +141,7 @@ public function testRejectSingletonXy(): void { $line = new LineString([[1, 2]]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($line); + (new Encoder(new GeoJsonStrategy()))->encode($line); } /** Reject an incompatible concrete input without modifying it. */ @@ -135,7 +149,7 @@ public function testRejectSingletonXyz(): void { $line = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\LineString([[1, 2, 3]]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($line); + (new Encoder(new GeoJsonStrategy()))->encode($line); } /** Reject an incompatible concrete input without modifying it. */ @@ -143,7 +157,7 @@ public function testRejectXym(): void { $line = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\LineString([[1, 2, 3], [4, 5, 6]]); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($line); + (new Encoder(new GeoJsonStrategy()))->encode($line); } /** Reject an incompatible concrete input without modifying it. */ @@ -151,36 +165,42 @@ public function testRejectXyzm(): void { $line = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\LineString([[1, 2, 3, 4], [5, 6, 7, 8]]); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($line); + (new Encoder(new GeoJsonStrategy()))->encode($line); } /** Preserve coordinates and their order without reference metadata. */ public function testUnknownReference(): void { $line = new LineString([[1, 2], [3, 4]], new SpatialReference(999999, 'CUSTOM')); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[1,2],[3,4]]}', $writer->convert($line)); - static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[1,2],[3,4]]}', (new GeoJsonStrategy())->executeStrategy($line)); + $encoded = $encoder->encode($line); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[1,2],[3,4]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[1,2],[3,4]]}', (new GeoJsonStrategy())->encode($line)); } /** Preserve coordinates and their order without reference metadata. */ public function testXy(): void { $line = new LineString([[1, 2], [3, 4]]); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[1,2],[3,4]]}', $writer->convert($line)); - static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[1,2],[3,4]]}', (new GeoJsonStrategy())->executeStrategy($line)); + $encoded = $encoder->encode($line); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[1,2],[3,4]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[1,2],[3,4]]}', (new GeoJsonStrategy())->encode($line)); } /** Preserve coordinates and their order without reference metadata. */ public function testXyz(): void { $line = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\LineString([[1, 2, 3], [4, 5, 6]]); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[1,2,3],[4,5,6]]}', $writer->convert($line)); - static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[1,2,3],[4,5,6]]}', (new GeoJsonStrategy())->executeStrategy($line)); + $encoded = $encoder->encode($line); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[1,2,3],[4,5,6]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[1,2,3],[4,5,6]]}', (new GeoJsonStrategy())->encode($line)); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/GeographyMultiLineStringTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/GeographyMultiLineStringTest.php similarity index 73% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/GeographyMultiLineStringTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/GeographyMultiLineStringTest.php index 0517322..f092576 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/GeographyMultiLineStringTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/GeographyMultiLineStringTest.php @@ -1,6 +1,6 @@ convert($multiLine)); - static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[170,45],[-170,45]],[[1,2],[3,4]]]}', (new GeoJsonStrategy())->executeStrategy($multiLine)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($multiLine); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[170,45],[-170,45]],[[1,2],[3,4]]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[170,45],[-170,45]],[[1,2],[3,4]]]}', (new GeoJsonStrategy())->encode($multiLine)); } /** Preserve line membership, coordinates and order without reference metadata. */ @@ -51,8 +53,10 @@ public function testDeclaredReference(): void { $multiLine = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\MultiLineString([[[1, 2, 3], [4, 5, 6]]], new SpatialReference(4326, 'EPSG')); - static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[1,2,3],[4,5,6]]]}', (new Writer(new GeoJsonStrategy()))->convert($multiLine)); - static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[1,2,3],[4,5,6]]]}', (new GeoJsonStrategy())->executeStrategy($multiLine)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($multiLine); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[1,2,3],[4,5,6]]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[1,2,3],[4,5,6]]]}', (new GeoJsonStrategy())->encode($multiLine)); } /** Preserve line membership, coordinates and order without reference metadata. */ @@ -60,8 +64,10 @@ public function testEmptyXy(): void { $multiLine = new MultiLineString([]); - static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[]}', (new Writer(new GeoJsonStrategy()))->convert($multiLine)); - static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[]}', (new GeoJsonStrategy())->executeStrategy($multiLine)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($multiLine); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[]}', (new GeoJsonStrategy())->encode($multiLine)); } /** Preserve line membership, coordinates and order without reference metadata. */ @@ -69,8 +75,10 @@ public function testEmptyXyz(): void { $multiLine = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\MultiLineString([]); - static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[]}', (new Writer(new GeoJsonStrategy()))->convert($multiLine)); - static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[]}', (new GeoJsonStrategy())->executeStrategy($multiLine)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($multiLine); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[]}', (new GeoJsonStrategy())->encode($multiLine)); } /** Preserve line membership, coordinates and order without reference metadata. */ @@ -78,8 +86,10 @@ public function testMemberAndPositionOrder(): void { $multiLine = new MultiLineString([[[7.5, 8], [5, 6], [-2, 1]], [[3, 4], [1, 2]]]); - static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[7.5,8],[5,6],[-2,1]],[[3,4],[1,2]]]}', (new Writer(new GeoJsonStrategy()))->convert($multiLine)); - static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[7.5,8],[5,6],[-2,1]],[[3,4],[1,2]]]}', (new GeoJsonStrategy())->executeStrategy($multiLine)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($multiLine); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[7.5,8],[5,6],[-2,1]],[[3,4],[1,2]]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[7.5,8],[5,6],[-2,1]],[[3,4],[1,2]]]}', (new GeoJsonStrategy())->encode($multiLine)); } /** Preserve line membership, coordinates and order without reference metadata. */ @@ -87,8 +97,10 @@ public function testOtherSrid(): void { $multiLine = new MultiLineString([new LineString([[1, 2], [3, 4]], 3857)], 3857); - static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[1,2],[3,4]]]}', (new Writer(new GeoJsonStrategy()))->convert($multiLine)); - static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[1,2],[3,4]]]}', (new GeoJsonStrategy())->executeStrategy($multiLine)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($multiLine); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[1,2],[3,4]]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[1,2],[3,4]]]}', (new GeoJsonStrategy())->encode($multiLine)); } /** Reject an incompatible line member instead of returning partial output. */ @@ -97,7 +109,7 @@ public function testRejectAllEmpty(): void $multiLine = new MultiLineString([new LineString([]), new LineString([])]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiLine); + (new Encoder(new GeoJsonStrategy()))->encode($multiLine); } /** Reject an incompatible line member instead of returning partial output. */ @@ -106,7 +118,7 @@ public function testRejectAllEmptyXyz(): void $multiLine = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\MultiLineString([[], []]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiLine); + (new Encoder(new GeoJsonStrategy()))->encode($multiLine); } /** Reject an incompatible line member instead of returning partial output. */ @@ -115,7 +127,7 @@ public function testRejectEmptyFirst(): void $multiLine = new MultiLineString([new LineString([]), new LineString([[1, 2], [3, 4]])]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiLine); + (new Encoder(new GeoJsonStrategy()))->encode($multiLine); } /** Reject an incompatible line member instead of returning partial output. */ @@ -124,7 +136,7 @@ public function testRejectEmptyLast(): void $multiLine = new MultiLineString([new LineString([[1, 2], [3, 4]]), new LineString([])]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiLine); + (new Encoder(new GeoJsonStrategy()))->encode($multiLine); } /** Reject measured dimensions even when no line members are present. */ @@ -133,7 +145,7 @@ public function testRejectEmptyXym(): void $multiLine = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\MultiLineString([]); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiLine); + (new Encoder(new GeoJsonStrategy()))->encode($multiLine); } /** Reject measured dimensions even when no line members are present. */ @@ -142,7 +154,7 @@ public function testRejectEmptyXyzm(): void $multiLine = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\MultiLineString([]); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiLine); + (new Encoder(new GeoJsonStrategy()))->encode($multiLine); } /** Reject an incompatible line member instead of returning partial output. */ @@ -151,7 +163,7 @@ public function testRejectEmptyXyzMember(): void $multiLine = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\MultiLineString([[[1, 2, 3], [4, 5, 6]], []]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiLine); + (new Encoder(new GeoJsonStrategy()))->encode($multiLine); } /** Reject an incompatible line member instead of returning partial output. */ @@ -160,7 +172,7 @@ public function testRejectSingletonMember(): void $multiLine = new MultiLineString([[[1, 2], [3, 4]], [[5, 6]]]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiLine); + (new Encoder(new GeoJsonStrategy()))->encode($multiLine); } /** Reject an incompatible line member instead of returning partial output. */ @@ -169,7 +181,7 @@ public function testRejectSingletonXyzMember(): void $multiLine = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\MultiLineString([[[1, 2, 3]]]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiLine); + (new Encoder(new GeoJsonStrategy()))->encode($multiLine); } /** Reject measured dimensions even when no line members are present. */ @@ -178,7 +190,7 @@ public function testRejectXym(): void $multiLine = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\MultiLineString([[[1, 2, 3], [4, 5, 6]]]); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiLine); + (new Encoder(new GeoJsonStrategy()))->encode($multiLine); } /** Reject measured dimensions even when no line members are present. */ @@ -187,7 +199,7 @@ public function testRejectXyzm(): void $multiLine = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\MultiLineString([[[1, 2, 3, 4], [5, 6, 7, 8]]]); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiLine); + (new Encoder(new GeoJsonStrategy()))->encode($multiLine); } /** Preserve line membership, coordinates and order without reference metadata. */ @@ -195,8 +207,10 @@ public function testSingleMember(): void { $multiLine = new MultiLineString([[[3, 4], [1, 2]]]); - static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[3,4],[1,2]]]}', (new Writer(new GeoJsonStrategy()))->convert($multiLine)); - static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[3,4],[1,2]]]}', (new GeoJsonStrategy())->executeStrategy($multiLine)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($multiLine); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[3,4],[1,2]]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[3,4],[1,2]]]}', (new GeoJsonStrategy())->encode($multiLine)); } /** Preserve line membership, coordinates and order without reference metadata. */ @@ -204,8 +218,10 @@ public function testUnknownReference(): void { $multiLine = new MultiLineString([[[1, 2], [3, 4]]], new SpatialReference(999999, 'CUSTOM')); - static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[1,2],[3,4]]]}', (new Writer(new GeoJsonStrategy()))->convert($multiLine)); - static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[1,2],[3,4]]]}', (new GeoJsonStrategy())->executeStrategy($multiLine)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($multiLine); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[1,2],[3,4]]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[1,2],[3,4]]]}', (new GeoJsonStrategy())->encode($multiLine)); } /** Preserve line membership, coordinates and order without reference metadata. */ @@ -213,8 +229,10 @@ public function testXy(): void { $multiLine = new MultiLineString([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]); - static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[1,2],[3,4]],[[5,6],[7,8]]]}', (new Writer(new GeoJsonStrategy()))->convert($multiLine)); - static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[1,2],[3,4]],[[5,6],[7,8]]]}', (new GeoJsonStrategy())->executeStrategy($multiLine)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($multiLine); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[1,2],[3,4]],[[5,6],[7,8]]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[1,2],[3,4]],[[5,6],[7,8]]]}', (new GeoJsonStrategy())->encode($multiLine)); } /** Preserve line membership, coordinates and order without reference metadata. */ @@ -222,7 +240,9 @@ public function testXyz(): void { $multiLine = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\MultiLineString([[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]); - static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]]]}', (new Writer(new GeoJsonStrategy()))->convert($multiLine)); - static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]]]}', (new GeoJsonStrategy())->executeStrategy($multiLine)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($multiLine); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]]]}', (new GeoJsonStrategy())->encode($multiLine)); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/GeographyMultiPointTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/GeographyMultiPointTest.php similarity index 69% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/GeographyMultiPointTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/GeographyMultiPointTest.php index 3685a4d..da0ecfb 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/GeographyMultiPointTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/GeographyMultiPointTest.php @@ -1,6 +1,6 @@ convert($multiPoint)); - static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[3,4,9.5],[1,2,-2],[-7,8,0]]}', (new GeoJsonStrategy())->executeStrategy($multiPoint)); + $encoded = $encoder->encode($multiPoint); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[3,4,9.5],[1,2,-2],[-7,8,0]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[3,4,9.5],[1,2,-2],[-7,8,0]]}', (new GeoJsonStrategy())->encode($multiPoint)); } /** Preserve coordinates and their order without reference metadata. */ public function testAntimeridian(): void { $multiPoint = new MultiPoint([[170, 45], [-170, 45]], 4326); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[170,45],[-170,45]]}', $writer->convert($multiPoint)); - static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[170,45],[-170,45]]}', (new GeoJsonStrategy())->executeStrategy($multiPoint)); + $encoded = $encoder->encode($multiPoint); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[170,45],[-170,45]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[170,45],[-170,45]]}', (new GeoJsonStrategy())->encode($multiPoint)); } /** Preserve coordinates and their order without reference metadata. */ public function testDeclaredEpsg(): void { $multiPoint = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\MultiPoint([[1, 2, 3], [4, 5, 6]], new SpatialReference(4326, 'EPSG')); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2,3],[4,5,6]]}', $writer->convert($multiPoint)); - static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2,3],[4,5,6]]}', (new GeoJsonStrategy())->executeStrategy($multiPoint)); + $encoded = $encoder->encode($multiPoint); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2,3],[4,5,6]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2,3],[4,5,6]]}', (new GeoJsonStrategy())->encode($multiPoint)); } /** Preserve coordinates and their order without reference metadata. */ public function testEmptyXy(): void { $multiPoint = new MultiPoint([]); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[]}', $writer->convert($multiPoint)); - static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[]}', (new GeoJsonStrategy())->executeStrategy($multiPoint)); + $encoded = $encoder->encode($multiPoint); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[]}', (new GeoJsonStrategy())->encode($multiPoint)); } /** Preserve coordinates and their order without reference metadata. */ public function testEmptyXyz(): void { $multiPoint = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\MultiPoint([]); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[]}', $writer->convert($multiPoint)); - static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[]}', (new GeoJsonStrategy())->executeStrategy($multiPoint)); + $encoded = $encoder->encode($multiPoint); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[]}', (new GeoJsonStrategy())->encode($multiPoint)); } /** Preserve coordinates and their order without reference metadata. */ public function testOtherSrid(): void { $multiPoint = new MultiPoint([[1, 2], [3, 4]], 3857); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2],[3,4]]}', $writer->convert($multiPoint)); - static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2],[3,4]]}', (new GeoJsonStrategy())->executeStrategy($multiPoint)); + $encoded = $encoder->encode($multiPoint); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2],[3,4]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2],[3,4]]}', (new GeoJsonStrategy())->encode($multiPoint)); } /** Reject an incompatible concrete input without modifying it. */ @@ -102,7 +114,7 @@ public function testRejectEmptyXym(): void { $multiPoint = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\MultiPoint([]); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiPoint); + (new Encoder(new GeoJsonStrategy()))->encode($multiPoint); } /** Reject an incompatible concrete input without modifying it. */ @@ -110,7 +122,7 @@ public function testRejectEmptyXyzm(): void { $multiPoint = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\MultiPoint([]); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiPoint); + (new Encoder(new GeoJsonStrategy()))->encode($multiPoint); } /** Reject an EMPTY member after a non-empty position without returning partial output. */ @@ -118,7 +130,7 @@ public function testRejectMixedEmptyMembersXy(): void { $multiPoint = new MultiPoint([new Point(1, 2), new Point()]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiPoint); + (new Encoder(new GeoJsonStrategy()))->encode($multiPoint); } /** Reject an EMPTY member after a non-empty position without returning partial output. */ @@ -126,7 +138,7 @@ public function testRejectMixedEmptyMembersXyz(): void { $multiPoint = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\MultiPoint([new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\Point(1, 2, 3), new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\Point()]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiPoint); + (new Encoder(new GeoJsonStrategy()))->encode($multiPoint); } /** Distinguish an aggregate containing only EMPTY members from one with no members. */ @@ -134,7 +146,7 @@ public function testRejectOnlyEmptyMembersXy(): void { $multiPoint = new MultiPoint([new Point(), new Point()]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiPoint); + (new Encoder(new GeoJsonStrategy()))->encode($multiPoint); } /** Distinguish an aggregate containing only EMPTY members from one with no members. */ @@ -142,7 +154,7 @@ public function testRejectOnlyEmptyMembersXyz(): void { $multiPoint = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\MultiPoint([new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\Point(), new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\Point()]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiPoint); + (new Encoder(new GeoJsonStrategy()))->encode($multiPoint); } /** Reject an incompatible concrete input without modifying it. */ @@ -150,7 +162,7 @@ public function testRejectXym(): void { $multiPoint = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\MultiPoint([[1, 2, 3], [4, 5, 6]]); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiPoint); + (new Encoder(new GeoJsonStrategy()))->encode($multiPoint); } /** Reject an incompatible concrete input without modifying it. */ @@ -158,60 +170,72 @@ public function testRejectXyzm(): void { $multiPoint = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\MultiPoint([[1, 2, 3, 4], [5, 6, 7, 8]]); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiPoint); + (new Encoder(new GeoJsonStrategy()))->encode($multiPoint); } /** Preserve coordinates and their order without reference metadata. */ public function testRepeatedPositions(): void { $multiPoint = new MultiPoint([[3.5, 4.25], [1, 2], [3.5, 4.25]]); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[3.5,4.25],[1,2],[3.5,4.25]]}', $writer->convert($multiPoint)); - static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[3.5,4.25],[1,2],[3.5,4.25]]}', (new GeoJsonStrategy())->executeStrategy($multiPoint)); + $encoded = $encoder->encode($multiPoint); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[3.5,4.25],[1,2],[3.5,4.25]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[3.5,4.25],[1,2],[3.5,4.25]]}', (new GeoJsonStrategy())->encode($multiPoint)); } /** Preserve a singleton as a MultiPoint. */ public function testSingletonXy(): void { $multiPoint = new MultiPoint([[1, 2]]); - static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2]]}', (new Writer(new GeoJsonStrategy()))->convert($multiPoint)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($multiPoint); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2]]}', $encoded); } /** Preserve a singleton as a MultiPoint. */ public function testSingletonXyz(): void { $multiPoint = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\MultiPoint([[1, 2, 3]]); - static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2,3]]}', (new Writer(new GeoJsonStrategy()))->convert($multiPoint)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($multiPoint); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2,3]]}', $encoded); } /** Preserve coordinates and their order without reference metadata. */ public function testUnknownReference(): void { $multiPoint = new MultiPoint([[1, 2], [3, 4]], new SpatialReference(999999, 'CUSTOM')); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2],[3,4]]}', $writer->convert($multiPoint)); - static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2],[3,4]]}', (new GeoJsonStrategy())->executeStrategy($multiPoint)); + $encoded = $encoder->encode($multiPoint); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2],[3,4]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2],[3,4]]}', (new GeoJsonStrategy())->encode($multiPoint)); } /** Preserve coordinates and their order without reference metadata. */ public function testXy(): void { $multiPoint = new MultiPoint([[1, 2], [3, 4]]); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2],[3,4]]}', $writer->convert($multiPoint)); - static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2],[3,4]]}', (new GeoJsonStrategy())->executeStrategy($multiPoint)); + $encoded = $encoder->encode($multiPoint); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2],[3,4]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2],[3,4]]}', (new GeoJsonStrategy())->encode($multiPoint)); } /** Preserve coordinates and their order without reference metadata. */ public function testXyz(): void { $multiPoint = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\MultiPoint([[1, 2, 3], [4, 5, 6]]); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2,3],[4,5,6]]}', $writer->convert($multiPoint)); - static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2,3],[4,5,6]]}', (new GeoJsonStrategy())->executeStrategy($multiPoint)); + $encoded = $encoder->encode($multiPoint); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2,3],[4,5,6]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2,3],[4,5,6]]}', (new GeoJsonStrategy())->encode($multiPoint)); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/GeographyMultiPolygonTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/GeographyMultiPolygonTest.php similarity index 73% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/GeographyMultiPolygonTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/GeographyMultiPolygonTest.php index 7aa11cd..1bc4d20 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/GeographyMultiPolygonTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/GeographyMultiPolygonTest.php @@ -1,6 +1,6 @@ convert($multiPolygon)); - static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[[[[170,40],[170,50],[-170,50],[-170,40],[170,40]]]]}', (new GeoJsonStrategy())->executeStrategy($multiPolygon)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($multiPolygon); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[[[[170,40],[170,50],[-170,50],[-170,40],[170,40]]]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[[[[170,40],[170,50],[-170,50],[-170,40],[170,40]]]]}', (new GeoJsonStrategy())->encode($multiPolygon)); } /** An aggregate without members is supported. */ @@ -51,8 +53,10 @@ public function testEmptyXy(): void { $multiPolygon = new MultiPolygon([]); - static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[]}', (new Writer(new GeoJsonStrategy()))->convert($multiPolygon)); - static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[]}', (new GeoJsonStrategy())->executeStrategy($multiPolygon)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($multiPolygon); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[]}', (new GeoJsonStrategy())->encode($multiPolygon)); } /** An empty XYZ aggregate has no dimension marker. */ @@ -60,8 +64,10 @@ public function testEmptyXyz(): void { $multiPolygon = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\MultiPolygon([]); - static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[]}', (new Writer(new GeoJsonStrategy()))->convert($multiPolygon)); - static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[]}', (new GeoJsonStrategy())->executeStrategy($multiPolygon)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($multiPolygon); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[]}', (new GeoJsonStrategy())->encode($multiPolygon)); } /** Reject the whole aggregate through the approved structural contract. */ @@ -70,7 +76,7 @@ public function testRejectClockwiseLaterExterior(): void $multiPolygon = new MultiPolygon([[[[0, 0], [2, 0], [0, 2], [0, 0]]], [[[3, 0], [3, 2], [5, 0], [3, 0]]]]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiPolygon); + (new Encoder(new GeoJsonStrategy()))->encode($multiPolygon); } /** Reject the whole aggregate through the approved structural contract. */ @@ -79,7 +85,7 @@ public function testRejectCounterclockwiseLaterHole(): void $multiPolygon = new MultiPolygon([[[[10, 0], [12, 0], [10, 2], [10, 0]]], [[[0, 0], [4, 0], [4, 4], [0, 4], [0, 0]], [[1, 1], [2, 1], [2, 2], [1, 2], [1, 1]]]]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiPolygon); + (new Encoder(new GeoJsonStrategy()))->encode($multiPolygon); } /** Reject the whole aggregate through the approved structural contract. */ @@ -88,7 +94,7 @@ public function testRejectEmptyMember(): void $multiPolygon = new MultiPolygon([new Polygon([[[0, 0], [2, 0], [0, 2], [0, 0]]]), new Polygon([])]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiPolygon); + (new Encoder(new GeoJsonStrategy()))->encode($multiPolygon); } /** Reject measured dimensions without discarding M. */ @@ -97,7 +103,7 @@ public function testRejectEmptyXym(): void $multiPolygon = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\MultiPolygon([]); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiPolygon); + (new Encoder(new GeoJsonStrategy()))->encode($multiPolygon); } /** Reject measured dimensions without discarding M. */ @@ -106,7 +112,7 @@ public function testRejectEmptyXyzm(): void $multiPolygon = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\MultiPolygon([]); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiPolygon); + (new Encoder(new GeoJsonStrategy()))->encode($multiPolygon); } /** Reject the whole aggregate through the approved structural contract. */ @@ -115,7 +121,7 @@ public function testRejectOnlyEmptyMembers(): void $multiPolygon = new MultiPolygon([new Polygon([]), new Polygon([])]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiPolygon); + (new Encoder(new GeoJsonStrategy()))->encode($multiPolygon); } /** Reject measured dimensions without discarding M. */ @@ -124,7 +130,7 @@ public function testRejectXym(): void $multiPolygon = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\MultiPolygon([[[[0, 0, 3], [2, 0, 3], [0, 2, 3], [0, 0, 3]]]]); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiPolygon); + (new Encoder(new GeoJsonStrategy()))->encode($multiPolygon); } /** Reject measured dimensions without discarding M. */ @@ -133,7 +139,7 @@ public function testRejectXyzm(): void $multiPolygon = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\MultiPolygon([[[[0, 0, 3, 4], [2, 0, 3, 4], [0, 2, 3, 4], [0, 0, 3, 4]]]]); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiPolygon); + (new Encoder(new GeoJsonStrategy()))->encode($multiPolygon); } /** Reject the whole aggregate through the approved structural contract. */ @@ -142,7 +148,7 @@ public function testRejectZeroAreaExterior(): void $multiPolygon = new MultiPolygon([[[[0, 0], [1, 0], [2, 0], [0, 0]]]]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiPolygon); + (new Encoder(new GeoJsonStrategy()))->encode($multiPolygon); } /** Preserve multiple holes, member order and decimal coordinates. */ @@ -150,8 +156,10 @@ public function testRingOrder(): void { $multiPolygon = new MultiPolygon([[[[0, 0], [8, 0], [8, 8], [0, 8], [0, 0]], [[1, 1], [1, 2], [2, 2], [2, 1], [1, 1]], [[4, 4], [4, 5], [5, 5], [5, 4], [4, 4]]], [[[10.5, 0], [12, 0], [10.5, 2], [10.5, 0]]]]); - static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[[[[0,0],[8,0],[8,8],[0,8],[0,0]],[[1,1],[1,2],[2,2],[2,1],[1,1]],[[4,4],[4,5],[5,5],[5,4],[4,4]]],[[[10.5,0],[12,0],[10.5,2],[10.5,0]]]]}', (new Writer(new GeoJsonStrategy()))->convert($multiPolygon)); - static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[[[[0,0],[8,0],[8,8],[0,8],[0,0]],[[1,1],[1,2],[2,2],[2,1],[1,1]],[[4,4],[4,5],[5,5],[5,4],[4,4]]],[[[10.5,0],[12,0],[10.5,2],[10.5,0]]]]}', (new GeoJsonStrategy())->executeStrategy($multiPolygon)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($multiPolygon); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[[[[0,0],[8,0],[8,8],[0,8],[0,0]],[[1,1],[1,2],[2,2],[2,1],[1,1]],[[4,4],[4,5],[5,5],[5,4],[4,4]]],[[[10.5,0],[12,0],[10.5,2],[10.5,0]]]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[[[[0,0],[8,0],[8,8],[0,8],[0,0]],[[1,1],[1,2],[2,2],[2,1],[1,1]],[[4,4],[4,5],[5,5],[5,4],[4,4]]],[[[10.5,0],[12,0],[10.5,2],[10.5,0]]]]}', (new GeoJsonStrategy())->encode($multiPolygon)); } /** Preserve member and position order with SRID omitted. */ @@ -159,8 +167,10 @@ public function testXy(): void { $multiPolygon = new MultiPolygon([[[[0, 0], [2, 0], [0, 2], [0, 0]]], [[[3, 0], [5, 0], [3, 2], [3, 0]]]], 4326); - static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[[[[0,0],[2,0],[0,2],[0,0]]],[[[3,0],[5,0],[3,2],[3,0]]]]}', (new Writer(new GeoJsonStrategy()))->convert($multiPolygon)); - static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[[[[0,0],[2,0],[0,2],[0,0]]],[[[3,0],[5,0],[3,2],[3,0]]]]}', (new GeoJsonStrategy())->executeStrategy($multiPolygon)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($multiPolygon); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[[[[0,0],[2,0],[0,2],[0,0]]],[[[3,0],[5,0],[3,2],[3,0]]]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[[[[0,0],[2,0],[0,2],[0,0]]],[[[3,0],[5,0],[3,2],[3,0]]]]}', (new GeoJsonStrategy())->encode($multiPolygon)); } /** Keep the singleton wrapper, Z and coordinates without reference metadata. */ @@ -168,7 +178,9 @@ public function testXyz(): void { $multiPolygon = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\MultiPolygon([[[[0, 0, 3], [2, 0, 3], [0, 2, 3], [0, 0, 3]]]], new SpatialReference(999999, 'CUSTOM')); - static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[[[[0,0,3],[2,0,3],[0,2,3],[0,0,3]]]]}', (new Writer(new GeoJsonStrategy()))->convert($multiPolygon)); - static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[[[[0,0,3],[2,0,3],[0,2,3],[0,0,3]]]]}', (new GeoJsonStrategy())->executeStrategy($multiPolygon)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($multiPolygon); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[[[[0,0,3],[2,0,3],[0,2,3],[0,0,3]]]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[[[[0,0,3],[2,0,3],[0,2,3],[0,0,3]]]]}', (new GeoJsonStrategy())->encode($multiPolygon)); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/GeographyPointTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/GeographyPointTest.php similarity index 62% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/GeographyPointTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/GeographyPointTest.php index 99e24c0..36aabea 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/GeographyPointTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/GeographyPointTest.php @@ -1,6 +1,6 @@ convert($point)); - static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[]}', (new GeoJsonStrategy())->executeStrategy($point)); + $encoded = $encoder->encode($point); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[]}', (new GeoJsonStrategy())->encode($point)); } /** Preserve the supplied point coordinates without reference metadata. */ public function testEmptyXyz(): void { $point = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\Point(); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[]}', $writer->convert($point)); - static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[]}', (new GeoJsonStrategy())->executeStrategy($point)); + $encoded = $encoder->encode($point); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[]}', (new GeoJsonStrategy())->encode($point)); } /** Preserve the supplied point coordinates without reference metadata. */ public function testEpsg(): void { $point = new Point(1, 2, new SpatialReference(4326, 'EPSG')); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2]}', $writer->convert($point)); - static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2]}', (new GeoJsonStrategy())->executeStrategy($point)); + $encoded = $encoder->encode($point); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2]}', (new GeoJsonStrategy())->encode($point)); } /** Preserve the supplied point coordinates without reference metadata. */ public function testFractionalCoordinates(): void { $point = new Point(2.35, 48.86, 4326); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[2.35,48.86]}', $writer->convert($point)); - static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[2.35,48.86]}', (new GeoJsonStrategy())->executeStrategy($point)); + $encoded = $encoder->encode($point); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[2.35,48.86]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[2.35,48.86]}', (new GeoJsonStrategy())->encode($point)); } /** Preserve the supplied point coordinates without reference metadata. */ public function testOtherSrid(): void { $point = new Point(1, 2, 3857); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2]}', $writer->convert($point)); - static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2]}', (new GeoJsonStrategy())->executeStrategy($point)); + $encoded = $encoder->encode($point); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2]}', (new GeoJsonStrategy())->encode($point)); } /** Reject measured points without dropping or reinterpreting M. */ @@ -92,7 +102,7 @@ public function testRejectEmptyXym(): void { $point = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\Point(); $this->expectException(UnsupportedDimensionException::class); - (new GeoJsonStrategy())->executeStrategy($point); + (new GeoJsonStrategy())->encode($point); } /** Reject measured points without dropping or reinterpreting M. */ @@ -100,15 +110,15 @@ public function testRejectEmptyXyzm(): void { $point = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\Point(); $this->expectException(UnsupportedDimensionException::class); - (new GeoJsonStrategy())->executeStrategy($point); + (new GeoJsonStrategy())->encode($point); } - /** Do not convert a recognized non-GeoJSON type to another geometry. */ + /** Do not encode a recognized non-GeoJSON type to another geometry. */ public function testRejectTriangle(): void { $triangle = new Triangle([]); $this->expectException(UnsupportedSpatialTypeException::class); - (new GeoJsonStrategy())->executeStrategy($triangle); + (new GeoJsonStrategy())->encode($triangle); } /** Reject measured points without dropping or reinterpreting M. */ @@ -116,7 +126,7 @@ public function testRejectXym(): void { $point = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\Point(1, 2, 4); $this->expectException(UnsupportedDimensionException::class); - (new GeoJsonStrategy())->executeStrategy($point); + (new GeoJsonStrategy())->encode($point); } /** Reject measured points without dropping or reinterpreting M. */ @@ -124,46 +134,54 @@ public function testRejectXyzm(): void { $point = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\Point(1, 2, 3, 4); $this->expectException(UnsupportedDimensionException::class); - (new GeoJsonStrategy())->executeStrategy($point); + (new GeoJsonStrategy())->encode($point); } /** Preserve the supplied point coordinates without reference metadata. */ public function testUnknownReference(): void { $point = new Point(1, 2, new SpatialReference(999999, 'CUSTOM')); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2]}', $writer->convert($point)); - static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2]}', (new GeoJsonStrategy())->executeStrategy($point)); + $encoded = $encoder->encode($point); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2]}', (new GeoJsonStrategy())->encode($point)); } /** Preserve the supplied point coordinates without reference metadata. */ public function testXy(): void { $point = new Point(1, 2); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2]}', $writer->convert($point)); - static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2]}', (new GeoJsonStrategy())->executeStrategy($point)); + $encoded = $encoder->encode($point); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2]}', (new GeoJsonStrategy())->encode($point)); } /** Preserve the supplied point coordinates without reference metadata. */ public function testXyz(): void { $point = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\Point(1, 2, 3); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2,3]}', $writer->convert($point)); - static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2,3]}', (new GeoJsonStrategy())->executeStrategy($point)); + $encoded = $encoder->encode($point); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2,3]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2,3]}', (new GeoJsonStrategy())->encode($point)); } /** Preserve the supplied point coordinates without reference metadata. */ public function testZeroSrid(): void { $point = new Point(1, 2, 0); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2]}', $writer->convert($point)); - static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2]}', (new GeoJsonStrategy())->executeStrategy($point)); + $encoded = $encoder->encode($point); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2]}', (new GeoJsonStrategy())->encode($point)); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/GeographyPolygonTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/GeographyPolygonTest.php similarity index 74% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/GeographyPolygonTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/GeographyPolygonTest.php index 190bb02..7802862 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/GeographyPolygonTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/GeographyPolygonTest.php @@ -1,6 +1,6 @@ convert($polygon)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($polygon); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"Polygon","coordinates":[[[170,40],[170,50],[-170,50],[-170,40],[170,40]]]}', $encoded); } /** Reject clockwise exteriors without reversing the source ring. */ @@ -50,7 +52,7 @@ public function testClockwiseExterior(): void $polygon = new Polygon([[[0, 0], [0, 2], [2, 0], [0, 0]]]); try { - (new Writer(new GeoJsonStrategy()))->convert($polygon); + (new Encoder(new GeoJsonStrategy()))->encode($polygon); static::fail('Clockwise exterior must be rejected.'); } catch (UnsupportedGeometryStructureException) { static::assertSame([[[0, 0], [0, 2], [2, 0], [0, 0]]], $polygon->toArray()); @@ -63,7 +65,7 @@ public function testCounterclockwiseHole(): void $polygon = new Polygon([[[0, 0], [4, 0], [4, 4], [0, 4], [0, 0]], [[1, 1], [2, 1], [2, 2], [1, 2], [1, 1]]]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($polygon); + (new Encoder(new GeoJsonStrategy()))->encode($polygon); } /** A positive signed area does not claim or require ring simplicity. */ @@ -71,7 +73,9 @@ public function testCrossedRingWithPositiveArea(): void { $polygon = new Polygon([[[0, 0], [3, 3], [0, 3], [2, 0], [0, 0]]]); - static::assertJsonStringEqualsJsonString('{"type":"Polygon","coordinates":[[[0,0],[3,3],[0,3],[2,0],[0,0]]]}', (new Writer(new GeoJsonStrategy()))->convert($polygon)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($polygon); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"Polygon","coordinates":[[[0,0],[3,3],[0,3],[2,0],[0,0]]]}', $encoded); } /** EMPTY is an empty coordinates array. */ @@ -79,7 +83,9 @@ public function testEmptyXy(): void { $polygon = new Polygon([]); - static::assertJsonStringEqualsJsonString('{"type":"Polygon","coordinates":[]}', (new Writer(new GeoJsonStrategy()))->convert($polygon)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($polygon); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"Polygon","coordinates":[]}', $encoded); } /** EMPTY has no artificial dimension marker. */ @@ -87,7 +93,9 @@ public function testEmptyXyz(): void { $polygon = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\Polygon([]); - static::assertJsonStringEqualsJsonString('{"type":"Polygon","coordinates":[]}', (new Writer(new GeoJsonStrategy()))->convert($polygon)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($polygon); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"Polygon","coordinates":[]}', $encoded); } /** Preserve exterior and interior ring order and winding. */ @@ -95,7 +103,9 @@ public function testHole(): void { $polygon = new Polygon([[[0, 0], [4, 0], [4, 4], [0, 4], [0, 0]], [[1, 1], [1, 2], [2, 2], [2, 1], [1, 1]]]); - static::assertJsonStringEqualsJsonString('{"type":"Polygon","coordinates":[[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[1,2],[2,2],[2,1],[1,1]]]}', (new Writer(new GeoJsonStrategy()))->convert($polygon)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($polygon); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"Polygon","coordinates":[[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[1,2],[2,2],[2,1],[1,1]]]}', $encoded); } /** Reject measured dimensions even when EMPTY. */ @@ -104,7 +114,7 @@ public function testRejectEmptyXym(): void $polygon = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\Polygon([]); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($polygon); + (new Encoder(new GeoJsonStrategy()))->encode($polygon); } /** Reject measured dimensions even when EMPTY. */ @@ -113,7 +123,7 @@ public function testRejectEmptyXyzm(): void $polygon = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\Polygon([]); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($polygon); + (new Encoder(new GeoJsonStrategy()))->encode($polygon); } /** A later hole must also be checked before returning any output. */ @@ -126,7 +136,7 @@ public function testRejectLaterCounterclockwiseHole(): void ]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($polygon); + (new Encoder(new GeoJsonStrategy()))->encode($polygon); } /** M must not be serialized as altitude. */ @@ -135,7 +145,7 @@ public function testRejectXym(): void $polygon = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\Polygon([[[0, 0, 3], [2, 0, 3], [0, 2, 3], [0, 0, 3]]]); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($polygon); + (new Encoder(new GeoJsonStrategy()))->encode($polygon); } /** M must not be discarded. */ @@ -144,7 +154,7 @@ public function testRejectXyzm(): void $polygon = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\Polygon([[[0, 0, 3, 4], [2, 0, 3, 4], [0, 2, 3, 4], [0, 0, 3, 4]]]); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($polygon); + (new Encoder(new GeoJsonStrategy()))->encode($polygon); } /** The bow-tie is rejected for zero signed area, without topology analysis. */ @@ -153,7 +163,7 @@ public function testRejectZeroAreaCrossedRing(): void $polygon = new Polygon([[[0, 0], [2, 2], [0, 2], [2, 0], [0, 0]]]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($polygon); + (new Encoder(new GeoJsonStrategy()))->encode($polygon); } /** Collinear rings have no winding and are rejected by the approved policy. */ @@ -162,7 +172,7 @@ public function testRejectZeroAreaExterior(): void $polygon = new Polygon([[[0, 0], [1, 0], [2, 0], [0, 0]]]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($polygon); + (new Encoder(new GeoJsonStrategy()))->encode($polygon); } /** The orientation policy applies to every interior ring as well. */ @@ -171,7 +181,7 @@ public function testRejectZeroAreaHole(): void $polygon = new Polygon([[[0, 0], [4, 0], [4, 4], [0, 4], [0, 0]], [[1, 1], [2, 1], [3, 1], [1, 1]]]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($polygon); + (new Encoder(new GeoJsonStrategy()))->encode($polygon); } /** Varying height does not change the XY winding or position order. */ @@ -183,7 +193,9 @@ public function testVaryingAltitudeAndMultipleHoles(): void [[4, 4, 9], [4, 5, 10], [5, 5, 11], [5, 4, 12], [4, 4, 9]], ]); - static::assertJsonStringEqualsJsonString('{"type":"Polygon","coordinates":[[[0,0,1],[8,0,2],[8,8,3],[0,8,4],[0,0,1]],[[1,1,5],[1,2,6],[2,2,7],[2,1,8],[1,1,5]],[[4,4,9],[4,5,10],[5,5,11],[5,4,12],[4,4,9]]]}', (new Writer(new GeoJsonStrategy()))->convert($polygon)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($polygon); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"Polygon","coordinates":[[[0,0,1],[8,0,2],[8,8,3],[0,8,4],[0,0,1]],[[1,1,5],[1,2,6],[2,2,7],[2,1,8],[1,1,5]],[[4,4,9],[4,5,10],[5,5,11],[5,4,12],[4,4,9]]]}', $encoded); } /** Preserve the exterior ring and the original object. */ @@ -191,7 +203,9 @@ public function testXy(): void { $polygon = new Polygon([[[0, 0], [2, 0], [0, 2], [0, 0]]], 4326); - static::assertJsonStringEqualsJsonString('{"type":"Polygon","coordinates":[[[0,0],[2,0],[0,2],[0,0]]]}', (new Writer(new GeoJsonStrategy()))->convert($polygon)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($polygon); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"Polygon","coordinates":[[[0,0],[2,0],[0,2],[0,0]]]}', $encoded); static::assertSame([[[0, 0], [2, 0], [0, 2], [0, 0]]], $polygon->toArray()); } @@ -200,6 +214,8 @@ public function testXyz(): void { $polygon = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\Polygon([[[0, 0, 3], [2, 0, 3], [0, 2, 3], [0, 0, 3]]], new SpatialReference(999999, 'CUSTOM')); - static::assertJsonStringEqualsJsonString('{"type":"Polygon","coordinates":[[[0,0,3],[2,0,3],[0,2,3],[0,0,3]]]}', (new Writer(new GeoJsonStrategy()))->convert($polygon)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($polygon); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"Polygon","coordinates":[[[0,0,3],[2,0,3],[0,2,3],[0,0,3]]]}', $encoded); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/GeometryCollectionTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/GeometryCollectionTest.php similarity index 75% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/GeometryCollectionTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/GeometryCollectionTest.php index 3238d14..700ee0d 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/GeometryCollectionTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/GeometryCollectionTest.php @@ -1,6 +1,6 @@ convert($collection)); - static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[1,2]},{"type":"LineString","coordinates":[[3,4],[5,6]]},{"type":"MultiPoint","coordinates":[[7,8],[9,10]]},{"type":"MultiLineString","coordinates":[[[11,12],[13,14]]]},{"type":"Polygon","coordinates":[[[0,0],[2,0],[0,2],[0,0]]]},{"type":"MultiPolygon","coordinates":[[[[3,0],[5,0],[3,2],[3,0]]]]}]}', (new GeoJsonStrategy())->executeStrategy($collection)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($collection); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[1,2]},{"type":"LineString","coordinates":[[3,4],[5,6]]},{"type":"MultiPoint","coordinates":[[7,8],[9,10]]},{"type":"MultiLineString","coordinates":[[[11,12],[13,14]]]},{"type":"Polygon","coordinates":[[[0,0],[2,0],[0,2],[0,0]]]},{"type":"MultiPolygon","coordinates":[[[[3,0],[5,0],[3,2],[3,0]]]]}]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[1,2]},{"type":"LineString","coordinates":[[3,4],[5,6]]},{"type":"MultiPoint","coordinates":[[7,8],[9,10]]},{"type":"MultiLineString","coordinates":[[[11,12],[13,14]]]},{"type":"Polygon","coordinates":[[[0,0],[2,0],[0,2],[0,0]]]},{"type":"MultiPolygon","coordinates":[[[[3,0],[5,0],[3,2],[3,0]]]]}]}', (new GeoJsonStrategy())->encode($collection)); } /** Preserve the complete collection structure and values. */ @@ -58,8 +60,10 @@ public function testAntimeridian(): void { $collection = new GeometryCollection(0, [new LineString([[170, 45], [-170, 45]])]); - static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"LineString","coordinates":[[170,45],[-170,45]]}]}', (new Writer(new GeoJsonStrategy()))->convert($collection)); - static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"LineString","coordinates":[[170,45],[-170,45]]}]}', (new GeoJsonStrategy())->executeStrategy($collection)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($collection); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"LineString","coordinates":[[170,45],[-170,45]]}]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"LineString","coordinates":[[170,45],[-170,45]]}]}', (new GeoJsonStrategy())->encode($collection)); } /** Preserve the complete collection structure and values. */ @@ -67,8 +71,10 @@ public function testEmptyXy(): void { $collection = new GeometryCollection(0, []); - static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[]}', (new Writer(new GeoJsonStrategy()))->convert($collection)); - static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[]}', (new GeoJsonStrategy())->executeStrategy($collection)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($collection); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[]}', (new GeoJsonStrategy())->encode($collection)); } /** Preserve the complete collection structure and values. */ @@ -76,8 +82,10 @@ public function testEmptyXyz(): void { $collection = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\GeometryCollection(0, []); - static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[]}', (new Writer(new GeoJsonStrategy()))->convert($collection)); - static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[]}', (new GeoJsonStrategy())->executeStrategy($collection)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($collection); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[]}', (new GeoJsonStrategy())->encode($collection)); } /** Preserve the complete collection structure and values. */ @@ -85,8 +93,10 @@ public function testHomogeneous(): void { $collection = new GeometryCollection(0, [new Point(3, 4), new Point(1, 2), new Point(3, 4)]); - static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[3,4]},{"type":"Point","coordinates":[1,2]},{"type":"Point","coordinates":[3,4]}]}', (new Writer(new GeoJsonStrategy()))->convert($collection)); - static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[3,4]},{"type":"Point","coordinates":[1,2]},{"type":"Point","coordinates":[3,4]}]}', (new GeoJsonStrategy())->executeStrategy($collection)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($collection); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[3,4]},{"type":"Point","coordinates":[1,2]},{"type":"Point","coordinates":[3,4]}]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[3,4]},{"type":"Point","coordinates":[1,2]},{"type":"Point","coordinates":[3,4]}]}', (new GeoJsonStrategy())->encode($collection)); } /** Preserve the complete collection structure and values. */ @@ -94,8 +104,10 @@ public function testNestedEmpty(): void { $collection = new GeometryCollection(0, [new GeometryCollection(0, [new Point()]), new GeometryCollection(0, [])]); - static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[]}]},{"type":"GeometryCollection","geometries":[]}]}', (new Writer(new GeoJsonStrategy()))->convert($collection)); - static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[]}]},{"type":"GeometryCollection","geometries":[]}]}', (new GeoJsonStrategy())->executeStrategy($collection)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($collection); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[]}]},{"type":"GeometryCollection","geometries":[]}]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[]}]},{"type":"GeometryCollection","geometries":[]}]}', (new GeoJsonStrategy())->encode($collection)); } /** Propagate failure without returning a partial collection. */ @@ -104,7 +116,7 @@ public function testRejectClockwisePolygon(): void $collection = new GeometryCollection(0, [new Point(1, 2), new Polygon([[[0, 0], [0, 2], [2, 0], [0, 0]]])]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($collection); + (new Encoder(new GeoJsonStrategy()))->encode($collection); } /** Propagate failure without returning a partial collection. */ @@ -113,7 +125,7 @@ public function testRejectDimension3m(): void $collection = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\GeometryCollection(0, [new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\Point(1, 2, 3)]); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($collection); + (new Encoder(new GeoJsonStrategy()))->encode($collection); } /** Propagate failure without returning a partial collection. */ @@ -122,7 +134,7 @@ public function testRejectDimension4zm(): void $collection = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\GeometryCollection(0, [new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\Point(1, 2, 3, 4)]); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($collection); + (new Encoder(new GeoJsonStrategy()))->encode($collection); } /** Propagate failure without returning a partial collection. */ @@ -131,7 +143,7 @@ public function testRejectEmptyDimension3m(): void $collection = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\GeometryCollection(0, []); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($collection); + (new Encoder(new GeoJsonStrategy()))->encode($collection); } /** Propagate failure without returning a partial collection. */ @@ -140,7 +152,7 @@ public function testRejectEmptyDimension4zm(): void $collection = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\GeometryCollection(0, []); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($collection); + (new Encoder(new GeoJsonStrategy()))->encode($collection); } /** Propagate failure without returning a partial collection. */ @@ -149,7 +161,7 @@ public function testRejectEmptyMultiPointMember(): void $collection = new GeometryCollection(0, [new Point(1, 2), new MultiPoint([new Point()])]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($collection); + (new Encoder(new GeoJsonStrategy()))->encode($collection); } /** Propagate failure without returning a partial collection. */ @@ -158,7 +170,7 @@ public function testRejectNestedSingletonLine(): void $collection = new GeometryCollection(0, [new Point(1, 2), new GeometryCollection(0, [new LineString([[3, 4]])])]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($collection); + (new Encoder(new GeoJsonStrategy()))->encode($collection); } /** Propagate failure without returning a partial collection. */ @@ -167,7 +179,7 @@ public function testRejectNestedTriangle(): void $collection = new GeometryCollection(0, [new Point(1, 2), new GeometryCollection(0, [new Triangle([[[0, 0], [2, 0], [0, 2], [0, 0]]])])]); $this->expectException(UnsupportedSpatialTypeException::class); - (new Writer(new GeoJsonStrategy()))->convert($collection); + (new Encoder(new GeoJsonStrategy()))->encode($collection); } /** Preserve the complete collection structure and values. */ @@ -175,8 +187,10 @@ public function testXy(): void { $collection = new GeometryCollection(4326, [new Point(1, 2, 4326), new LineString([[3, 4], [5, 6]], 4326)]); - static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[1,2]},{"type":"LineString","coordinates":[[3,4],[5,6]]}]}', (new Writer(new GeoJsonStrategy()))->convert($collection)); - static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[1,2]},{"type":"LineString","coordinates":[[3,4],[5,6]]}]}', (new GeoJsonStrategy())->executeStrategy($collection)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($collection); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[1,2]},{"type":"LineString","coordinates":[[3,4],[5,6]]}]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[1,2]},{"type":"LineString","coordinates":[[3,4],[5,6]]}]}', (new GeoJsonStrategy())->encode($collection)); } /** Preserve the complete collection structure and values. */ @@ -184,7 +198,9 @@ public function testXyzSingleton(): void { $collection = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\GeometryCollection(new SpatialReference(999999, 'CUSTOM'), [new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\Point(1, 2, 3, new SpatialReference(999999, 'CUSTOM'))]); - static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[1,2,3]}]}', (new Writer(new GeoJsonStrategy()))->convert($collection)); - static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[1,2,3]}]}', (new GeoJsonStrategy())->executeStrategy($collection)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($collection); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[1,2,3]}]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[1,2,3]}]}', (new GeoJsonStrategy())->encode($collection)); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/GeometryLineStringTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/GeometryLineStringTest.php similarity index 68% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/GeometryLineStringTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/GeometryLineStringTest.php index 49390b5..3a2c4ee 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/GeometryLineStringTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/GeometryLineStringTest.php @@ -1,6 +1,6 @@ convert($line)); - static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[3.5,4.25],[1,2],[-7,8]]}', (new GeoJsonStrategy())->executeStrategy($line)); + $encoded = $encoder->encode($line); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[3.5,4.25],[1,2],[-7,8]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[3.5,4.25],[1,2],[-7,8]]}', (new GeoJsonStrategy())->encode($line)); } /** Preserve coordinates and their order without reference metadata. */ public function testAdditionalXyzPositions(): void { $line = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\LineString([[3, 4, 9.5], [1, 2, -2], [-7, 8, 0]]); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[3,4,9.5],[1,2,-2],[-7,8,0]]}', $writer->convert($line)); - static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[3,4,9.5],[1,2,-2],[-7,8,0]]}', (new GeoJsonStrategy())->executeStrategy($line)); + $encoded = $encoder->encode($line); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[3,4,9.5],[1,2,-2],[-7,8,0]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[3,4,9.5],[1,2,-2],[-7,8,0]]}', (new GeoJsonStrategy())->encode($line)); } /** Preserve coordinates and their order without reference metadata. */ public function testAntimeridian(): void { $line = new LineString([[170, 45], [-170, 45]], 4326); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[170,45],[-170,45]]}', $writer->convert($line)); - static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[170,45],[-170,45]]}', (new GeoJsonStrategy())->executeStrategy($line)); + $encoded = $encoder->encode($line); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[170,45],[-170,45]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[170,45],[-170,45]]}', (new GeoJsonStrategy())->encode($line)); } /** Preserve coordinates and their order without reference metadata. */ public function testDeclaredEpsg(): void { $line = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\LineString([[1, 2, 3], [4, 5, 6]], new SpatialReference(4326, 'EPSG')); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[1,2,3],[4,5,6]]}', $writer->convert($line)); - static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[1,2,3],[4,5,6]]}', (new GeoJsonStrategy())->executeStrategy($line)); + $encoded = $encoder->encode($line); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[1,2,3],[4,5,6]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[1,2,3],[4,5,6]]}', (new GeoJsonStrategy())->encode($line)); } /** Preserve coordinates and their order without reference metadata. */ public function testEmptyXy(): void { $line = new LineString([]); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[]}', $writer->convert($line)); - static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[]}', (new GeoJsonStrategy())->executeStrategy($line)); + $encoded = $encoder->encode($line); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[]}', (new GeoJsonStrategy())->encode($line)); } /** Preserve coordinates and their order without reference metadata. */ public function testEmptyXyz(): void { $line = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\LineString([]); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[]}', $writer->convert($line)); - static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[]}', (new GeoJsonStrategy())->executeStrategy($line)); + $encoded = $encoder->encode($line); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[]}', (new GeoJsonStrategy())->encode($line)); } /** Preserve coordinates and their order without reference metadata. */ public function testOtherSrid(): void { $line = new LineString([[1, 2], [3, 4]], 3857); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[1,2],[3,4]]}', $writer->convert($line)); - static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[1,2],[3,4]]}', (new GeoJsonStrategy())->executeStrategy($line)); + $encoded = $encoder->encode($line); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[1,2],[3,4]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[1,2],[3,4]]}', (new GeoJsonStrategy())->encode($line)); } /** Reject an incompatible concrete input without modifying it. */ @@ -111,7 +125,7 @@ public function testRejectEmptyXym(): void { $line = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\LineString([]); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($line); + (new Encoder(new GeoJsonStrategy()))->encode($line); } /** Reject an incompatible concrete input without modifying it. */ @@ -119,7 +133,7 @@ public function testRejectEmptyXyzm(): void { $line = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\LineString([]); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($line); + (new Encoder(new GeoJsonStrategy()))->encode($line); } /** Reject an incompatible concrete input without modifying it. */ @@ -127,7 +141,7 @@ public function testRejectSingletonXy(): void { $line = new LineString([[1, 2]]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($line); + (new Encoder(new GeoJsonStrategy()))->encode($line); } /** Reject an incompatible concrete input without modifying it. */ @@ -135,7 +149,7 @@ public function testRejectSingletonXyz(): void { $line = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\LineString([[1, 2, 3]]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($line); + (new Encoder(new GeoJsonStrategy()))->encode($line); } /** Reject an incompatible concrete input without modifying it. */ @@ -143,7 +157,7 @@ public function testRejectXym(): void { $line = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\LineString([[1, 2, 3], [4, 5, 6]]); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($line); + (new Encoder(new GeoJsonStrategy()))->encode($line); } /** Reject an incompatible concrete input without modifying it. */ @@ -151,36 +165,42 @@ public function testRejectXyzm(): void { $line = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\LineString([[1, 2, 3, 4], [5, 6, 7, 8]]); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($line); + (new Encoder(new GeoJsonStrategy()))->encode($line); } /** Preserve coordinates and their order without reference metadata. */ public function testUnknownReference(): void { $line = new LineString([[1, 2], [3, 4]], new SpatialReference(999999, 'CUSTOM')); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[1,2],[3,4]]}', $writer->convert($line)); - static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[1,2],[3,4]]}', (new GeoJsonStrategy())->executeStrategy($line)); + $encoded = $encoder->encode($line); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[1,2],[3,4]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[1,2],[3,4]]}', (new GeoJsonStrategy())->encode($line)); } /** Preserve coordinates and their order without reference metadata. */ public function testXy(): void { $line = new LineString([[1, 2], [3, 4]]); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[1,2],[3,4]]}', $writer->convert($line)); - static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[1,2],[3,4]]}', (new GeoJsonStrategy())->executeStrategy($line)); + $encoded = $encoder->encode($line); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[1,2],[3,4]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[1,2],[3,4]]}', (new GeoJsonStrategy())->encode($line)); } /** Preserve coordinates and their order without reference metadata. */ public function testXyz(): void { $line = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\LineString([[1, 2, 3], [4, 5, 6]]); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[1,2,3],[4,5,6]]}', $writer->convert($line)); - static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[1,2,3],[4,5,6]]}', (new GeoJsonStrategy())->executeStrategy($line)); + $encoded = $encoder->encode($line); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[1,2,3],[4,5,6]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"LineString","coordinates":[[1,2,3],[4,5,6]]}', (new GeoJsonStrategy())->encode($line)); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/GeometryMultiLineStringTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/GeometryMultiLineStringTest.php similarity index 72% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/GeometryMultiLineStringTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/GeometryMultiLineStringTest.php index 6b74f8b..a47966b 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/GeometryMultiLineStringTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/GeometryMultiLineStringTest.php @@ -1,6 +1,6 @@ convert($multiLine)); - static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[170,45],[-170,45]],[[1,2],[3,4]]]}', (new GeoJsonStrategy())->executeStrategy($multiLine)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($multiLine); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[170,45],[-170,45]],[[1,2],[3,4]]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[170,45],[-170,45]],[[1,2],[3,4]]]}', (new GeoJsonStrategy())->encode($multiLine)); } /** Preserve line membership, coordinates and order without reference metadata. */ @@ -51,8 +53,10 @@ public function testDeclaredReference(): void { $multiLine = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\MultiLineString([[[1, 2, 3], [4, 5, 6]]], new SpatialReference(4326, 'EPSG')); - static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[1,2,3],[4,5,6]]]}', (new Writer(new GeoJsonStrategy()))->convert($multiLine)); - static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[1,2,3],[4,5,6]]]}', (new GeoJsonStrategy())->executeStrategy($multiLine)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($multiLine); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[1,2,3],[4,5,6]]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[1,2,3],[4,5,6]]]}', (new GeoJsonStrategy())->encode($multiLine)); } /** Preserve line membership, coordinates and order without reference metadata. */ @@ -60,8 +64,10 @@ public function testEmptyXy(): void { $multiLine = new MultiLineString([]); - static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[]}', (new Writer(new GeoJsonStrategy()))->convert($multiLine)); - static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[]}', (new GeoJsonStrategy())->executeStrategy($multiLine)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($multiLine); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[]}', (new GeoJsonStrategy())->encode($multiLine)); } /** Preserve line membership, coordinates and order without reference metadata. */ @@ -69,8 +75,10 @@ public function testEmptyXyz(): void { $multiLine = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\MultiLineString([]); - static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[]}', (new Writer(new GeoJsonStrategy()))->convert($multiLine)); - static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[]}', (new GeoJsonStrategy())->executeStrategy($multiLine)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($multiLine); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[]}', (new GeoJsonStrategy())->encode($multiLine)); } /** Preserve line membership, coordinates and order without reference metadata. */ @@ -78,8 +86,10 @@ public function testMemberAndPositionOrder(): void { $multiLine = new MultiLineString([[[7.5, 8], [5, 6], [-2, 1]], [[3, 4], [1, 2]]]); - static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[7.5,8],[5,6],[-2,1]],[[3,4],[1,2]]]}', (new Writer(new GeoJsonStrategy()))->convert($multiLine)); - static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[7.5,8],[5,6],[-2,1]],[[3,4],[1,2]]]}', (new GeoJsonStrategy())->executeStrategy($multiLine)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($multiLine); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[7.5,8],[5,6],[-2,1]],[[3,4],[1,2]]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[7.5,8],[5,6],[-2,1]],[[3,4],[1,2]]]}', (new GeoJsonStrategy())->encode($multiLine)); } /** Preserve line membership, coordinates and order without reference metadata. */ @@ -87,8 +97,10 @@ public function testOtherSrid(): void { $multiLine = new MultiLineString([new LineString([[1, 2], [3, 4]], 3857)], 3857); - static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[1,2],[3,4]]]}', (new Writer(new GeoJsonStrategy()))->convert($multiLine)); - static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[1,2],[3,4]]]}', (new GeoJsonStrategy())->executeStrategy($multiLine)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($multiLine); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[1,2],[3,4]]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[1,2],[3,4]]]}', (new GeoJsonStrategy())->encode($multiLine)); } /** Reject an incompatible line member instead of returning partial output. */ @@ -97,7 +109,7 @@ public function testRejectAllEmpty(): void $multiLine = new MultiLineString([new LineString([]), new LineString([])]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiLine); + (new Encoder(new GeoJsonStrategy()))->encode($multiLine); } /** Reject an incompatible line member instead of returning partial output. */ @@ -106,7 +118,7 @@ public function testRejectAllEmptyXyz(): void $multiLine = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\MultiLineString([[], []]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiLine); + (new Encoder(new GeoJsonStrategy()))->encode($multiLine); } /** Reject an incompatible line member instead of returning partial output. */ @@ -115,7 +127,7 @@ public function testRejectEmptyFirst(): void $multiLine = new MultiLineString([new LineString([]), new LineString([[1, 2], [3, 4]])]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiLine); + (new Encoder(new GeoJsonStrategy()))->encode($multiLine); } /** Reject an incompatible line member instead of returning partial output. */ @@ -124,7 +136,7 @@ public function testRejectEmptyLast(): void $multiLine = new MultiLineString([new LineString([[1, 2], [3, 4]]), new LineString([])]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiLine); + (new Encoder(new GeoJsonStrategy()))->encode($multiLine); } /** Reject measured dimensions even when no line members are present. */ @@ -133,7 +145,7 @@ public function testRejectEmptyXym(): void $multiLine = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\MultiLineString([]); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiLine); + (new Encoder(new GeoJsonStrategy()))->encode($multiLine); } /** Reject measured dimensions even when no line members are present. */ @@ -142,7 +154,7 @@ public function testRejectEmptyXyzm(): void $multiLine = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\MultiLineString([]); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiLine); + (new Encoder(new GeoJsonStrategy()))->encode($multiLine); } /** Reject an incompatible line member instead of returning partial output. */ @@ -151,7 +163,7 @@ public function testRejectEmptyXyzMember(): void $multiLine = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\MultiLineString([[[1, 2, 3], [4, 5, 6]], []]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiLine); + (new Encoder(new GeoJsonStrategy()))->encode($multiLine); } /** Reject an incompatible line member instead of returning partial output. */ @@ -160,7 +172,7 @@ public function testRejectSingletonMember(): void $multiLine = new MultiLineString([[[1, 2], [3, 4]], [[5, 6]]]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiLine); + (new Encoder(new GeoJsonStrategy()))->encode($multiLine); } /** Reject an incompatible line member instead of returning partial output. */ @@ -169,7 +181,7 @@ public function testRejectSingletonXyzMember(): void $multiLine = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\MultiLineString([[[1, 2, 3]]]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiLine); + (new Encoder(new GeoJsonStrategy()))->encode($multiLine); } /** Reject measured dimensions even when no line members are present. */ @@ -178,7 +190,7 @@ public function testRejectXym(): void $multiLine = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\MultiLineString([[[1, 2, 3], [4, 5, 6]]]); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiLine); + (new Encoder(new GeoJsonStrategy()))->encode($multiLine); } /** Reject measured dimensions even when no line members are present. */ @@ -187,7 +199,7 @@ public function testRejectXyzm(): void $multiLine = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\MultiLineString([[[1, 2, 3, 4], [5, 6, 7, 8]]]); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiLine); + (new Encoder(new GeoJsonStrategy()))->encode($multiLine); } /** Preserve line membership, coordinates and order without reference metadata. */ @@ -195,8 +207,10 @@ public function testSingleMember(): void { $multiLine = new MultiLineString([[[3, 4], [1, 2]]]); - static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[3,4],[1,2]]]}', (new Writer(new GeoJsonStrategy()))->convert($multiLine)); - static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[3,4],[1,2]]]}', (new GeoJsonStrategy())->executeStrategy($multiLine)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($multiLine); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[3,4],[1,2]]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[3,4],[1,2]]]}', (new GeoJsonStrategy())->encode($multiLine)); } /** Preserve line membership, coordinates and order without reference metadata. */ @@ -204,8 +218,10 @@ public function testUnknownReference(): void { $multiLine = new MultiLineString([[[1, 2], [3, 4]]], new SpatialReference(999999, 'CUSTOM')); - static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[1,2],[3,4]]]}', (new Writer(new GeoJsonStrategy()))->convert($multiLine)); - static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[1,2],[3,4]]]}', (new GeoJsonStrategy())->executeStrategy($multiLine)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($multiLine); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[1,2],[3,4]]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[1,2],[3,4]]]}', (new GeoJsonStrategy())->encode($multiLine)); } /** Preserve line membership, coordinates and order without reference metadata. */ @@ -213,8 +229,10 @@ public function testXy(): void { $multiLine = new MultiLineString([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]); - static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[1,2],[3,4]],[[5,6],[7,8]]]}', (new Writer(new GeoJsonStrategy()))->convert($multiLine)); - static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[1,2],[3,4]],[[5,6],[7,8]]]}', (new GeoJsonStrategy())->executeStrategy($multiLine)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($multiLine); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[1,2],[3,4]],[[5,6],[7,8]]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[1,2],[3,4]],[[5,6],[7,8]]]}', (new GeoJsonStrategy())->encode($multiLine)); } /** Preserve line membership, coordinates and order without reference metadata. */ @@ -222,7 +240,9 @@ public function testXyz(): void { $multiLine = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\MultiLineString([[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]); - static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]]]}', (new Writer(new GeoJsonStrategy()))->convert($multiLine)); - static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]]]}', (new GeoJsonStrategy())->executeStrategy($multiLine)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($multiLine); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiLineString","coordinates":[[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]]]}', (new GeoJsonStrategy())->encode($multiLine)); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/GeometryMultiPointTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/GeometryMultiPointTest.php similarity index 69% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/GeometryMultiPointTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/GeometryMultiPointTest.php index 7f6dedc..eb01b97 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/GeometryMultiPointTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/GeometryMultiPointTest.php @@ -1,6 +1,6 @@ convert($multiPoint)); - static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[3,4,9.5],[1,2,-2],[-7,8,0]]}', (new GeoJsonStrategy())->executeStrategy($multiPoint)); + $encoded = $encoder->encode($multiPoint); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[3,4,9.5],[1,2,-2],[-7,8,0]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[3,4,9.5],[1,2,-2],[-7,8,0]]}', (new GeoJsonStrategy())->encode($multiPoint)); } /** Preserve coordinates and their order without reference metadata. */ public function testAntimeridian(): void { $multiPoint = new MultiPoint([[170, 45], [-170, 45]], 4326); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[170,45],[-170,45]]}', $writer->convert($multiPoint)); - static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[170,45],[-170,45]]}', (new GeoJsonStrategy())->executeStrategy($multiPoint)); + $encoded = $encoder->encode($multiPoint); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[170,45],[-170,45]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[170,45],[-170,45]]}', (new GeoJsonStrategy())->encode($multiPoint)); } /** Preserve coordinates and their order without reference metadata. */ public function testDeclaredEpsg(): void { $multiPoint = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\MultiPoint([[1, 2, 3], [4, 5, 6]], new SpatialReference(4326, 'EPSG')); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2,3],[4,5,6]]}', $writer->convert($multiPoint)); - static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2,3],[4,5,6]]}', (new GeoJsonStrategy())->executeStrategy($multiPoint)); + $encoded = $encoder->encode($multiPoint); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2,3],[4,5,6]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2,3],[4,5,6]]}', (new GeoJsonStrategy())->encode($multiPoint)); } /** Preserve coordinates and their order without reference metadata. */ public function testEmptyXy(): void { $multiPoint = new MultiPoint([]); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[]}', $writer->convert($multiPoint)); - static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[]}', (new GeoJsonStrategy())->executeStrategy($multiPoint)); + $encoded = $encoder->encode($multiPoint); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[]}', (new GeoJsonStrategy())->encode($multiPoint)); } /** Preserve coordinates and their order without reference metadata. */ public function testEmptyXyz(): void { $multiPoint = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\MultiPoint([]); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[]}', $writer->convert($multiPoint)); - static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[]}', (new GeoJsonStrategy())->executeStrategy($multiPoint)); + $encoded = $encoder->encode($multiPoint); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[]}', (new GeoJsonStrategy())->encode($multiPoint)); } /** Preserve coordinates and their order without reference metadata. */ public function testOtherSrid(): void { $multiPoint = new MultiPoint([[1, 2], [3, 4]], 3857); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2],[3,4]]}', $writer->convert($multiPoint)); - static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2],[3,4]]}', (new GeoJsonStrategy())->executeStrategy($multiPoint)); + $encoded = $encoder->encode($multiPoint); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2],[3,4]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2],[3,4]]}', (new GeoJsonStrategy())->encode($multiPoint)); } /** Reject an incompatible concrete input without modifying it. */ @@ -102,7 +114,7 @@ public function testRejectEmptyXym(): void { $multiPoint = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\MultiPoint([]); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiPoint); + (new Encoder(new GeoJsonStrategy()))->encode($multiPoint); } /** Reject an incompatible concrete input without modifying it. */ @@ -110,7 +122,7 @@ public function testRejectEmptyXyzm(): void { $multiPoint = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\MultiPoint([]); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiPoint); + (new Encoder(new GeoJsonStrategy()))->encode($multiPoint); } /** Reject an EMPTY member after a non-empty position without returning partial output. */ @@ -118,7 +130,7 @@ public function testRejectMixedEmptyMembersXy(): void { $multiPoint = new MultiPoint([new Point(1, 2), new Point()]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiPoint); + (new Encoder(new GeoJsonStrategy()))->encode($multiPoint); } /** Reject an EMPTY member after a non-empty position without returning partial output. */ @@ -126,7 +138,7 @@ public function testRejectMixedEmptyMembersXyz(): void { $multiPoint = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\MultiPoint([new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\Point(1, 2, 3), new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\Point()]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiPoint); + (new Encoder(new GeoJsonStrategy()))->encode($multiPoint); } /** Distinguish an aggregate containing only EMPTY members from one with no members. */ @@ -134,7 +146,7 @@ public function testRejectOnlyEmptyMembersXy(): void { $multiPoint = new MultiPoint([new Point(), new Point()]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiPoint); + (new Encoder(new GeoJsonStrategy()))->encode($multiPoint); } /** Distinguish an aggregate containing only EMPTY members from one with no members. */ @@ -142,7 +154,7 @@ public function testRejectOnlyEmptyMembersXyz(): void { $multiPoint = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\MultiPoint([new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\Point(), new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\Point()]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiPoint); + (new Encoder(new GeoJsonStrategy()))->encode($multiPoint); } /** Reject an incompatible concrete input without modifying it. */ @@ -150,7 +162,7 @@ public function testRejectXym(): void { $multiPoint = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\MultiPoint([[1, 2, 3], [4, 5, 6]]); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiPoint); + (new Encoder(new GeoJsonStrategy()))->encode($multiPoint); } /** Reject an incompatible concrete input without modifying it. */ @@ -158,60 +170,72 @@ public function testRejectXyzm(): void { $multiPoint = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\MultiPoint([[1, 2, 3, 4], [5, 6, 7, 8]]); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiPoint); + (new Encoder(new GeoJsonStrategy()))->encode($multiPoint); } /** Preserve coordinates and their order without reference metadata. */ public function testRepeatedPositions(): void { $multiPoint = new MultiPoint([[3.5, 4.25], [1, 2], [3.5, 4.25]]); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[3.5,4.25],[1,2],[3.5,4.25]]}', $writer->convert($multiPoint)); - static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[3.5,4.25],[1,2],[3.5,4.25]]}', (new GeoJsonStrategy())->executeStrategy($multiPoint)); + $encoded = $encoder->encode($multiPoint); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[3.5,4.25],[1,2],[3.5,4.25]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[3.5,4.25],[1,2],[3.5,4.25]]}', (new GeoJsonStrategy())->encode($multiPoint)); } /** Preserve a singleton as a MultiPoint. */ public function testSingletonXy(): void { $multiPoint = new MultiPoint([[1, 2]]); - static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2]]}', (new Writer(new GeoJsonStrategy()))->convert($multiPoint)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($multiPoint); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2]]}', $encoded); } /** Preserve a singleton as a MultiPoint. */ public function testSingletonXyz(): void { $multiPoint = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\MultiPoint([[1, 2, 3]]); - static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2,3]]}', (new Writer(new GeoJsonStrategy()))->convert($multiPoint)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($multiPoint); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2,3]]}', $encoded); } /** Preserve coordinates and their order without reference metadata. */ public function testUnknownReference(): void { $multiPoint = new MultiPoint([[1, 2], [3, 4]], new SpatialReference(999999, 'CUSTOM')); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2],[3,4]]}', $writer->convert($multiPoint)); - static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2],[3,4]]}', (new GeoJsonStrategy())->executeStrategy($multiPoint)); + $encoded = $encoder->encode($multiPoint); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2],[3,4]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2],[3,4]]}', (new GeoJsonStrategy())->encode($multiPoint)); } /** Preserve coordinates and their order without reference metadata. */ public function testXy(): void { $multiPoint = new MultiPoint([[1, 2], [3, 4]]); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2],[3,4]]}', $writer->convert($multiPoint)); - static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2],[3,4]]}', (new GeoJsonStrategy())->executeStrategy($multiPoint)); + $encoded = $encoder->encode($multiPoint); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2],[3,4]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2],[3,4]]}', (new GeoJsonStrategy())->encode($multiPoint)); } /** Preserve coordinates and their order without reference metadata. */ public function testXyz(): void { $multiPoint = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\MultiPoint([[1, 2, 3], [4, 5, 6]]); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2,3],[4,5,6]]}', $writer->convert($multiPoint)); - static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2,3],[4,5,6]]}', (new GeoJsonStrategy())->executeStrategy($multiPoint)); + $encoded = $encoder->encode($multiPoint); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2,3],[4,5,6]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPoint","coordinates":[[1,2,3],[4,5,6]]}', (new GeoJsonStrategy())->encode($multiPoint)); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/GeometryMultiPolygonTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/GeometryMultiPolygonTest.php similarity index 73% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/GeometryMultiPolygonTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/GeometryMultiPolygonTest.php index f09cccc..3296ecc 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/GeometryMultiPolygonTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/GeometryMultiPolygonTest.php @@ -1,6 +1,6 @@ convert($multiPolygon)); - static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[[[[170,40],[170,50],[-170,50],[-170,40],[170,40]]]]}', (new GeoJsonStrategy())->executeStrategy($multiPolygon)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($multiPolygon); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[[[[170,40],[170,50],[-170,50],[-170,40],[170,40]]]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[[[[170,40],[170,50],[-170,50],[-170,40],[170,40]]]]}', (new GeoJsonStrategy())->encode($multiPolygon)); } /** An aggregate without members is supported. */ @@ -51,8 +53,10 @@ public function testEmptyXy(): void { $multiPolygon = new MultiPolygon([]); - static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[]}', (new Writer(new GeoJsonStrategy()))->convert($multiPolygon)); - static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[]}', (new GeoJsonStrategy())->executeStrategy($multiPolygon)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($multiPolygon); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[]}', (new GeoJsonStrategy())->encode($multiPolygon)); } /** An empty XYZ aggregate has no dimension marker. */ @@ -60,8 +64,10 @@ public function testEmptyXyz(): void { $multiPolygon = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\MultiPolygon([]); - static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[]}', (new Writer(new GeoJsonStrategy()))->convert($multiPolygon)); - static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[]}', (new GeoJsonStrategy())->executeStrategy($multiPolygon)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($multiPolygon); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[]}', (new GeoJsonStrategy())->encode($multiPolygon)); } /** Reject the whole aggregate through the approved structural contract. */ @@ -70,7 +76,7 @@ public function testRejectClockwiseLaterExterior(): void $multiPolygon = new MultiPolygon([[[[0, 0], [2, 0], [0, 2], [0, 0]]], [[[3, 0], [3, 2], [5, 0], [3, 0]]]]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiPolygon); + (new Encoder(new GeoJsonStrategy()))->encode($multiPolygon); } /** Reject the whole aggregate through the approved structural contract. */ @@ -79,7 +85,7 @@ public function testRejectCounterclockwiseLaterHole(): void $multiPolygon = new MultiPolygon([[[[10, 0], [12, 0], [10, 2], [10, 0]]], [[[0, 0], [4, 0], [4, 4], [0, 4], [0, 0]], [[1, 1], [2, 1], [2, 2], [1, 2], [1, 1]]]]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiPolygon); + (new Encoder(new GeoJsonStrategy()))->encode($multiPolygon); } /** Reject the whole aggregate through the approved structural contract. */ @@ -88,7 +94,7 @@ public function testRejectEmptyMember(): void $multiPolygon = new MultiPolygon([new Polygon([[[0, 0], [2, 0], [0, 2], [0, 0]]]), new Polygon([])]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiPolygon); + (new Encoder(new GeoJsonStrategy()))->encode($multiPolygon); } /** Reject measured dimensions without discarding M. */ @@ -97,7 +103,7 @@ public function testRejectEmptyXym(): void $multiPolygon = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\MultiPolygon([]); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiPolygon); + (new Encoder(new GeoJsonStrategy()))->encode($multiPolygon); } /** Reject measured dimensions without discarding M. */ @@ -106,7 +112,7 @@ public function testRejectEmptyXyzm(): void $multiPolygon = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\MultiPolygon([]); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiPolygon); + (new Encoder(new GeoJsonStrategy()))->encode($multiPolygon); } /** Reject the whole aggregate through the approved structural contract. */ @@ -115,7 +121,7 @@ public function testRejectOnlyEmptyMembers(): void $multiPolygon = new MultiPolygon([new Polygon([]), new Polygon([])]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiPolygon); + (new Encoder(new GeoJsonStrategy()))->encode($multiPolygon); } /** Reject measured dimensions without discarding M. */ @@ -124,7 +130,7 @@ public function testRejectXym(): void $multiPolygon = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\MultiPolygon([[[[0, 0, 3], [2, 0, 3], [0, 2, 3], [0, 0, 3]]]]); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiPolygon); + (new Encoder(new GeoJsonStrategy()))->encode($multiPolygon); } /** Reject measured dimensions without discarding M. */ @@ -133,7 +139,7 @@ public function testRejectXyzm(): void $multiPolygon = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\MultiPolygon([[[[0, 0, 3, 4], [2, 0, 3, 4], [0, 2, 3, 4], [0, 0, 3, 4]]]]); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiPolygon); + (new Encoder(new GeoJsonStrategy()))->encode($multiPolygon); } /** Reject the whole aggregate through the approved structural contract. */ @@ -142,7 +148,7 @@ public function testRejectZeroAreaExterior(): void $multiPolygon = new MultiPolygon([[[[0, 0], [1, 0], [2, 0], [0, 0]]]]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($multiPolygon); + (new Encoder(new GeoJsonStrategy()))->encode($multiPolygon); } /** Preserve multiple holes, member order and decimal coordinates. */ @@ -150,8 +156,10 @@ public function testRingOrder(): void { $multiPolygon = new MultiPolygon([[[[0, 0], [8, 0], [8, 8], [0, 8], [0, 0]], [[1, 1], [1, 2], [2, 2], [2, 1], [1, 1]], [[4, 4], [4, 5], [5, 5], [5, 4], [4, 4]]], [[[10.5, 0], [12, 0], [10.5, 2], [10.5, 0]]]]); - static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[[[[0,0],[8,0],[8,8],[0,8],[0,0]],[[1,1],[1,2],[2,2],[2,1],[1,1]],[[4,4],[4,5],[5,5],[5,4],[4,4]]],[[[10.5,0],[12,0],[10.5,2],[10.5,0]]]]}', (new Writer(new GeoJsonStrategy()))->convert($multiPolygon)); - static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[[[[0,0],[8,0],[8,8],[0,8],[0,0]],[[1,1],[1,2],[2,2],[2,1],[1,1]],[[4,4],[4,5],[5,5],[5,4],[4,4]]],[[[10.5,0],[12,0],[10.5,2],[10.5,0]]]]}', (new GeoJsonStrategy())->executeStrategy($multiPolygon)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($multiPolygon); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[[[[0,0],[8,0],[8,8],[0,8],[0,0]],[[1,1],[1,2],[2,2],[2,1],[1,1]],[[4,4],[4,5],[5,5],[5,4],[4,4]]],[[[10.5,0],[12,0],[10.5,2],[10.5,0]]]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[[[[0,0],[8,0],[8,8],[0,8],[0,0]],[[1,1],[1,2],[2,2],[2,1],[1,1]],[[4,4],[4,5],[5,5],[5,4],[4,4]]],[[[10.5,0],[12,0],[10.5,2],[10.5,0]]]]}', (new GeoJsonStrategy())->encode($multiPolygon)); } /** Preserve member and position order with SRID omitted. */ @@ -159,8 +167,10 @@ public function testXy(): void { $multiPolygon = new MultiPolygon([[[[0, 0], [2, 0], [0, 2], [0, 0]]], [[[3, 0], [5, 0], [3, 2], [3, 0]]]], 4326); - static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[[[[0,0],[2,0],[0,2],[0,0]]],[[[3,0],[5,0],[3,2],[3,0]]]]}', (new Writer(new GeoJsonStrategy()))->convert($multiPolygon)); - static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[[[[0,0],[2,0],[0,2],[0,0]]],[[[3,0],[5,0],[3,2],[3,0]]]]}', (new GeoJsonStrategy())->executeStrategy($multiPolygon)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($multiPolygon); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[[[[0,0],[2,0],[0,2],[0,0]]],[[[3,0],[5,0],[3,2],[3,0]]]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[[[[0,0],[2,0],[0,2],[0,0]]],[[[3,0],[5,0],[3,2],[3,0]]]]}', (new GeoJsonStrategy())->encode($multiPolygon)); } /** Keep the singleton wrapper, Z and coordinates without reference metadata. */ @@ -168,7 +178,9 @@ public function testXyz(): void { $multiPolygon = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\MultiPolygon([[[[0, 0, 3], [2, 0, 3], [0, 2, 3], [0, 0, 3]]]], new SpatialReference(999999, 'CUSTOM')); - static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[[[[0,0,3],[2,0,3],[0,2,3],[0,0,3]]]]}', (new Writer(new GeoJsonStrategy()))->convert($multiPolygon)); - static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[[[[0,0,3],[2,0,3],[0,2,3],[0,0,3]]]]}', (new GeoJsonStrategy())->executeStrategy($multiPolygon)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($multiPolygon); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[[[[0,0,3],[2,0,3],[0,2,3],[0,0,3]]]]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"MultiPolygon","coordinates":[[[[0,0,3],[2,0,3],[0,2,3],[0,0,3]]]]}', (new GeoJsonStrategy())->encode($multiPolygon)); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/GeometryPointTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/GeometryPointTest.php similarity index 62% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/GeometryPointTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/GeometryPointTest.php index 2be8066..8f25b03 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/GeometryPointTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/GeometryPointTest.php @@ -1,6 +1,6 @@ convert($point)); - static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[]}', (new GeoJsonStrategy())->executeStrategy($point)); + $encoded = $encoder->encode($point); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[]}', (new GeoJsonStrategy())->encode($point)); } /** Preserve the supplied point coordinates without reference metadata. */ public function testEmptyXyz(): void { $point = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\Point(); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[]}', $writer->convert($point)); - static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[]}', (new GeoJsonStrategy())->executeStrategy($point)); + $encoded = $encoder->encode($point); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[]}', (new GeoJsonStrategy())->encode($point)); } /** Preserve the supplied point coordinates without reference metadata. */ public function testEpsg(): void { $point = new Point(1, 2, new SpatialReference(4326, 'EPSG')); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2]}', $writer->convert($point)); - static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2]}', (new GeoJsonStrategy())->executeStrategy($point)); + $encoded = $encoder->encode($point); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2]}', (new GeoJsonStrategy())->encode($point)); } /** Preserve the supplied point coordinates without reference metadata. */ public function testFractionalCoordinates(): void { $point = new Point(2.35, 48.86, 4326); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[2.35,48.86]}', $writer->convert($point)); - static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[2.35,48.86]}', (new GeoJsonStrategy())->executeStrategy($point)); + $encoded = $encoder->encode($point); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[2.35,48.86]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[2.35,48.86]}', (new GeoJsonStrategy())->encode($point)); } /** Preserve the supplied point coordinates without reference metadata. */ public function testOtherSrid(): void { $point = new Point(1, 2, 3857); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2]}', $writer->convert($point)); - static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2]}', (new GeoJsonStrategy())->executeStrategy($point)); + $encoded = $encoder->encode($point); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2]}', (new GeoJsonStrategy())->encode($point)); } /** Reject measured points without dropping or reinterpreting M. */ @@ -92,7 +102,7 @@ public function testRejectEmptyXym(): void { $point = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\Point(); $this->expectException(UnsupportedDimensionException::class); - (new GeoJsonStrategy())->executeStrategy($point); + (new GeoJsonStrategy())->encode($point); } /** Reject measured points without dropping or reinterpreting M. */ @@ -100,15 +110,15 @@ public function testRejectEmptyXyzm(): void { $point = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\Point(); $this->expectException(UnsupportedDimensionException::class); - (new GeoJsonStrategy())->executeStrategy($point); + (new GeoJsonStrategy())->encode($point); } - /** Do not convert a recognized non-GeoJSON type to another geometry. */ + /** Do not encode a recognized non-GeoJSON type to another geometry. */ public function testRejectTriangle(): void { $triangle = new Triangle([]); $this->expectException(UnsupportedSpatialTypeException::class); - (new GeoJsonStrategy())->executeStrategy($triangle); + (new GeoJsonStrategy())->encode($triangle); } /** Reject measured points without dropping or reinterpreting M. */ @@ -116,7 +126,7 @@ public function testRejectXym(): void { $point = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\Point(1, 2, 4); $this->expectException(UnsupportedDimensionException::class); - (new GeoJsonStrategy())->executeStrategy($point); + (new GeoJsonStrategy())->encode($point); } /** Reject measured points without dropping or reinterpreting M. */ @@ -124,46 +134,54 @@ public function testRejectXyzm(): void { $point = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\Point(1, 2, 3, 4); $this->expectException(UnsupportedDimensionException::class); - (new GeoJsonStrategy())->executeStrategy($point); + (new GeoJsonStrategy())->encode($point); } /** Preserve the supplied point coordinates without reference metadata. */ public function testUnknownReference(): void { $point = new Point(1, 2, new SpatialReference(999999, 'CUSTOM')); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2]}', $writer->convert($point)); - static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2]}', (new GeoJsonStrategy())->executeStrategy($point)); + $encoded = $encoder->encode($point); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2]}', (new GeoJsonStrategy())->encode($point)); } /** Preserve the supplied point coordinates without reference metadata. */ public function testXy(): void { $point = new Point(1, 2); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2]}', $writer->convert($point)); - static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2]}', (new GeoJsonStrategy())->executeStrategy($point)); + $encoded = $encoder->encode($point); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2]}', (new GeoJsonStrategy())->encode($point)); } /** Preserve the supplied point coordinates without reference metadata. */ public function testXyz(): void { $point = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\Point(1, 2, 3); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2,3]}', $writer->convert($point)); - static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2,3]}', (new GeoJsonStrategy())->executeStrategy($point)); + $encoded = $encoder->encode($point); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2,3]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2,3]}', (new GeoJsonStrategy())->encode($point)); } /** Preserve the supplied point coordinates without reference metadata. */ public function testZeroSrid(): void { $point = new Point(1, 2, 0); - $writer = new Writer(new GeoJsonStrategy()); + $encoder = new Encoder(new GeoJsonStrategy()); - static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2]}', $writer->convert($point)); - static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2]}', (new GeoJsonStrategy())->executeStrategy($point)); + $encoded = $encoder->encode($point); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2]}', $encoded); + static::assertJsonStringEqualsJsonString('{"type":"Point","coordinates":[1,2]}', (new GeoJsonStrategy())->encode($point)); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/GeometryPolygonTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/GeometryPolygonTest.php similarity index 74% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/GeometryPolygonTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/GeometryPolygonTest.php index 1d376d3..2b4e484 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/GeoJson/GeometryPolygonTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/GeoJson/GeometryPolygonTest.php @@ -1,6 +1,6 @@ convert($polygon)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($polygon); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"Polygon","coordinates":[[[170,40],[170,50],[-170,50],[-170,40],[170,40]]]}', $encoded); } /** Reject clockwise exteriors without reversing the source ring. */ @@ -50,7 +52,7 @@ public function testClockwiseExterior(): void $polygon = new Polygon([[[0, 0], [0, 2], [2, 0], [0, 0]]]); try { - (new Writer(new GeoJsonStrategy()))->convert($polygon); + (new Encoder(new GeoJsonStrategy()))->encode($polygon); static::fail('Clockwise exterior must be rejected.'); } catch (UnsupportedGeometryStructureException) { static::assertSame([[[0, 0], [0, 2], [2, 0], [0, 0]]], $polygon->toArray()); @@ -63,7 +65,7 @@ public function testCounterclockwiseHole(): void $polygon = new Polygon([[[0, 0], [4, 0], [4, 4], [0, 4], [0, 0]], [[1, 1], [2, 1], [2, 2], [1, 2], [1, 1]]]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($polygon); + (new Encoder(new GeoJsonStrategy()))->encode($polygon); } /** A positive signed area does not claim or require ring simplicity. */ @@ -71,7 +73,9 @@ public function testCrossedRingWithPositiveArea(): void { $polygon = new Polygon([[[0, 0], [3, 3], [0, 3], [2, 0], [0, 0]]]); - static::assertJsonStringEqualsJsonString('{"type":"Polygon","coordinates":[[[0,0],[3,3],[0,3],[2,0],[0,0]]]}', (new Writer(new GeoJsonStrategy()))->convert($polygon)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($polygon); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"Polygon","coordinates":[[[0,0],[3,3],[0,3],[2,0],[0,0]]]}', $encoded); } /** EMPTY is an empty coordinates array. */ @@ -79,7 +83,9 @@ public function testEmptyXy(): void { $polygon = new Polygon([]); - static::assertJsonStringEqualsJsonString('{"type":"Polygon","coordinates":[]}', (new Writer(new GeoJsonStrategy()))->convert($polygon)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($polygon); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"Polygon","coordinates":[]}', $encoded); } /** EMPTY has no artificial dimension marker. */ @@ -87,7 +93,9 @@ public function testEmptyXyz(): void { $polygon = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\Polygon([]); - static::assertJsonStringEqualsJsonString('{"type":"Polygon","coordinates":[]}', (new Writer(new GeoJsonStrategy()))->convert($polygon)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($polygon); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"Polygon","coordinates":[]}', $encoded); } /** Preserve exterior and interior ring order and winding. */ @@ -95,7 +103,9 @@ public function testHole(): void { $polygon = new Polygon([[[0, 0], [4, 0], [4, 4], [0, 4], [0, 0]], [[1, 1], [1, 2], [2, 2], [2, 1], [1, 1]]]); - static::assertJsonStringEqualsJsonString('{"type":"Polygon","coordinates":[[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[1,2],[2,2],[2,1],[1,1]]]}', (new Writer(new GeoJsonStrategy()))->convert($polygon)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($polygon); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"Polygon","coordinates":[[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[1,2],[2,2],[2,1],[1,1]]]}', $encoded); } /** Reject measured dimensions even when EMPTY. */ @@ -104,7 +114,7 @@ public function testRejectEmptyXym(): void $polygon = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\Polygon([]); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($polygon); + (new Encoder(new GeoJsonStrategy()))->encode($polygon); } /** Reject measured dimensions even when EMPTY. */ @@ -113,7 +123,7 @@ public function testRejectEmptyXyzm(): void $polygon = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\Polygon([]); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($polygon); + (new Encoder(new GeoJsonStrategy()))->encode($polygon); } /** A later hole must also be checked before returning any output. */ @@ -126,7 +136,7 @@ public function testRejectLaterCounterclockwiseHole(): void ]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($polygon); + (new Encoder(new GeoJsonStrategy()))->encode($polygon); } /** M must not be serialized as altitude. */ @@ -135,7 +145,7 @@ public function testRejectXym(): void $polygon = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\Polygon([[[0, 0, 3], [2, 0, 3], [0, 2, 3], [0, 0, 3]]]); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($polygon); + (new Encoder(new GeoJsonStrategy()))->encode($polygon); } /** M must not be discarded. */ @@ -144,7 +154,7 @@ public function testRejectXyzm(): void $polygon = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\Polygon([[[0, 0, 3, 4], [2, 0, 3, 4], [0, 2, 3, 4], [0, 0, 3, 4]]]); $this->expectException(UnsupportedDimensionException::class); - (new Writer(new GeoJsonStrategy()))->convert($polygon); + (new Encoder(new GeoJsonStrategy()))->encode($polygon); } /** The bow-tie is rejected for zero signed area, without topology analysis. */ @@ -153,7 +163,7 @@ public function testRejectZeroAreaCrossedRing(): void $polygon = new Polygon([[[0, 0], [2, 2], [0, 2], [2, 0], [0, 0]]]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($polygon); + (new Encoder(new GeoJsonStrategy()))->encode($polygon); } /** Collinear rings have no winding and are rejected by the approved policy. */ @@ -162,7 +172,7 @@ public function testRejectZeroAreaExterior(): void $polygon = new Polygon([[[0, 0], [1, 0], [2, 0], [0, 0]]]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($polygon); + (new Encoder(new GeoJsonStrategy()))->encode($polygon); } /** The orientation policy applies to every interior ring as well. */ @@ -171,7 +181,7 @@ public function testRejectZeroAreaHole(): void $polygon = new Polygon([[[0, 0], [4, 0], [4, 4], [0, 4], [0, 0]], [[1, 1], [2, 1], [3, 1], [1, 1]]]); $this->expectException(UnsupportedGeometryStructureException::class); - (new Writer(new GeoJsonStrategy()))->convert($polygon); + (new Encoder(new GeoJsonStrategy()))->encode($polygon); } /** Varying height does not change the XY winding or position order. */ @@ -183,7 +193,9 @@ public function testVaryingAltitudeAndMultipleHoles(): void [[4, 4, 9], [4, 5, 10], [5, 5, 11], [5, 4, 12], [4, 4, 9]], ]); - static::assertJsonStringEqualsJsonString('{"type":"Polygon","coordinates":[[[0,0,1],[8,0,2],[8,8,3],[0,8,4],[0,0,1]],[[1,1,5],[1,2,6],[2,2,7],[2,1,8],[1,1,5]],[[4,4,9],[4,5,10],[5,5,11],[5,4,12],[4,4,9]]]}', (new Writer(new GeoJsonStrategy()))->convert($polygon)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($polygon); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"Polygon","coordinates":[[[0,0,1],[8,0,2],[8,8,3],[0,8,4],[0,0,1]],[[1,1,5],[1,2,6],[2,2,7],[2,1,8],[1,1,5]],[[4,4,9],[4,5,10],[5,5,11],[5,4,12],[4,4,9]]]}', $encoded); } /** Preserve the exterior ring and the original object. */ @@ -191,7 +203,9 @@ public function testXy(): void { $polygon = new Polygon([[[0, 0], [2, 0], [0, 2], [0, 0]]], 4326); - static::assertJsonStringEqualsJsonString('{"type":"Polygon","coordinates":[[[0,0],[2,0],[0,2],[0,0]]]}', (new Writer(new GeoJsonStrategy()))->convert($polygon)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($polygon); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"Polygon","coordinates":[[[0,0],[2,0],[0,2],[0,0]]]}', $encoded); static::assertSame([[[0, 0], [2, 0], [0, 2], [0, 0]]], $polygon->toArray()); } @@ -200,6 +214,8 @@ public function testXyz(): void { $polygon = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\Polygon([[[0, 0, 3], [2, 0, 3], [0, 2, 3], [0, 0, 3]]], new SpatialReference(999999, 'CUSTOM')); - static::assertJsonStringEqualsJsonString('{"type":"Polygon","coordinates":[[[0,0,3],[2,0,3],[0,2,3],[0,0,3]]]}', (new Writer(new GeoJsonStrategy()))->convert($polygon)); + $encoded = (new Encoder(new GeoJsonStrategy()))->encode($polygon); + static::assertIsString($encoded); + static::assertJsonStringEqualsJsonString('{"type":"Polygon","coordinates":[[[0,0,3],[2,0,3],[0,2,3],[0,0,3]]]}', $encoded); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/MySQL/GeographyCoordinateOrderTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/MySQL/GeographyCoordinateOrderTest.php similarity index 87% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/MySQL/GeographyCoordinateOrderTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/MySQL/GeographyCoordinateOrderTest.php index ce5d9a9..c1efabf 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/MySQL/GeographyCoordinateOrderTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/MySQL/GeographyCoordinateOrderTest.php @@ -1,6 +1,6 @@ executeStrategy($collection)) + bin2hex((new MySQLBinaryStrategy())->encode($collection)) ); } @@ -58,7 +58,7 @@ public function testGeographyCollectionEmpty(): void // Reference geometry in WKT: GEOMETRYCOLLECTION EMPTY static::assertSame( 'e6100000010700000000000000', - bin2hex((new MySQLBinaryStrategy())->executeStrategy($collection)) + bin2hex((new MySQLBinaryStrategy())->encode($collection)) ); } @@ -70,7 +70,7 @@ public function testLineString(): void // Reference geometry in WKT: LINESTRING (0 0, 2 3, 4 1) static::assertSame( 'e610000001020000000300000000000000000000000000000000000000000000000000004000000000000008400000000000001040000000000000f03f', - bin2hex((new MySQLBinaryStrategy())->executeStrategy($line)) + bin2hex((new MySQLBinaryStrategy())->encode($line)) ); } @@ -85,7 +85,7 @@ public function testMultiLineString(): void // Reference geometry in WKT: MULTILINESTRING ((0 0, 2 3), (4 1, 5 2)) static::assertSame( 'e610000001050000000200000001020000000200000000000000000000000000000000000000000000000000004000000000000008400102000000020000000000000000001040000000000000f03f00000000000014400000000000000040', - bin2hex((new MySQLBinaryStrategy())->executeStrategy($lines)) + bin2hex((new MySQLBinaryStrategy())->encode($lines)) ); } @@ -97,7 +97,7 @@ public function testMultiPoint(): void // Reference geometry in WKT: MULTIPOINT ((1 2), (3 4)) static::assertSame( 'e61000000104000000020000000101000000000000000000f03f0000000000000040010100000000000000000008400000000000001040', - bin2hex((new MySQLBinaryStrategy())->executeStrategy($points)) + bin2hex((new MySQLBinaryStrategy())->encode($points)) ); } @@ -112,7 +112,7 @@ public function testMultiPolygon(): void // Reference geometry in WKT: MULTIPOLYGON (((0 0, 2 0, 0 2, 0 0)), ((3 3, 5 3, 3 5, 3 3))) static::assertSame( 'e610000001060000000200000001030000000100000004000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000040000000000000000000000000000000000103000000010000000400000000000000000008400000000000000840000000000000144000000000000008400000000000000840000000000000144000000000000008400000000000000840', - bin2hex((new MySQLBinaryStrategy())->executeStrategy($polygons)) + bin2hex((new MySQLBinaryStrategy())->encode($polygons)) ); } @@ -125,7 +125,7 @@ public function testNestedCollection(): void ]); static::assertSame( 'e61000000107000000020000000101000000cdcccccccccc0240ae47e17a146e4840010700000001000000010700000000000000', - bin2hex((new MySQLBinaryStrategy())->executeStrategy($collection)) + bin2hex((new MySQLBinaryStrategy())->encode($collection)) ); } @@ -143,7 +143,7 @@ public function testNestedMultiLineStringWithEmptyCollection(): void static::assertSame( 'e610000001070000000200000001070000000000000001070000000100000001050000000200000001020000000200000000000000000000000000000000000000000000000000004000000000000008400102000000020000000000000000001040000000000000f03f00000000000014400000000000000040', - bin2hex((new MySQLBinaryStrategy())->executeStrategy($collection)) + bin2hex((new MySQLBinaryStrategy())->encode($collection)) ); } @@ -158,7 +158,7 @@ public function testNestedMultiPointWithEmptyCollection(): void static::assertSame( 'e61000000107000000020000000107000000000000000107000000010000000104000000020000000101000000000000000000f03f0000000000000040010100000000000000000008400000000000001040', - bin2hex((new MySQLBinaryStrategy())->executeStrategy($collection)) + bin2hex((new MySQLBinaryStrategy())->encode($collection)) ); } @@ -176,7 +176,7 @@ public function testNestedMultiPolygonWithEmptyCollection(): void static::assertSame( 'e610000001070000000200000001070000000000000001070000000100000001060000000200000001030000000100000004000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000040000000000000000000000000000000000103000000010000000400000000000000000008400000000000000840000000000000144000000000000008400000000000000840000000000000144000000000000008400000000000000840', - bin2hex((new MySQLBinaryStrategy())->executeStrategy($collection)) + bin2hex((new MySQLBinaryStrategy())->encode($collection)) ); } @@ -186,7 +186,7 @@ public function testParisPoint(): void $point = new Point(2.35, 48.86, 4326); static::assertSame( 'e61000000101000000cdcccccccccc0240ae47e17a146e4840', - bin2hex((new MySQLBinaryStrategy())->executeStrategy($point)) + bin2hex((new MySQLBinaryStrategy())->encode($point)) ); } @@ -198,7 +198,7 @@ public function testPoint(): void // Reference geometry in WKT: POINT (2.5 -3) static::assertSame( 'e61000000101000000000000000000044000000000000008c0', - bin2hex((new MySQLBinaryStrategy())->executeStrategy($point)) + bin2hex((new MySQLBinaryStrategy())->encode($point)) ); } @@ -213,7 +213,7 @@ public function testPolygon(): void // Reference geometry in WKT: POLYGON ((0 0, 4 0, 4 4, 0 4, 0 0), (1 1, 1 2, 2 2, 2 1, 1 1)) static::assertSame( 'e610000001030000000200000005000000000000000000000000000000000000000000000000001040000000000000000000000000000010400000000000001040000000000000000000000000000010400000000000000000000000000000000005000000000000000000f03f000000000000f03f000000000000f03f0000000000000040000000000000004000000000000000400000000000000040000000000000f03f000000000000f03f000000000000f03f', - bin2hex((new MySQLBinaryStrategy())->executeStrategy($polygon)) + bin2hex((new MySQLBinaryStrategy())->encode($polygon)) ); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/MySQL/GeographyInvalidInputTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/MySQL/GeographyInvalidInputTest.php similarity index 84% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/MySQL/GeographyInvalidInputTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/MySQL/GeographyInvalidInputTest.php index f5a0d3c..aaa0375 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/MySQL/GeographyInvalidInputTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/MySQL/GeographyInvalidInputTest.php @@ -1,6 +1,6 @@ expectException(UnsupportedSpatialTypeException::class); $this->expectExceptionMessage('MySQL adapter does not support empty LineString; only GeometryCollection may be empty.'); - (new MySQLBinaryStrategy())->executeStrategy($spatial); + (new MySQLBinaryStrategy())->encode($spatial); } /** Reject incompatible input instead of emitting a lossy or invalid value. */ @@ -54,7 +54,7 @@ public function testEmptyMultiLineString(): void $spatial = new MultiLineString([], 4326); $this->expectException(UnsupportedSpatialTypeException::class); $this->expectExceptionMessage('MySQL adapter does not support empty MultiLineString; only GeometryCollection may be empty.'); - (new MySQLBinaryStrategy())->executeStrategy($spatial); + (new MySQLBinaryStrategy())->encode($spatial); } /** Reject incompatible input instead of emitting a lossy or invalid value. */ @@ -63,7 +63,7 @@ public function testEmptyMultiPoint(): void $spatial = new MultiPoint([], 4326); $this->expectException(UnsupportedSpatialTypeException::class); $this->expectExceptionMessage('MySQL adapter does not support empty MultiPoint; only GeometryCollection may be empty.'); - (new MySQLBinaryStrategy())->executeStrategy($spatial); + (new MySQLBinaryStrategy())->encode($spatial); } /** Reject incompatible input instead of emitting a lossy or invalid value. */ @@ -72,7 +72,7 @@ public function testEmptyMultiPolygon(): void $spatial = new MultiPolygon([], 4326); $this->expectException(UnsupportedSpatialTypeException::class); $this->expectExceptionMessage('MySQL adapter does not support empty MultiPolygon; only GeometryCollection may be empty.'); - (new MySQLBinaryStrategy())->executeStrategy($spatial); + (new MySQLBinaryStrategy())->encode($spatial); } /** Reject incompatible input instead of emitting a lossy or invalid value. */ @@ -81,7 +81,7 @@ public function testEmptyPoint(): void $spatial = new Point(srid: 4326); $this->expectException(UnsupportedSpatialTypeException::class); $this->expectExceptionMessage('MySQL adapter does not support empty Point; only GeometryCollection may be empty.'); - (new MySQLBinaryStrategy())->executeStrategy($spatial); + (new MySQLBinaryStrategy())->encode($spatial); } /** Reject incompatible input instead of emitting a lossy or invalid value. */ @@ -90,7 +90,7 @@ public function testEmptyPolygon(): void $spatial = new Polygon([], 4326); $this->expectException(UnsupportedSpatialTypeException::class); $this->expectExceptionMessage('MySQL adapter does not support empty Polygon; only GeometryCollection may be empty.'); - (new MySQLBinaryStrategy())->executeStrategy($spatial); + (new MySQLBinaryStrategy())->encode($spatial); } /** Reject incompatible input instead of emitting a lossy or invalid value. */ @@ -99,7 +99,7 @@ public function testMultiLineStringWithEmptyMember(): void $spatial = new MultiLineString([new LineString([], 4326)], 4326); $this->expectException(UnsupportedSpatialTypeException::class); $this->expectExceptionMessage('MySQL adapter does not support empty LineString; only GeometryCollection may be empty.'); - (new MySQLBinaryStrategy())->executeStrategy($spatial); + (new MySQLBinaryStrategy())->encode($spatial); } /** Reject incompatible input instead of emitting a lossy or invalid value. */ @@ -108,7 +108,7 @@ public function testMultiPolygonWithEmptyMember(): void $spatial = new MultiPolygon([new Polygon([], 4326)], 4326); $this->expectException(UnsupportedSpatialTypeException::class); $this->expectExceptionMessage('MySQL adapter does not support empty Polygon; only GeometryCollection may be empty.'); - (new MySQLBinaryStrategy())->executeStrategy($spatial); + (new MySQLBinaryStrategy())->encode($spatial); } /** Reject incompatible input instead of emitting a lossy or invalid value. */ @@ -119,7 +119,7 @@ public function testNestedEmptyPoint(): void ]); $this->expectException(UnsupportedSpatialTypeException::class); $this->expectExceptionMessage('MySQL adapter does not support empty Point; only GeometryCollection may be empty.'); - (new MySQLBinaryStrategy())->executeStrategy($spatial); + (new MySQLBinaryStrategy())->encode($spatial); } /** Reject incompatible input instead of emitting a lossy or invalid value. */ @@ -128,7 +128,7 @@ public function testXymEmptyCollection(): void $spatial = new GeographyCollection(4326, []); $this->expectException(UnsupportedDimensionException::class); $this->expectExceptionMessage('MySQL adapter only supports XY coordinates; Z and M are not supported.'); - (new MySQLBinaryStrategy())->executeStrategy($spatial); + (new MySQLBinaryStrategy())->encode($spatial); } /** Reject incompatible input instead of emitting a lossy or invalid value. */ @@ -137,7 +137,7 @@ public function testXymEmptyPoint(): void $spatial = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\Point(srid: 4326); $this->expectException(UnsupportedDimensionException::class); $this->expectExceptionMessage('MySQL adapter only supports XY coordinates; Z and M are not supported.'); - (new MySQLBinaryStrategy())->executeStrategy($spatial); + (new MySQLBinaryStrategy())->encode($spatial); } /** Reject incompatible input instead of emitting a lossy or invalid value. */ @@ -146,7 +146,7 @@ public function testXymPoint(): void $spatial = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\Point(1, 2, 4, 4326); $this->expectException(UnsupportedDimensionException::class); $this->expectExceptionMessage('MySQL adapter only supports XY coordinates; Z and M are not supported.'); - (new MySQLBinaryStrategy())->executeStrategy($spatial); + (new MySQLBinaryStrategy())->encode($spatial); } /** Reject incompatible input instead of emitting a lossy or invalid value. */ @@ -155,7 +155,7 @@ public function testXyzEmptyCollection(): void $spatial = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\GeographyCollection(4326, []); $this->expectException(UnsupportedDimensionException::class); $this->expectExceptionMessage('MySQL adapter only supports XY coordinates; Z and M are not supported.'); - (new MySQLBinaryStrategy())->executeStrategy($spatial); + (new MySQLBinaryStrategy())->encode($spatial); } /** Reject incompatible input instead of emitting a lossy or invalid value. */ @@ -164,7 +164,7 @@ public function testXyzEmptyPoint(): void $spatial = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\Point(srid: 4326); $this->expectException(UnsupportedDimensionException::class); $this->expectExceptionMessage('MySQL adapter only supports XY coordinates; Z and M are not supported.'); - (new MySQLBinaryStrategy())->executeStrategy($spatial); + (new MySQLBinaryStrategy())->encode($spatial); } /** Reject incompatible input instead of emitting a lossy or invalid value. */ @@ -173,7 +173,7 @@ public function testXyzmEmptyCollection(): void $spatial = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\GeographyCollection(4326, []); $this->expectException(UnsupportedDimensionException::class); $this->expectExceptionMessage('MySQL adapter only supports XY coordinates; Z and M are not supported.'); - (new MySQLBinaryStrategy())->executeStrategy($spatial); + (new MySQLBinaryStrategy())->encode($spatial); } /** Reject incompatible input instead of emitting a lossy or invalid value. */ @@ -182,7 +182,7 @@ public function testXyzmEmptyPoint(): void $spatial = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\Point(srid: 4326); $this->expectException(UnsupportedDimensionException::class); $this->expectExceptionMessage('MySQL adapter only supports XY coordinates; Z and M are not supported.'); - (new MySQLBinaryStrategy())->executeStrategy($spatial); + (new MySQLBinaryStrategy())->encode($spatial); } /** Reject incompatible input instead of emitting a lossy or invalid value. */ @@ -191,7 +191,7 @@ public function testXyzmPoint(): void $spatial = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\Point(1, 2, 3, 4, 4326); $this->expectException(UnsupportedDimensionException::class); $this->expectExceptionMessage('MySQL adapter only supports XY coordinates; Z and M are not supported.'); - (new MySQLBinaryStrategy())->executeStrategy($spatial); + (new MySQLBinaryStrategy())->encode($spatial); } /** Reject incompatible input instead of emitting a lossy or invalid value. */ @@ -200,6 +200,6 @@ public function testXyzPoint(): void $spatial = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\Point(1, 2, 3, 4326); $this->expectException(UnsupportedDimensionException::class); $this->expectExceptionMessage('MySQL adapter only supports XY coordinates; Z and M are not supported.'); - (new MySQLBinaryStrategy())->executeStrategy($spatial); + (new MySQLBinaryStrategy())->encode($spatial); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/MySQL/GeometryCoordinateOrderTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/MySQL/GeometryCoordinateOrderTest.php similarity index 87% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/MySQL/GeometryCoordinateOrderTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/MySQL/GeometryCoordinateOrderTest.php index 78cc5db..0efc64c 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/MySQL/GeometryCoordinateOrderTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/MySQL/GeometryCoordinateOrderTest.php @@ -1,6 +1,6 @@ executeStrategy($collection)) + bin2hex((new MySQLBinaryStrategy())->encode($collection)) ); } @@ -58,7 +58,7 @@ public function testGeometryCollectionEmpty(): void // Reference geometry in WKT: GEOMETRYCOLLECTION EMPTY static::assertSame( 'e6100000010700000000000000', - bin2hex((new MySQLBinaryStrategy())->executeStrategy($collection)) + bin2hex((new MySQLBinaryStrategy())->encode($collection)) ); } @@ -70,7 +70,7 @@ public function testLineString(): void // Reference geometry in WKT: LINESTRING (0 0, 2 3, 4 1) static::assertSame( 'e610000001020000000300000000000000000000000000000000000000000000000000004000000000000008400000000000001040000000000000f03f', - bin2hex((new MySQLBinaryStrategy())->executeStrategy($line)) + bin2hex((new MySQLBinaryStrategy())->encode($line)) ); } @@ -85,7 +85,7 @@ public function testMultiLineString(): void // Reference geometry in WKT: MULTILINESTRING ((0 0, 2 3), (4 1, 5 2)) static::assertSame( 'e610000001050000000200000001020000000200000000000000000000000000000000000000000000000000004000000000000008400102000000020000000000000000001040000000000000f03f00000000000014400000000000000040', - bin2hex((new MySQLBinaryStrategy())->executeStrategy($lines)) + bin2hex((new MySQLBinaryStrategy())->encode($lines)) ); } @@ -97,7 +97,7 @@ public function testMultiPoint(): void // Reference geometry in WKT: MULTIPOINT ((1 2), (3 4)) static::assertSame( 'e61000000104000000020000000101000000000000000000f03f0000000000000040010100000000000000000008400000000000001040', - bin2hex((new MySQLBinaryStrategy())->executeStrategy($points)) + bin2hex((new MySQLBinaryStrategy())->encode($points)) ); } @@ -112,7 +112,7 @@ public function testMultiPolygon(): void // Reference geometry in WKT: MULTIPOLYGON (((0 0, 2 0, 0 2, 0 0)), ((3 3, 5 3, 3 5, 3 3))) static::assertSame( 'e610000001060000000200000001030000000100000004000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000040000000000000000000000000000000000103000000010000000400000000000000000008400000000000000840000000000000144000000000000008400000000000000840000000000000144000000000000008400000000000000840', - bin2hex((new MySQLBinaryStrategy())->executeStrategy($polygons)) + bin2hex((new MySQLBinaryStrategy())->encode($polygons)) ); } @@ -125,7 +125,7 @@ public function testNestedCollection(): void ]); static::assertSame( 'e61000000107000000020000000101000000cdcccccccccc0240ae47e17a146e4840010700000001000000010700000000000000', - bin2hex((new MySQLBinaryStrategy())->executeStrategy($collection)) + bin2hex((new MySQLBinaryStrategy())->encode($collection)) ); } @@ -143,7 +143,7 @@ public function testNestedMultiLineStringWithEmptyCollection(): void static::assertSame( 'e610000001070000000200000001070000000000000001070000000100000001050000000200000001020000000200000000000000000000000000000000000000000000000000004000000000000008400102000000020000000000000000001040000000000000f03f00000000000014400000000000000040', - bin2hex((new MySQLBinaryStrategy())->executeStrategy($collection)) + bin2hex((new MySQLBinaryStrategy())->encode($collection)) ); } @@ -158,7 +158,7 @@ public function testNestedMultiPointWithEmptyCollection(): void static::assertSame( 'e61000000107000000020000000107000000000000000107000000010000000104000000020000000101000000000000000000f03f0000000000000040010100000000000000000008400000000000001040', - bin2hex((new MySQLBinaryStrategy())->executeStrategy($collection)) + bin2hex((new MySQLBinaryStrategy())->encode($collection)) ); } @@ -176,7 +176,7 @@ public function testNestedMultiPolygonWithEmptyCollection(): void static::assertSame( 'e610000001070000000200000001070000000000000001070000000100000001060000000200000001030000000100000004000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000040000000000000000000000000000000000103000000010000000400000000000000000008400000000000000840000000000000144000000000000008400000000000000840000000000000144000000000000008400000000000000840', - bin2hex((new MySQLBinaryStrategy())->executeStrategy($collection)) + bin2hex((new MySQLBinaryStrategy())->encode($collection)) ); } @@ -186,7 +186,7 @@ public function testParisPoint(): void $point = new Point(2.35, 48.86, 4326); static::assertSame( 'e61000000101000000cdcccccccccc0240ae47e17a146e4840', - bin2hex((new MySQLBinaryStrategy())->executeStrategy($point)) + bin2hex((new MySQLBinaryStrategy())->encode($point)) ); } @@ -198,7 +198,7 @@ public function testPoint(): void // Reference geometry in WKT: POINT (2.5 -3) static::assertSame( 'e61000000101000000000000000000044000000000000008c0', - bin2hex((new MySQLBinaryStrategy())->executeStrategy($point)) + bin2hex((new MySQLBinaryStrategy())->encode($point)) ); } @@ -213,7 +213,7 @@ public function testPolygon(): void // Reference geometry in WKT: POLYGON ((0 0, 4 0, 4 4, 0 4, 0 0), (1 1, 1 2, 2 2, 2 1, 1 1)) static::assertSame( 'e610000001030000000200000005000000000000000000000000000000000000000000000000001040000000000000000000000000000010400000000000001040000000000000000000000000000010400000000000000000000000000000000005000000000000000000f03f000000000000f03f000000000000f03f0000000000000040000000000000004000000000000000400000000000000040000000000000f03f000000000000f03f000000000000f03f', - bin2hex((new MySQLBinaryStrategy())->executeStrategy($polygon)) + bin2hex((new MySQLBinaryStrategy())->encode($polygon)) ); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/MySQL/GeometryInvalidInputTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/MySQL/GeometryInvalidInputTest.php similarity index 84% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/MySQL/GeometryInvalidInputTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/MySQL/GeometryInvalidInputTest.php index cbf1e1f..44fd076 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/MySQL/GeometryInvalidInputTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/MySQL/GeometryInvalidInputTest.php @@ -1,6 +1,6 @@ expectException(UnsupportedSpatialTypeException::class); $this->expectExceptionMessage('MySQL adapter does not support empty LineString; only GeometryCollection may be empty.'); - (new MySQLBinaryStrategy())->executeStrategy($spatial); + (new MySQLBinaryStrategy())->encode($spatial); } /** Reject incompatible input instead of emitting a lossy or invalid value. */ @@ -54,7 +54,7 @@ public function testEmptyMultiLineString(): void $spatial = new MultiLineString([], 4326); $this->expectException(UnsupportedSpatialTypeException::class); $this->expectExceptionMessage('MySQL adapter does not support empty MultiLineString; only GeometryCollection may be empty.'); - (new MySQLBinaryStrategy())->executeStrategy($spatial); + (new MySQLBinaryStrategy())->encode($spatial); } /** Reject incompatible input instead of emitting a lossy or invalid value. */ @@ -63,7 +63,7 @@ public function testEmptyMultiPoint(): void $spatial = new MultiPoint([], 4326); $this->expectException(UnsupportedSpatialTypeException::class); $this->expectExceptionMessage('MySQL adapter does not support empty MultiPoint; only GeometryCollection may be empty.'); - (new MySQLBinaryStrategy())->executeStrategy($spatial); + (new MySQLBinaryStrategy())->encode($spatial); } /** Reject incompatible input instead of emitting a lossy or invalid value. */ @@ -72,7 +72,7 @@ public function testEmptyMultiPolygon(): void $spatial = new MultiPolygon([], 4326); $this->expectException(UnsupportedSpatialTypeException::class); $this->expectExceptionMessage('MySQL adapter does not support empty MultiPolygon; only GeometryCollection may be empty.'); - (new MySQLBinaryStrategy())->executeStrategy($spatial); + (new MySQLBinaryStrategy())->encode($spatial); } /** Reject incompatible input instead of emitting a lossy or invalid value. */ @@ -81,7 +81,7 @@ public function testEmptyPoint(): void $spatial = new Point(srid: 4326); $this->expectException(UnsupportedSpatialTypeException::class); $this->expectExceptionMessage('MySQL adapter does not support empty Point; only GeometryCollection may be empty.'); - (new MySQLBinaryStrategy())->executeStrategy($spatial); + (new MySQLBinaryStrategy())->encode($spatial); } /** Reject incompatible input instead of emitting a lossy or invalid value. */ @@ -90,7 +90,7 @@ public function testEmptyPolygon(): void $spatial = new Polygon([], 4326); $this->expectException(UnsupportedSpatialTypeException::class); $this->expectExceptionMessage('MySQL adapter does not support empty Polygon; only GeometryCollection may be empty.'); - (new MySQLBinaryStrategy())->executeStrategy($spatial); + (new MySQLBinaryStrategy())->encode($spatial); } /** Reject incompatible input instead of emitting a lossy or invalid value. */ @@ -99,7 +99,7 @@ public function testMultiLineStringWithEmptyMember(): void $spatial = new MultiLineString([new LineString([], 4326)], 4326); $this->expectException(UnsupportedSpatialTypeException::class); $this->expectExceptionMessage('MySQL adapter does not support empty LineString; only GeometryCollection may be empty.'); - (new MySQLBinaryStrategy())->executeStrategy($spatial); + (new MySQLBinaryStrategy())->encode($spatial); } /** Reject incompatible input instead of emitting a lossy or invalid value. */ @@ -108,7 +108,7 @@ public function testMultiPolygonWithEmptyMember(): void $spatial = new MultiPolygon([new Polygon([], 4326)], 4326); $this->expectException(UnsupportedSpatialTypeException::class); $this->expectExceptionMessage('MySQL adapter does not support empty Polygon; only GeometryCollection may be empty.'); - (new MySQLBinaryStrategy())->executeStrategy($spatial); + (new MySQLBinaryStrategy())->encode($spatial); } /** Reject incompatible input instead of emitting a lossy or invalid value. */ @@ -119,7 +119,7 @@ public function testNestedEmptyPoint(): void ]); $this->expectException(UnsupportedSpatialTypeException::class); $this->expectExceptionMessage('MySQL adapter does not support empty Point; only GeometryCollection may be empty.'); - (new MySQLBinaryStrategy())->executeStrategy($spatial); + (new MySQLBinaryStrategy())->encode($spatial); } /** Reject incompatible input instead of emitting a lossy or invalid value. */ @@ -128,7 +128,7 @@ public function testXymEmptyCollection(): void $spatial = new GeometryCollection(4326, []); $this->expectException(UnsupportedDimensionException::class); $this->expectExceptionMessage('MySQL adapter only supports XY coordinates; Z and M are not supported.'); - (new MySQLBinaryStrategy())->executeStrategy($spatial); + (new MySQLBinaryStrategy())->encode($spatial); } /** Reject incompatible input instead of emitting a lossy or invalid value. */ @@ -137,7 +137,7 @@ public function testXymEmptyPoint(): void $spatial = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\Point(srid: 4326); $this->expectException(UnsupportedDimensionException::class); $this->expectExceptionMessage('MySQL adapter only supports XY coordinates; Z and M are not supported.'); - (new MySQLBinaryStrategy())->executeStrategy($spatial); + (new MySQLBinaryStrategy())->encode($spatial); } /** Reject incompatible input instead of emitting a lossy or invalid value. */ @@ -146,7 +146,7 @@ public function testXymPoint(): void $spatial = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\Point(1, 2, 4, 4326); $this->expectException(UnsupportedDimensionException::class); $this->expectExceptionMessage('MySQL adapter only supports XY coordinates; Z and M are not supported.'); - (new MySQLBinaryStrategy())->executeStrategy($spatial); + (new MySQLBinaryStrategy())->encode($spatial); } /** Reject incompatible input instead of emitting a lossy or invalid value. */ @@ -155,7 +155,7 @@ public function testXyzEmptyCollection(): void $spatial = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\GeometryCollection(4326, []); $this->expectException(UnsupportedDimensionException::class); $this->expectExceptionMessage('MySQL adapter only supports XY coordinates; Z and M are not supported.'); - (new MySQLBinaryStrategy())->executeStrategy($spatial); + (new MySQLBinaryStrategy())->encode($spatial); } /** Reject incompatible input instead of emitting a lossy or invalid value. */ @@ -164,7 +164,7 @@ public function testXyzEmptyPoint(): void $spatial = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\Point(srid: 4326); $this->expectException(UnsupportedDimensionException::class); $this->expectExceptionMessage('MySQL adapter only supports XY coordinates; Z and M are not supported.'); - (new MySQLBinaryStrategy())->executeStrategy($spatial); + (new MySQLBinaryStrategy())->encode($spatial); } /** Reject incompatible input instead of emitting a lossy or invalid value. */ @@ -173,7 +173,7 @@ public function testXyzmEmptyCollection(): void $spatial = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\GeometryCollection(4326, []); $this->expectException(UnsupportedDimensionException::class); $this->expectExceptionMessage('MySQL adapter only supports XY coordinates; Z and M are not supported.'); - (new MySQLBinaryStrategy())->executeStrategy($spatial); + (new MySQLBinaryStrategy())->encode($spatial); } /** Reject incompatible input instead of emitting a lossy or invalid value. */ @@ -182,7 +182,7 @@ public function testXyzmEmptyPoint(): void $spatial = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\Point(srid: 4326); $this->expectException(UnsupportedDimensionException::class); $this->expectExceptionMessage('MySQL adapter only supports XY coordinates; Z and M are not supported.'); - (new MySQLBinaryStrategy())->executeStrategy($spatial); + (new MySQLBinaryStrategy())->encode($spatial); } /** Reject incompatible input instead of emitting a lossy or invalid value. */ @@ -191,7 +191,7 @@ public function testXyzmPoint(): void $spatial = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\Point(1, 2, 3, 4, 4326); $this->expectException(UnsupportedDimensionException::class); $this->expectExceptionMessage('MySQL adapter only supports XY coordinates; Z and M are not supported.'); - (new MySQLBinaryStrategy())->executeStrategy($spatial); + (new MySQLBinaryStrategy())->encode($spatial); } /** Reject incompatible input instead of emitting a lossy or invalid value. */ @@ -200,6 +200,6 @@ public function testXyzPoint(): void $spatial = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\Point(1, 2, 3, 4326); $this->expectException(UnsupportedDimensionException::class); $this->expectExceptionMessage('MySQL adapter only supports XY coordinates; Z and M are not supported.'); - (new MySQLBinaryStrategy())->executeStrategy($spatial); + (new MySQLBinaryStrategy())->encode($spatial); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/MySQLStrategyTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/MySQLStrategyTest.php similarity index 95% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/MySQLStrategyTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/MySQLStrategyTest.php index 64eba5e..88a50e0 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/MySQLStrategyTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/MySQLStrategyTest.php @@ -1,6 +1,6 @@ strategy->executeStrategy($collection)))); + static::assertSame($expected, mb_strtoupper(bin2hex($this->strategy->encode($collection)))); } /** @@ -133,13 +133,13 @@ public static function collectionProvider(): \Generator /** * Let's check the MySQL strategy with a linestring. * - * @param LineStringInterface $lineString the linestring to convert + * @param LineStringInterface $lineString the linestring to encode * @param string $expected the expected result in hexadecimal format */ #[DataProvider('lineStringProvider')] public function testLineString(LineStringInterface $lineString, string $expected): void { - static::assertSame($expected, mb_strtoupper(bin2hex($this->strategy->executeStrategy($lineString)))); + static::assertSame($expected, mb_strtoupper(bin2hex($this->strategy->encode($lineString)))); } /** @@ -173,13 +173,13 @@ public static function lineStringProvider(): \Generator /** * Let's check the MySQL strategy with a multilinestring. * - * @param MultiLineStringInterface $multiLineString the multilinestring to convert + * @param MultiLineStringInterface $multiLineString the multilinestring to encode * @param string $expected the expected result in hexadecimal format */ #[DataProvider('multiLineStringProvider')] public function testMultiLineString(MultiLineStringInterface $multiLineString, string $expected): void { - static::assertSame($expected, mb_strtoupper(bin2hex($this->strategy->executeStrategy($multiLineString)))); + static::assertSame($expected, mb_strtoupper(bin2hex($this->strategy->encode($multiLineString)))); } /** @@ -204,13 +204,13 @@ public static function multiLineStringProvider(): \Generator /** * Let's check the MySQL strategy with a multipoint. * - * @param MultiPointInterface $multiPoint the multipoint to convert + * @param MultiPointInterface $multiPoint the multipoint to encode * @param string $expected the expected result in hexadecimal format */ #[DataProvider('multiPointProvider')] public function testMultiPoint(MultiPointInterface $multiPoint, string $expected): void { - static::assertSame($expected, mb_strtoupper(bin2hex($this->strategy->executeStrategy($multiPoint)))); + static::assertSame($expected, mb_strtoupper(bin2hex($this->strategy->encode($multiPoint)))); } /** @@ -232,13 +232,13 @@ public static function multiPointProvider(): \Generator /** * Let's check the MySQL strategy with a multipolygon. * - * @param MultiPolygonInterface $multiPolygon the multipolygon to convert + * @param MultiPolygonInterface $multiPolygon the multipolygon to encode * @param string $expected the expected result in hexadecimal format */ #[DataProvider('multiPolygonProvider')] public function testMultiPolygon(MultiPolygonInterface $multiPolygon, string $expected): void { - static::assertSame($expected, mb_strtoupper(bin2hex($this->strategy->executeStrategy($multiPolygon)))); + static::assertSame($expected, mb_strtoupper(bin2hex($this->strategy->encode($multiPolygon)))); } /** @@ -263,13 +263,13 @@ public static function multiPolygonProvider(): \Generator /** * Let's check the MySQL strategy with a point. * - * @param PointInterface $point the point to convert + * @param PointInterface $point the point to encode * @param string $expected the expected result in hexadecimal format */ #[DataProvider('pointProvider')] public function testPoint(PointInterface $point, string $expected): void { - static::assertSame($expected, mb_strtoupper(bin2hex($this->strategy->executeStrategy($point)))); + static::assertSame($expected, mb_strtoupper(bin2hex($this->strategy->encode($point)))); } /** @@ -315,13 +315,13 @@ public static function pointProvider(): \Generator /** * Let's check the MySQL strategy with a polygon. * - * @param PolygonInterface $polygon the polygon to convert + * @param PolygonInterface $polygon the polygon to encode * @param string $expected the expected result in hexadecimal format */ #[DataProvider('polygonProvider')] public function testPolygon(PolygonInterface $polygon, string $expected): void { - static::assertSame($expected, mb_strtoupper(bin2hex($this->strategy->executeStrategy($polygon)))); + static::assertSame($expected, mb_strtoupper(bin2hex($this->strategy->encode($polygon)))); } /** diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkb/Examples/GeographyXyTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkb/Examples/GeographyXyTest.php similarity index 84% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkb/Examples/GeographyXyTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkb/Examples/GeographyXyTest.php index 342ce84..cdedd83 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkb/Examples/GeographyXyTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkb/Examples/GeographyXyTest.php @@ -1,6 +1,6 @@ executeStrategy($collection)) + bin2hex((new WkbBinaryStrategy())->encode($collection)) ); } @@ -61,7 +61,7 @@ public function testGeographyCollectionEmpty(): void // Reference geometry in WKT: GEOMETRYCOLLECTION EMPTY static::assertSame( '010700000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($collection)) + bin2hex((new WkbBinaryStrategy())->encode($collection)) ); } @@ -73,7 +73,7 @@ public function testLineString(): void // Reference geometry in WKT: LINESTRING (0 0, 2 3, 4 1) static::assertSame( '01020000000300000000000000000000000000000000000000000000000000004000000000000008400000000000001040000000000000f03f', - bin2hex((new WkbBinaryStrategy())->executeStrategy($line)) + bin2hex((new WkbBinaryStrategy())->encode($line)) ); } @@ -85,7 +85,7 @@ public function testLineStringEmpty(): void // Reference geometry in WKT: LINESTRING EMPTY static::assertSame( '010200000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($line)) + bin2hex((new WkbBinaryStrategy())->encode($line)) ); } @@ -100,7 +100,7 @@ public function testMultiLineString(): void // Reference geometry in WKT: MULTILINESTRING ((0 0, 2 3), (4 1, 5 2)) static::assertSame( '01050000000200000001020000000200000000000000000000000000000000000000000000000000004000000000000008400102000000020000000000000000001040000000000000f03f00000000000014400000000000000040', - bin2hex((new WkbBinaryStrategy())->executeStrategy($lines)) + bin2hex((new WkbBinaryStrategy())->encode($lines)) ); } @@ -112,7 +112,7 @@ public function testMultiLineStringEmpty(): void // Reference geometry in WKT: MULTILINESTRING EMPTY static::assertSame( '010500000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($lines)) + bin2hex((new WkbBinaryStrategy())->encode($lines)) ); } @@ -124,7 +124,7 @@ public function testMultiPoint(): void // Reference geometry in WKT: MULTIPOINT ((1 2), (3 4)) static::assertSame( '0104000000020000000101000000000000000000f03f0000000000000040010100000000000000000008400000000000001040', - bin2hex((new WkbBinaryStrategy())->executeStrategy($points)) + bin2hex((new WkbBinaryStrategy())->encode($points)) ); } @@ -136,7 +136,7 @@ public function testMultiPointEmpty(): void // Reference geometry in WKT: MULTIPOINT EMPTY static::assertSame( '010400000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($points)) + bin2hex((new WkbBinaryStrategy())->encode($points)) ); } @@ -151,7 +151,7 @@ public function testMultiPolygon(): void // Reference geometry in WKT: MULTIPOLYGON (((0 0, 2 0, 0 2, 0 0)), ((3 3, 5 3, 3 5, 3 3))) static::assertSame( '01060000000200000001030000000100000004000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000040000000000000000000000000000000000103000000010000000400000000000000000008400000000000000840000000000000144000000000000008400000000000000840000000000000144000000000000008400000000000000840', - bin2hex((new WkbBinaryStrategy())->executeStrategy($polygons)) + bin2hex((new WkbBinaryStrategy())->encode($polygons)) ); } @@ -163,7 +163,7 @@ public function testMultiPolygonEmpty(): void // Reference geometry in WKT: MULTIPOLYGON EMPTY static::assertSame( '010600000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($polygons)) + bin2hex((new WkbBinaryStrategy())->encode($polygons)) ); } @@ -175,7 +175,7 @@ public function testPoint(): void // Reference geometry in WKT: POINT (2.5 -3) static::assertSame( '0101000000000000000000044000000000000008c0', - bin2hex((new WkbBinaryStrategy())->executeStrategy($point)) + bin2hex((new WkbBinaryStrategy())->encode($point)) ); } @@ -187,7 +187,7 @@ public function testPointEmpty(): void // Reference geometry in WKT: POINT EMPTY static::assertSame( '0101000000000000000000f87f000000000000f87f', - bin2hex((new WkbBinaryStrategy())->executeStrategy($point)) + bin2hex((new WkbBinaryStrategy())->encode($point)) ); } @@ -202,7 +202,7 @@ public function testPolygon(): void // Reference geometry in WKT: POLYGON ((0 0, 4 0, 4 4, 0 4, 0 0), (1 1, 1 2, 2 2, 2 1, 1 1)) static::assertSame( '01030000000200000005000000000000000000000000000000000000000000000000001040000000000000000000000000000010400000000000001040000000000000000000000000000010400000000000000000000000000000000005000000000000000000f03f000000000000f03f000000000000f03f0000000000000040000000000000004000000000000000400000000000000040000000000000f03f000000000000f03f000000000000f03f', - bin2hex((new WkbBinaryStrategy())->executeStrategy($polygon)) + bin2hex((new WkbBinaryStrategy())->encode($polygon)) ); } @@ -214,7 +214,7 @@ public function testPolygonEmpty(): void // Reference geometry in WKT: POLYGON EMPTY static::assertSame( '010300000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($polygon)) + bin2hex((new WkbBinaryStrategy())->encode($polygon)) ); } @@ -226,7 +226,7 @@ public function testTriangle(): void // Reference geometry in WKT: TRIANGLE ((0 0, 2 0, 0 2, 0 0)) static::assertSame( '0111000000010000000400000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000004000000000000000000000000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($triangle)) + bin2hex((new WkbBinaryStrategy())->encode($triangle)) ); } @@ -238,7 +238,7 @@ public function testTriangleEmpty(): void // Reference geometry in WKT: TRIANGLE EMPTY static::assertSame( '011100000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($triangle)) + bin2hex((new WkbBinaryStrategy())->encode($triangle)) ); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkb/Examples/GeographyXymTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkb/Examples/GeographyXymTest.php similarity index 86% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkb/Examples/GeographyXymTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkb/Examples/GeographyXymTest.php index 955432a..db0faec 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkb/Examples/GeographyXymTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkb/Examples/GeographyXymTest.php @@ -1,6 +1,6 @@ executeStrategy($collection)) + bin2hex((new WkbBinaryStrategy())->encode($collection)) ); } @@ -64,7 +64,7 @@ public function testGeographyCollectionEmpty(): void // Reference geometry in WKT: GEOMETRYCOLLECTION M EMPTY static::assertSame( '01d707000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($collection)) + bin2hex((new WkbBinaryStrategy())->encode($collection)) ); } @@ -76,7 +76,7 @@ public function testLineString(): void // Reference geometry in WKT: LINESTRING M (0 0 10, 2 3 20, 4 1 30) static::assertSame( '01d2070000030000000000000000000000000000000000000000000000000024400000000000000040000000000000084000000000000034400000000000001040000000000000f03f0000000000003e40', - bin2hex((new WkbBinaryStrategy())->executeStrategy($line)) + bin2hex((new WkbBinaryStrategy())->encode($line)) ); } @@ -88,7 +88,7 @@ public function testLineStringEmpty(): void // Reference geometry in WKT: LINESTRING M EMPTY static::assertSame( '01d207000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($line)) + bin2hex((new WkbBinaryStrategy())->encode($line)) ); } @@ -103,7 +103,7 @@ public function testMultiLineString(): void // Reference geometry in WKT: MULTILINESTRING M ((0 0 10, 2 3 20), (4 1 30, 5 2 40)) static::assertSame( '01d50700000200000001d20700000200000000000000000000000000000000000000000000000000244000000000000000400000000000000840000000000000344001d2070000020000000000000000001040000000000000f03f0000000000003e40000000000000144000000000000000400000000000004440', - bin2hex((new WkbBinaryStrategy())->executeStrategy($lines)) + bin2hex((new WkbBinaryStrategy())->encode($lines)) ); } @@ -115,7 +115,7 @@ public function testMultiLineStringEmpty(): void // Reference geometry in WKT: MULTILINESTRING M EMPTY static::assertSame( '01d507000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($lines)) + bin2hex((new WkbBinaryStrategy())->encode($lines)) ); } @@ -127,7 +127,7 @@ public function testMultiPoint(): void // Reference geometry in WKT: MULTIPOINT M ((1 2 10), (3 4 20)) static::assertSame( '01d40700000200000001d1070000000000000000f03f0000000000000040000000000000244001d1070000000000000000084000000000000010400000000000003440', - bin2hex((new WkbBinaryStrategy())->executeStrategy($points)) + bin2hex((new WkbBinaryStrategy())->encode($points)) ); } @@ -139,7 +139,7 @@ public function testMultiPointEmpty(): void // Reference geometry in WKT: MULTIPOINT M EMPTY static::assertSame( '01d407000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($points)) + bin2hex((new WkbBinaryStrategy())->encode($points)) ); } @@ -154,7 +154,7 @@ public function testMultiPolygon(): void // Reference geometry in WKT: MULTIPOLYGON M (((0 0 10, 2 0 10, 0 2 10, 0 0 10)), ((3 3 20, 5 3 20, 3 5 20, 3 3 20))) static::assertSame( '01d60700000200000001d3070000010000000400000000000000000000000000000000000000000000000000244000000000000000400000000000000000000000000000244000000000000000000000000000000040000000000000244000000000000000000000000000000000000000000000244001d30700000100000004000000000000000000084000000000000008400000000000003440000000000000144000000000000008400000000000003440000000000000084000000000000014400000000000003440000000000000084000000000000008400000000000003440', - bin2hex((new WkbBinaryStrategy())->executeStrategy($polygons)) + bin2hex((new WkbBinaryStrategy())->encode($polygons)) ); } @@ -166,7 +166,7 @@ public function testMultiPolygonEmpty(): void // Reference geometry in WKT: MULTIPOLYGON M EMPTY static::assertSame( '01d607000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($polygons)) + bin2hex((new WkbBinaryStrategy())->encode($polygons)) ); } @@ -178,7 +178,7 @@ public function testPoint(): void // Reference geometry in WKT: POINT M (2.5 -3 10) static::assertSame( '01d1070000000000000000044000000000000008c00000000000002440', - bin2hex((new WkbBinaryStrategy())->executeStrategy($point)) + bin2hex((new WkbBinaryStrategy())->encode($point)) ); } @@ -190,7 +190,7 @@ public function testPointEmpty(): void // Reference geometry in WKT: POINT M EMPTY static::assertSame( '01d1070000000000000000f87f000000000000f87f000000000000f87f', - bin2hex((new WkbBinaryStrategy())->executeStrategy($point)) + bin2hex((new WkbBinaryStrategy())->encode($point)) ); } @@ -205,7 +205,7 @@ public function testPolygon(): void // Reference geometry in WKT: POLYGON M ((0 0 10, 4 0 10, 4 4 10, 0 4 10, 0 0 10), (1 1 10, 1 2 10, 2 2 10, 2 1 10, 1 1 10)) static::assertSame( '01d3070000020000000500000000000000000000000000000000000000000000000000244000000000000010400000000000000000000000000000244000000000000010400000000000001040000000000000244000000000000000000000000000001040000000000000244000000000000000000000000000000000000000000000244005000000000000000000f03f000000000000f03f0000000000002440000000000000f03f000000000000004000000000000024400000000000000040000000000000004000000000000024400000000000000040000000000000f03f0000000000002440000000000000f03f000000000000f03f0000000000002440', - bin2hex((new WkbBinaryStrategy())->executeStrategy($polygon)) + bin2hex((new WkbBinaryStrategy())->encode($polygon)) ); } @@ -217,7 +217,7 @@ public function testPolygonEmpty(): void // Reference geometry in WKT: POLYGON M EMPTY static::assertSame( '01d307000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($polygon)) + bin2hex((new WkbBinaryStrategy())->encode($polygon)) ); } @@ -229,7 +229,7 @@ public function testTriangle(): void // Reference geometry in WKT: TRIANGLE M ((0 0 10, 2 0 10, 0 2 10, 0 0 10)) static::assertSame( '01e10700000100000004000000000000000000000000000000000000000000000000002440000000000000004000000000000000000000000000002440000000000000000000000000000000400000000000002440000000000000000000000000000000000000000000002440', - bin2hex((new WkbBinaryStrategy())->executeStrategy($triangle)) + bin2hex((new WkbBinaryStrategy())->encode($triangle)) ); } @@ -241,7 +241,7 @@ public function testTriangleEmpty(): void // Reference geometry in WKT: TRIANGLE M EMPTY static::assertSame( '01e107000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($triangle)) + bin2hex((new WkbBinaryStrategy())->encode($triangle)) ); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkb/Examples/GeographyXyzTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkb/Examples/GeographyXyzTest.php similarity index 86% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkb/Examples/GeographyXyzTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkb/Examples/GeographyXyzTest.php index 12e84fb..c064180 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkb/Examples/GeographyXyzTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkb/Examples/GeographyXyzTest.php @@ -1,6 +1,6 @@ executeStrategy($collection)) + bin2hex((new WkbBinaryStrategy())->encode($collection)) ); } @@ -62,7 +62,7 @@ public function testGeographyCollectionEmpty(): void // Reference geometry in WKT: GEOMETRYCOLLECTION Z EMPTY static::assertSame( '01ef03000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($collection)) + bin2hex((new WkbBinaryStrategy())->encode($collection)) ); } @@ -74,7 +74,7 @@ public function testLineString(): void // Reference geometry in WKT: LINESTRING Z (0 0 5, 2 3 6, 4 1 7) static::assertSame( '01ea030000030000000000000000000000000000000000000000000000000014400000000000000040000000000000084000000000000018400000000000001040000000000000f03f0000000000001c40', - bin2hex((new WkbBinaryStrategy())->executeStrategy($line)) + bin2hex((new WkbBinaryStrategy())->encode($line)) ); } @@ -86,7 +86,7 @@ public function testLineStringEmpty(): void // Reference geometry in WKT: LINESTRING Z EMPTY static::assertSame( '01ea03000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($line)) + bin2hex((new WkbBinaryStrategy())->encode($line)) ); } @@ -101,7 +101,7 @@ public function testMultiLineString(): void // Reference geometry in WKT: MULTILINESTRING Z ((0 0 5, 2 3 6), (4 1 7, 5 2 8)) static::assertSame( '01ed0300000200000001ea0300000200000000000000000000000000000000000000000000000000144000000000000000400000000000000840000000000000184001ea030000020000000000000000001040000000000000f03f0000000000001c40000000000000144000000000000000400000000000002040', - bin2hex((new WkbBinaryStrategy())->executeStrategy($lines)) + bin2hex((new WkbBinaryStrategy())->encode($lines)) ); } @@ -113,7 +113,7 @@ public function testMultiLineStringEmpty(): void // Reference geometry in WKT: MULTILINESTRING Z EMPTY static::assertSame( '01ed03000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($lines)) + bin2hex((new WkbBinaryStrategy())->encode($lines)) ); } @@ -125,7 +125,7 @@ public function testMultiPoint(): void // Reference geometry in WKT: MULTIPOINT Z ((1 2 5), (3 4 6)) static::assertSame( '01ec0300000200000001e9030000000000000000f03f0000000000000040000000000000144001e9030000000000000000084000000000000010400000000000001840', - bin2hex((new WkbBinaryStrategy())->executeStrategy($points)) + bin2hex((new WkbBinaryStrategy())->encode($points)) ); } @@ -137,7 +137,7 @@ public function testMultiPointEmpty(): void // Reference geometry in WKT: MULTIPOINT Z EMPTY static::assertSame( '01ec03000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($points)) + bin2hex((new WkbBinaryStrategy())->encode($points)) ); } @@ -152,7 +152,7 @@ public function testMultiPolygon(): void // Reference geometry in WKT: MULTIPOLYGON Z (((0 0 5, 2 0 5, 0 2 5, 0 0 5)), ((3 3 6, 5 3 6, 3 5 6, 3 3 6))) static::assertSame( '01ee0300000200000001eb030000010000000400000000000000000000000000000000000000000000000000144000000000000000400000000000000000000000000000144000000000000000000000000000000040000000000000144000000000000000000000000000000000000000000000144001eb0300000100000004000000000000000000084000000000000008400000000000001840000000000000144000000000000008400000000000001840000000000000084000000000000014400000000000001840000000000000084000000000000008400000000000001840', - bin2hex((new WkbBinaryStrategy())->executeStrategy($polygons)) + bin2hex((new WkbBinaryStrategy())->encode($polygons)) ); } @@ -164,7 +164,7 @@ public function testMultiPolygonEmpty(): void // Reference geometry in WKT: MULTIPOLYGON Z EMPTY static::assertSame( '01ee03000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($polygons)) + bin2hex((new WkbBinaryStrategy())->encode($polygons)) ); } @@ -176,7 +176,7 @@ public function testPoint(): void // Reference geometry in WKT: POINT Z (2.5 -3 5) static::assertSame( '01e9030000000000000000044000000000000008c00000000000001440', - bin2hex((new WkbBinaryStrategy())->executeStrategy($point)) + bin2hex((new WkbBinaryStrategy())->encode($point)) ); } @@ -188,7 +188,7 @@ public function testPointEmpty(): void // Reference geometry in WKT: POINT Z EMPTY static::assertSame( '01e9030000000000000000f87f000000000000f87f000000000000f87f', - bin2hex((new WkbBinaryStrategy())->executeStrategy($point)) + bin2hex((new WkbBinaryStrategy())->encode($point)) ); } @@ -203,7 +203,7 @@ public function testPolygon(): void // Reference geometry in WKT: POLYGON Z ((0 0 5, 4 0 5, 4 4 5, 0 4 5, 0 0 5), (1 1 5, 1 2 5, 2 2 5, 2 1 5, 1 1 5)) static::assertSame( '01eb030000020000000500000000000000000000000000000000000000000000000000144000000000000010400000000000000000000000000000144000000000000010400000000000001040000000000000144000000000000000000000000000001040000000000000144000000000000000000000000000000000000000000000144005000000000000000000f03f000000000000f03f0000000000001440000000000000f03f000000000000004000000000000014400000000000000040000000000000004000000000000014400000000000000040000000000000f03f0000000000001440000000000000f03f000000000000f03f0000000000001440', - bin2hex((new WkbBinaryStrategy())->executeStrategy($polygon)) + bin2hex((new WkbBinaryStrategy())->encode($polygon)) ); } @@ -215,7 +215,7 @@ public function testPolygonEmpty(): void // Reference geometry in WKT: POLYGON Z EMPTY static::assertSame( '01eb03000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($polygon)) + bin2hex((new WkbBinaryStrategy())->encode($polygon)) ); } @@ -230,7 +230,7 @@ public function testPolyhedralSurface(): void // Reference geometry in WKT: POLYHEDRALSURFACE Z (((0 0 5, 1 0 5, 1 1 5, 0 1 5, 0 0 5)), ((1 0 5, 2 0 5, 2 1 5, 1 1 5, 1 0 5))) static::assertSame( '01f70300000200000001eb0300000100000005000000000000000000000000000000000000000000000000001440000000000000f03f00000000000000000000000000001440000000000000f03f000000000000f03f00000000000014400000000000000000000000000000f03f000000000000144000000000000000000000000000000000000000000000144001eb0300000100000005000000000000000000f03f000000000000000000000000000014400000000000000040000000000000000000000000000014400000000000000040000000000000f03f0000000000001440000000000000f03f000000000000f03f0000000000001440000000000000f03f00000000000000000000000000001440', - bin2hex((new WkbBinaryStrategy())->executeStrategy($surface)) + bin2hex((new WkbBinaryStrategy())->encode($surface)) ); } @@ -242,7 +242,7 @@ public function testPolyhedralSurfaceEmpty(): void // Reference geometry in WKT: POLYHEDRALSURFACE Z EMPTY static::assertSame( '01f703000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($surface)) + bin2hex((new WkbBinaryStrategy())->encode($surface)) ); } @@ -254,7 +254,7 @@ public function testTriangle(): void // Reference geometry in WKT: TRIANGLE Z ((0 0 5, 2 0 5, 0 2 5, 0 0 5)) static::assertSame( '01f90300000100000004000000000000000000000000000000000000000000000000001440000000000000004000000000000000000000000000001440000000000000000000000000000000400000000000001440000000000000000000000000000000000000000000001440', - bin2hex((new WkbBinaryStrategy())->executeStrategy($triangle)) + bin2hex((new WkbBinaryStrategy())->encode($triangle)) ); } @@ -266,7 +266,7 @@ public function testTriangleEmpty(): void // Reference geometry in WKT: TRIANGLE Z EMPTY static::assertSame( '01f903000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($triangle)) + bin2hex((new WkbBinaryStrategy())->encode($triangle)) ); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkb/Examples/GeographyXyzmTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkb/Examples/GeographyXyzmTest.php similarity index 87% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkb/Examples/GeographyXyzmTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkb/Examples/GeographyXyzmTest.php index e261b2f..ed8cc2f 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkb/Examples/GeographyXyzmTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkb/Examples/GeographyXyzmTest.php @@ -1,6 +1,6 @@ executeStrategy($collection)) + bin2hex((new WkbBinaryStrategy())->encode($collection)) ); } @@ -62,7 +62,7 @@ public function testGeographyCollectionEmpty(): void // Reference geometry in WKT: GEOMETRYCOLLECTION ZM EMPTY static::assertSame( '01bf0b000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($collection)) + bin2hex((new WkbBinaryStrategy())->encode($collection)) ); } @@ -74,7 +74,7 @@ public function testLineString(): void // Reference geometry in WKT: LINESTRING ZM (0 0 5 10, 2 3 6 20, 4 1 7 30) static::assertSame( '01ba0b000003000000000000000000000000000000000000000000000000001440000000000000244000000000000000400000000000000840000000000000184000000000000034400000000000001040000000000000f03f0000000000001c400000000000003e40', - bin2hex((new WkbBinaryStrategy())->executeStrategy($line)) + bin2hex((new WkbBinaryStrategy())->encode($line)) ); } @@ -86,7 +86,7 @@ public function testLineStringEmpty(): void // Reference geometry in WKT: LINESTRING ZM EMPTY static::assertSame( '01ba0b000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($line)) + bin2hex((new WkbBinaryStrategy())->encode($line)) ); } @@ -101,7 +101,7 @@ public function testMultiLineString(): void // Reference geometry in WKT: MULTILINESTRING ZM ((0 0 5 10, 2 3 6 20), (4 1 7 30, 5 2 8 40)) static::assertSame( '01bd0b00000200000001ba0b0000020000000000000000000000000000000000000000000000000014400000000000002440000000000000004000000000000008400000000000001840000000000000344001ba0b0000020000000000000000001040000000000000f03f0000000000001c400000000000003e400000000000001440000000000000004000000000000020400000000000004440', - bin2hex((new WkbBinaryStrategy())->executeStrategy($lines)) + bin2hex((new WkbBinaryStrategy())->encode($lines)) ); } @@ -113,7 +113,7 @@ public function testMultiLineStringEmpty(): void // Reference geometry in WKT: MULTILINESTRING ZM EMPTY static::assertSame( '01bd0b000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($lines)) + bin2hex((new WkbBinaryStrategy())->encode($lines)) ); } @@ -125,7 +125,7 @@ public function testMultiPoint(): void // Reference geometry in WKT: MULTIPOINT ZM ((1 2 5 10), (3 4 6 20)) static::assertSame( '01bc0b00000200000001b90b0000000000000000f03f00000000000000400000000000001440000000000000244001b90b00000000000000000840000000000000104000000000000018400000000000003440', - bin2hex((new WkbBinaryStrategy())->executeStrategy($points)) + bin2hex((new WkbBinaryStrategy())->encode($points)) ); } @@ -137,7 +137,7 @@ public function testMultiPointEmpty(): void // Reference geometry in WKT: MULTIPOINT ZM EMPTY static::assertSame( '01bc0b000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($points)) + bin2hex((new WkbBinaryStrategy())->encode($points)) ); } @@ -152,7 +152,7 @@ public function testMultiPolygon(): void // Reference geometry in WKT: MULTIPOLYGON ZM (((0 0 5 10, 2 0 5 10, 0 2 5 10, 0 0 5 10)), ((3 3 6 20, 5 3 6 20, 3 5 6 20, 3 3 6 20))) static::assertSame( '01be0b00000200000001bb0b00000100000004000000000000000000000000000000000000000000000000001440000000000000244000000000000000400000000000000000000000000000144000000000000024400000000000000000000000000000004000000000000014400000000000002440000000000000000000000000000000000000000000001440000000000000244001bb0b000001000000040000000000000000000840000000000000084000000000000018400000000000003440000000000000144000000000000008400000000000001840000000000000344000000000000008400000000000001440000000000000184000000000000034400000000000000840000000000000084000000000000018400000000000003440', - bin2hex((new WkbBinaryStrategy())->executeStrategy($polygons)) + bin2hex((new WkbBinaryStrategy())->encode($polygons)) ); } @@ -164,7 +164,7 @@ public function testMultiPolygonEmpty(): void // Reference geometry in WKT: MULTIPOLYGON ZM EMPTY static::assertSame( '01be0b000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($polygons)) + bin2hex((new WkbBinaryStrategy())->encode($polygons)) ); } @@ -176,7 +176,7 @@ public function testPoint(): void // Reference geometry in WKT: POINT ZM (2.5 -3 5 10) static::assertSame( '01b90b0000000000000000044000000000000008c000000000000014400000000000002440', - bin2hex((new WkbBinaryStrategy())->executeStrategy($point)) + bin2hex((new WkbBinaryStrategy())->encode($point)) ); } @@ -188,7 +188,7 @@ public function testPointEmpty(): void // Reference geometry in WKT: POINT ZM EMPTY static::assertSame( '01b90b0000000000000000f87f000000000000f87f000000000000f87f000000000000f87f', - bin2hex((new WkbBinaryStrategy())->executeStrategy($point)) + bin2hex((new WkbBinaryStrategy())->encode($point)) ); } @@ -203,7 +203,7 @@ public function testPolygon(): void // Reference geometry in WKT: POLYGON ZM ((0 0 5 10, 4 0 5 10, 4 4 5 10, 0 4 5 10, 0 0 5 10), (1 1 5 10, 1 2 5 10, 2 2 5 10, 2 1 5 10, 1 1 5 10)) static::assertSame( '01bb0b000002000000050000000000000000000000000000000000000000000000000014400000000000002440000000000000104000000000000000000000000000001440000000000000244000000000000010400000000000001040000000000000144000000000000024400000000000000000000000000000104000000000000014400000000000002440000000000000000000000000000000000000000000001440000000000000244005000000000000000000f03f000000000000f03f00000000000014400000000000002440000000000000f03f00000000000000400000000000001440000000000000244000000000000000400000000000000040000000000000144000000000000024400000000000000040000000000000f03f00000000000014400000000000002440000000000000f03f000000000000f03f00000000000014400000000000002440', - bin2hex((new WkbBinaryStrategy())->executeStrategy($polygon)) + bin2hex((new WkbBinaryStrategy())->encode($polygon)) ); } @@ -215,7 +215,7 @@ public function testPolygonEmpty(): void // Reference geometry in WKT: POLYGON ZM EMPTY static::assertSame( '01bb0b000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($polygon)) + bin2hex((new WkbBinaryStrategy())->encode($polygon)) ); } @@ -230,7 +230,7 @@ public function testPolyhedralSurface(): void // Reference geometry in WKT: POLYHEDRALSURFACE ZM (((0 0 5 10, 1 0 5 10, 1 1 5 10, 0 1 5 10, 0 0 5 10)), ((1 0 5 10, 2 0 5 10, 2 1 5 10, 1 1 5 10, 1 0 5 10))) static::assertSame( '01c70b00000200000001bb0b000001000000050000000000000000000000000000000000000000000000000014400000000000002440000000000000f03f000000000000000000000000000014400000000000002440000000000000f03f000000000000f03f000000000000144000000000000024400000000000000000000000000000f03f00000000000014400000000000002440000000000000000000000000000000000000000000001440000000000000244001bb0b00000100000005000000000000000000f03f00000000000000000000000000001440000000000000244000000000000000400000000000000000000000000000144000000000000024400000000000000040000000000000f03f00000000000014400000000000002440000000000000f03f000000000000f03f00000000000014400000000000002440000000000000f03f000000000000000000000000000014400000000000002440', - bin2hex((new WkbBinaryStrategy())->executeStrategy($surface)) + bin2hex((new WkbBinaryStrategy())->encode($surface)) ); } @@ -242,7 +242,7 @@ public function testPolyhedralSurfaceEmpty(): void // Reference geometry in WKT: POLYHEDRALSURFACE ZM EMPTY static::assertSame( '01c70b000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($surface)) + bin2hex((new WkbBinaryStrategy())->encode($surface)) ); } @@ -254,7 +254,7 @@ public function testTriangle(): void // Reference geometry in WKT: TRIANGLE ZM ((0 0 5 10, 2 0 5 10, 0 2 5 10, 0 0 5 10)) static::assertSame( '01c90b000001000000040000000000000000000000000000000000000000000000000014400000000000002440000000000000004000000000000000000000000000001440000000000000244000000000000000000000000000000040000000000000144000000000000024400000000000000000000000000000000000000000000014400000000000002440', - bin2hex((new WkbBinaryStrategy())->executeStrategy($triangle)) + bin2hex((new WkbBinaryStrategy())->encode($triangle)) ); } @@ -266,7 +266,7 @@ public function testTriangleEmpty(): void // Reference geometry in WKT: TRIANGLE ZM EMPTY static::assertSame( '01c90b000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($triangle)) + bin2hex((new WkbBinaryStrategy())->encode($triangle)) ); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkb/Examples/GeometryXyTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkb/Examples/GeometryXyTest.php similarity index 84% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkb/Examples/GeometryXyTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkb/Examples/GeometryXyTest.php index a1dcfa3..fe2ad90 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkb/Examples/GeometryXyTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkb/Examples/GeometryXyTest.php @@ -1,6 +1,6 @@ executeStrategy($collection)) + bin2hex((new WkbBinaryStrategy())->encode($collection)) ); } @@ -61,7 +61,7 @@ public function testGeometryCollectionEmpty(): void // Reference geometry in WKT: GEOMETRYCOLLECTION EMPTY static::assertSame( '010700000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($collection)) + bin2hex((new WkbBinaryStrategy())->encode($collection)) ); } @@ -73,7 +73,7 @@ public function testLineString(): void // Reference geometry in WKT: LINESTRING (0 0, 2 3, 4 1) static::assertSame( '01020000000300000000000000000000000000000000000000000000000000004000000000000008400000000000001040000000000000f03f', - bin2hex((new WkbBinaryStrategy())->executeStrategy($line)) + bin2hex((new WkbBinaryStrategy())->encode($line)) ); } @@ -85,7 +85,7 @@ public function testLineStringEmpty(): void // Reference geometry in WKT: LINESTRING EMPTY static::assertSame( '010200000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($line)) + bin2hex((new WkbBinaryStrategy())->encode($line)) ); } @@ -100,7 +100,7 @@ public function testMultiLineString(): void // Reference geometry in WKT: MULTILINESTRING ((0 0, 2 3), (4 1, 5 2)) static::assertSame( '01050000000200000001020000000200000000000000000000000000000000000000000000000000004000000000000008400102000000020000000000000000001040000000000000f03f00000000000014400000000000000040', - bin2hex((new WkbBinaryStrategy())->executeStrategy($lines)) + bin2hex((new WkbBinaryStrategy())->encode($lines)) ); } @@ -112,7 +112,7 @@ public function testMultiLineStringEmpty(): void // Reference geometry in WKT: MULTILINESTRING EMPTY static::assertSame( '010500000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($lines)) + bin2hex((new WkbBinaryStrategy())->encode($lines)) ); } @@ -124,7 +124,7 @@ public function testMultiPoint(): void // Reference geometry in WKT: MULTIPOINT ((1 2), (3 4)) static::assertSame( '0104000000020000000101000000000000000000f03f0000000000000040010100000000000000000008400000000000001040', - bin2hex((new WkbBinaryStrategy())->executeStrategy($points)) + bin2hex((new WkbBinaryStrategy())->encode($points)) ); } @@ -136,7 +136,7 @@ public function testMultiPointEmpty(): void // Reference geometry in WKT: MULTIPOINT EMPTY static::assertSame( '010400000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($points)) + bin2hex((new WkbBinaryStrategy())->encode($points)) ); } @@ -151,7 +151,7 @@ public function testMultiPolygon(): void // Reference geometry in WKT: MULTIPOLYGON (((0 0, 2 0, 0 2, 0 0)), ((3 3, 5 3, 3 5, 3 3))) static::assertSame( '01060000000200000001030000000100000004000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000040000000000000000000000000000000000103000000010000000400000000000000000008400000000000000840000000000000144000000000000008400000000000000840000000000000144000000000000008400000000000000840', - bin2hex((new WkbBinaryStrategy())->executeStrategy($polygons)) + bin2hex((new WkbBinaryStrategy())->encode($polygons)) ); } @@ -163,7 +163,7 @@ public function testMultiPolygonEmpty(): void // Reference geometry in WKT: MULTIPOLYGON EMPTY static::assertSame( '010600000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($polygons)) + bin2hex((new WkbBinaryStrategy())->encode($polygons)) ); } @@ -175,7 +175,7 @@ public function testPoint(): void // Reference geometry in WKT: POINT (2.5 -3) static::assertSame( '0101000000000000000000044000000000000008c0', - bin2hex((new WkbBinaryStrategy())->executeStrategy($point)) + bin2hex((new WkbBinaryStrategy())->encode($point)) ); } @@ -187,7 +187,7 @@ public function testPointEmpty(): void // Reference geometry in WKT: POINT EMPTY static::assertSame( '0101000000000000000000f87f000000000000f87f', - bin2hex((new WkbBinaryStrategy())->executeStrategy($point)) + bin2hex((new WkbBinaryStrategy())->encode($point)) ); } @@ -202,7 +202,7 @@ public function testPolygon(): void // Reference geometry in WKT: POLYGON ((0 0, 4 0, 4 4, 0 4, 0 0), (1 1, 1 2, 2 2, 2 1, 1 1)) static::assertSame( '01030000000200000005000000000000000000000000000000000000000000000000001040000000000000000000000000000010400000000000001040000000000000000000000000000010400000000000000000000000000000000005000000000000000000f03f000000000000f03f000000000000f03f0000000000000040000000000000004000000000000000400000000000000040000000000000f03f000000000000f03f000000000000f03f', - bin2hex((new WkbBinaryStrategy())->executeStrategy($polygon)) + bin2hex((new WkbBinaryStrategy())->encode($polygon)) ); } @@ -214,7 +214,7 @@ public function testPolygonEmpty(): void // Reference geometry in WKT: POLYGON EMPTY static::assertSame( '010300000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($polygon)) + bin2hex((new WkbBinaryStrategy())->encode($polygon)) ); } @@ -226,7 +226,7 @@ public function testTriangle(): void // Reference geometry in WKT: TRIANGLE ((0 0, 2 0, 0 2, 0 0)) static::assertSame( '0111000000010000000400000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000004000000000000000000000000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($triangle)) + bin2hex((new WkbBinaryStrategy())->encode($triangle)) ); } @@ -238,7 +238,7 @@ public function testTriangleEmpty(): void // Reference geometry in WKT: TRIANGLE EMPTY static::assertSame( '011100000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($triangle)) + bin2hex((new WkbBinaryStrategy())->encode($triangle)) ); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkb/Examples/GeometryXymTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkb/Examples/GeometryXymTest.php similarity index 86% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkb/Examples/GeometryXymTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkb/Examples/GeometryXymTest.php index f095159..62812a1 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkb/Examples/GeometryXymTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkb/Examples/GeometryXymTest.php @@ -1,6 +1,6 @@ executeStrategy($collection)) + bin2hex((new WkbBinaryStrategy())->encode($collection)) ); } @@ -61,7 +61,7 @@ public function testGeometryCollectionEmpty(): void // Reference geometry in WKT: GEOMETRYCOLLECTION M EMPTY static::assertSame( '01d707000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($collection)) + bin2hex((new WkbBinaryStrategy())->encode($collection)) ); } @@ -73,7 +73,7 @@ public function testLineString(): void // Reference geometry in WKT: LINESTRING M (0 0 10, 2 3 20, 4 1 30) static::assertSame( '01d2070000030000000000000000000000000000000000000000000000000024400000000000000040000000000000084000000000000034400000000000001040000000000000f03f0000000000003e40', - bin2hex((new WkbBinaryStrategy())->executeStrategy($line)) + bin2hex((new WkbBinaryStrategy())->encode($line)) ); } @@ -85,7 +85,7 @@ public function testLineStringEmpty(): void // Reference geometry in WKT: LINESTRING M EMPTY static::assertSame( '01d207000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($line)) + bin2hex((new WkbBinaryStrategy())->encode($line)) ); } @@ -100,7 +100,7 @@ public function testMultiLineString(): void // Reference geometry in WKT: MULTILINESTRING M ((0 0 10, 2 3 20), (4 1 30, 5 2 40)) static::assertSame( '01d50700000200000001d20700000200000000000000000000000000000000000000000000000000244000000000000000400000000000000840000000000000344001d2070000020000000000000000001040000000000000f03f0000000000003e40000000000000144000000000000000400000000000004440', - bin2hex((new WkbBinaryStrategy())->executeStrategy($lines)) + bin2hex((new WkbBinaryStrategy())->encode($lines)) ); } @@ -112,7 +112,7 @@ public function testMultiLineStringEmpty(): void // Reference geometry in WKT: MULTILINESTRING M EMPTY static::assertSame( '01d507000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($lines)) + bin2hex((new WkbBinaryStrategy())->encode($lines)) ); } @@ -124,7 +124,7 @@ public function testMultiPoint(): void // Reference geometry in WKT: MULTIPOINT M ((1 2 10), (3 4 20)) static::assertSame( '01d40700000200000001d1070000000000000000f03f0000000000000040000000000000244001d1070000000000000000084000000000000010400000000000003440', - bin2hex((new WkbBinaryStrategy())->executeStrategy($points)) + bin2hex((new WkbBinaryStrategy())->encode($points)) ); } @@ -136,7 +136,7 @@ public function testMultiPointEmpty(): void // Reference geometry in WKT: MULTIPOINT M EMPTY static::assertSame( '01d407000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($points)) + bin2hex((new WkbBinaryStrategy())->encode($points)) ); } @@ -151,7 +151,7 @@ public function testMultiPolygon(): void // Reference geometry in WKT: MULTIPOLYGON M (((0 0 10, 2 0 10, 0 2 10, 0 0 10)), ((3 3 20, 5 3 20, 3 5 20, 3 3 20))) static::assertSame( '01d60700000200000001d3070000010000000400000000000000000000000000000000000000000000000000244000000000000000400000000000000000000000000000244000000000000000000000000000000040000000000000244000000000000000000000000000000000000000000000244001d30700000100000004000000000000000000084000000000000008400000000000003440000000000000144000000000000008400000000000003440000000000000084000000000000014400000000000003440000000000000084000000000000008400000000000003440', - bin2hex((new WkbBinaryStrategy())->executeStrategy($polygons)) + bin2hex((new WkbBinaryStrategy())->encode($polygons)) ); } @@ -163,7 +163,7 @@ public function testMultiPolygonEmpty(): void // Reference geometry in WKT: MULTIPOLYGON M EMPTY static::assertSame( '01d607000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($polygons)) + bin2hex((new WkbBinaryStrategy())->encode($polygons)) ); } @@ -175,7 +175,7 @@ public function testPoint(): void // Reference geometry in WKT: POINT M (2.5 -3 10) static::assertSame( '01d1070000000000000000044000000000000008c00000000000002440', - bin2hex((new WkbBinaryStrategy())->executeStrategy($point)) + bin2hex((new WkbBinaryStrategy())->encode($point)) ); } @@ -187,7 +187,7 @@ public function testPointEmpty(): void // Reference geometry in WKT: POINT M EMPTY static::assertSame( '01d1070000000000000000f87f000000000000f87f000000000000f87f', - bin2hex((new WkbBinaryStrategy())->executeStrategy($point)) + bin2hex((new WkbBinaryStrategy())->encode($point)) ); } @@ -202,7 +202,7 @@ public function testPolygon(): void // Reference geometry in WKT: POLYGON M ((0 0 10, 4 0 10, 4 4 10, 0 4 10, 0 0 10), (1 1 10, 1 2 10, 2 2 10, 2 1 10, 1 1 10)) static::assertSame( '01d3070000020000000500000000000000000000000000000000000000000000000000244000000000000010400000000000000000000000000000244000000000000010400000000000001040000000000000244000000000000000000000000000001040000000000000244000000000000000000000000000000000000000000000244005000000000000000000f03f000000000000f03f0000000000002440000000000000f03f000000000000004000000000000024400000000000000040000000000000004000000000000024400000000000000040000000000000f03f0000000000002440000000000000f03f000000000000f03f0000000000002440', - bin2hex((new WkbBinaryStrategy())->executeStrategy($polygon)) + bin2hex((new WkbBinaryStrategy())->encode($polygon)) ); } @@ -214,7 +214,7 @@ public function testPolygonEmpty(): void // Reference geometry in WKT: POLYGON M EMPTY static::assertSame( '01d307000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($polygon)) + bin2hex((new WkbBinaryStrategy())->encode($polygon)) ); } @@ -226,7 +226,7 @@ public function testTriangle(): void // Reference geometry in WKT: TRIANGLE M ((0 0 10, 2 0 10, 0 2 10, 0 0 10)) static::assertSame( '01e10700000100000004000000000000000000000000000000000000000000000000002440000000000000004000000000000000000000000000002440000000000000000000000000000000400000000000002440000000000000000000000000000000000000000000002440', - bin2hex((new WkbBinaryStrategy())->executeStrategy($triangle)) + bin2hex((new WkbBinaryStrategy())->encode($triangle)) ); } @@ -238,7 +238,7 @@ public function testTriangleEmpty(): void // Reference geometry in WKT: TRIANGLE M EMPTY static::assertSame( '01e107000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($triangle)) + bin2hex((new WkbBinaryStrategy())->encode($triangle)) ); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkb/Examples/GeometryXyzTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkb/Examples/GeometryXyzTest.php similarity index 86% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkb/Examples/GeometryXyzTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkb/Examples/GeometryXyzTest.php index f2fe97b..026fe6d 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkb/Examples/GeometryXyzTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkb/Examples/GeometryXyzTest.php @@ -1,6 +1,6 @@ executeStrategy($collection)) + bin2hex((new WkbBinaryStrategy())->encode($collection)) ); } @@ -62,7 +62,7 @@ public function testGeometryCollectionEmpty(): void // Reference geometry in WKT: GEOMETRYCOLLECTION Z EMPTY static::assertSame( '01ef03000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($collection)) + bin2hex((new WkbBinaryStrategy())->encode($collection)) ); } @@ -74,7 +74,7 @@ public function testLineString(): void // Reference geometry in WKT: LINESTRING Z (0 0 5, 2 3 6, 4 1 7) static::assertSame( '01ea030000030000000000000000000000000000000000000000000000000014400000000000000040000000000000084000000000000018400000000000001040000000000000f03f0000000000001c40', - bin2hex((new WkbBinaryStrategy())->executeStrategy($line)) + bin2hex((new WkbBinaryStrategy())->encode($line)) ); } @@ -86,7 +86,7 @@ public function testLineStringEmpty(): void // Reference geometry in WKT: LINESTRING Z EMPTY static::assertSame( '01ea03000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($line)) + bin2hex((new WkbBinaryStrategy())->encode($line)) ); } @@ -101,7 +101,7 @@ public function testMultiLineString(): void // Reference geometry in WKT: MULTILINESTRING Z ((0 0 5, 2 3 6), (4 1 7, 5 2 8)) static::assertSame( '01ed0300000200000001ea0300000200000000000000000000000000000000000000000000000000144000000000000000400000000000000840000000000000184001ea030000020000000000000000001040000000000000f03f0000000000001c40000000000000144000000000000000400000000000002040', - bin2hex((new WkbBinaryStrategy())->executeStrategy($lines)) + bin2hex((new WkbBinaryStrategy())->encode($lines)) ); } @@ -113,7 +113,7 @@ public function testMultiLineStringEmpty(): void // Reference geometry in WKT: MULTILINESTRING Z EMPTY static::assertSame( '01ed03000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($lines)) + bin2hex((new WkbBinaryStrategy())->encode($lines)) ); } @@ -125,7 +125,7 @@ public function testMultiPoint(): void // Reference geometry in WKT: MULTIPOINT Z ((1 2 5), (3 4 6)) static::assertSame( '01ec0300000200000001e9030000000000000000f03f0000000000000040000000000000144001e9030000000000000000084000000000000010400000000000001840', - bin2hex((new WkbBinaryStrategy())->executeStrategy($points)) + bin2hex((new WkbBinaryStrategy())->encode($points)) ); } @@ -137,7 +137,7 @@ public function testMultiPointEmpty(): void // Reference geometry in WKT: MULTIPOINT Z EMPTY static::assertSame( '01ec03000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($points)) + bin2hex((new WkbBinaryStrategy())->encode($points)) ); } @@ -152,7 +152,7 @@ public function testMultiPolygon(): void // Reference geometry in WKT: MULTIPOLYGON Z (((0 0 5, 2 0 5, 0 2 5, 0 0 5)), ((3 3 6, 5 3 6, 3 5 6, 3 3 6))) static::assertSame( '01ee0300000200000001eb030000010000000400000000000000000000000000000000000000000000000000144000000000000000400000000000000000000000000000144000000000000000000000000000000040000000000000144000000000000000000000000000000000000000000000144001eb0300000100000004000000000000000000084000000000000008400000000000001840000000000000144000000000000008400000000000001840000000000000084000000000000014400000000000001840000000000000084000000000000008400000000000001840', - bin2hex((new WkbBinaryStrategy())->executeStrategy($polygons)) + bin2hex((new WkbBinaryStrategy())->encode($polygons)) ); } @@ -164,7 +164,7 @@ public function testMultiPolygonEmpty(): void // Reference geometry in WKT: MULTIPOLYGON Z EMPTY static::assertSame( '01ee03000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($polygons)) + bin2hex((new WkbBinaryStrategy())->encode($polygons)) ); } @@ -176,7 +176,7 @@ public function testPoint(): void // Reference geometry in WKT: POINT Z (2.5 -3 5) static::assertSame( '01e9030000000000000000044000000000000008c00000000000001440', - bin2hex((new WkbBinaryStrategy())->executeStrategy($point)) + bin2hex((new WkbBinaryStrategy())->encode($point)) ); } @@ -188,7 +188,7 @@ public function testPointEmpty(): void // Reference geometry in WKT: POINT Z EMPTY static::assertSame( '01e9030000000000000000f87f000000000000f87f000000000000f87f', - bin2hex((new WkbBinaryStrategy())->executeStrategy($point)) + bin2hex((new WkbBinaryStrategy())->encode($point)) ); } @@ -203,7 +203,7 @@ public function testPolygon(): void // Reference geometry in WKT: POLYGON Z ((0 0 5, 4 0 5, 4 4 5, 0 4 5, 0 0 5), (1 1 5, 1 2 5, 2 2 5, 2 1 5, 1 1 5)) static::assertSame( '01eb030000020000000500000000000000000000000000000000000000000000000000144000000000000010400000000000000000000000000000144000000000000010400000000000001040000000000000144000000000000000000000000000001040000000000000144000000000000000000000000000000000000000000000144005000000000000000000f03f000000000000f03f0000000000001440000000000000f03f000000000000004000000000000014400000000000000040000000000000004000000000000014400000000000000040000000000000f03f0000000000001440000000000000f03f000000000000f03f0000000000001440', - bin2hex((new WkbBinaryStrategy())->executeStrategy($polygon)) + bin2hex((new WkbBinaryStrategy())->encode($polygon)) ); } @@ -215,7 +215,7 @@ public function testPolygonEmpty(): void // Reference geometry in WKT: POLYGON Z EMPTY static::assertSame( '01eb03000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($polygon)) + bin2hex((new WkbBinaryStrategy())->encode($polygon)) ); } @@ -230,7 +230,7 @@ public function testPolyhedralSurface(): void // Reference geometry in WKT: POLYHEDRALSURFACE Z (((0 0 5, 1 0 5, 1 1 5, 0 1 5, 0 0 5)), ((1 0 5, 2 0 5, 2 1 5, 1 1 5, 1 0 5))) static::assertSame( '01f70300000200000001eb0300000100000005000000000000000000000000000000000000000000000000001440000000000000f03f00000000000000000000000000001440000000000000f03f000000000000f03f00000000000014400000000000000000000000000000f03f000000000000144000000000000000000000000000000000000000000000144001eb0300000100000005000000000000000000f03f000000000000000000000000000014400000000000000040000000000000000000000000000014400000000000000040000000000000f03f0000000000001440000000000000f03f000000000000f03f0000000000001440000000000000f03f00000000000000000000000000001440', - bin2hex((new WkbBinaryStrategy())->executeStrategy($surface)) + bin2hex((new WkbBinaryStrategy())->encode($surface)) ); } @@ -242,7 +242,7 @@ public function testPolyhedralSurfaceEmpty(): void // Reference geometry in WKT: POLYHEDRALSURFACE Z EMPTY static::assertSame( '01f703000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($surface)) + bin2hex((new WkbBinaryStrategy())->encode($surface)) ); } @@ -254,7 +254,7 @@ public function testTriangle(): void // Reference geometry in WKT: TRIANGLE Z ((0 0 5, 2 0 5, 0 2 5, 0 0 5)) static::assertSame( '01f90300000100000004000000000000000000000000000000000000000000000000001440000000000000004000000000000000000000000000001440000000000000000000000000000000400000000000001440000000000000000000000000000000000000000000001440', - bin2hex((new WkbBinaryStrategy())->executeStrategy($triangle)) + bin2hex((new WkbBinaryStrategy())->encode($triangle)) ); } @@ -266,7 +266,7 @@ public function testTriangleEmpty(): void // Reference geometry in WKT: TRIANGLE Z EMPTY static::assertSame( '01f903000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($triangle)) + bin2hex((new WkbBinaryStrategy())->encode($triangle)) ); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkb/Examples/GeometryXyzmTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkb/Examples/GeometryXyzmTest.php similarity index 87% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkb/Examples/GeometryXyzmTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkb/Examples/GeometryXyzmTest.php index ba04e1b..5ec9ca7 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkb/Examples/GeometryXyzmTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkb/Examples/GeometryXyzmTest.php @@ -1,6 +1,6 @@ executeStrategy($collection)) + bin2hex((new WkbBinaryStrategy())->encode($collection)) ); } @@ -62,7 +62,7 @@ public function testGeometryCollectionEmpty(): void // Reference geometry in WKT: GEOMETRYCOLLECTION ZM EMPTY static::assertSame( '01bf0b000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($collection)) + bin2hex((new WkbBinaryStrategy())->encode($collection)) ); } @@ -74,7 +74,7 @@ public function testLineString(): void // Reference geometry in WKT: LINESTRING ZM (0 0 5 10, 2 3 6 20, 4 1 7 30) static::assertSame( '01ba0b000003000000000000000000000000000000000000000000000000001440000000000000244000000000000000400000000000000840000000000000184000000000000034400000000000001040000000000000f03f0000000000001c400000000000003e40', - bin2hex((new WkbBinaryStrategy())->executeStrategy($line)) + bin2hex((new WkbBinaryStrategy())->encode($line)) ); } @@ -86,7 +86,7 @@ public function testLineStringEmpty(): void // Reference geometry in WKT: LINESTRING ZM EMPTY static::assertSame( '01ba0b000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($line)) + bin2hex((new WkbBinaryStrategy())->encode($line)) ); } @@ -101,7 +101,7 @@ public function testMultiLineString(): void // Reference geometry in WKT: MULTILINESTRING ZM ((0 0 5 10, 2 3 6 20), (4 1 7 30, 5 2 8 40)) static::assertSame( '01bd0b00000200000001ba0b0000020000000000000000000000000000000000000000000000000014400000000000002440000000000000004000000000000008400000000000001840000000000000344001ba0b0000020000000000000000001040000000000000f03f0000000000001c400000000000003e400000000000001440000000000000004000000000000020400000000000004440', - bin2hex((new WkbBinaryStrategy())->executeStrategy($lines)) + bin2hex((new WkbBinaryStrategy())->encode($lines)) ); } @@ -113,7 +113,7 @@ public function testMultiLineStringEmpty(): void // Reference geometry in WKT: MULTILINESTRING ZM EMPTY static::assertSame( '01bd0b000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($lines)) + bin2hex((new WkbBinaryStrategy())->encode($lines)) ); } @@ -125,7 +125,7 @@ public function testMultiPoint(): void // Reference geometry in WKT: MULTIPOINT ZM ((1 2 5 10), (3 4 6 20)) static::assertSame( '01bc0b00000200000001b90b0000000000000000f03f00000000000000400000000000001440000000000000244001b90b00000000000000000840000000000000104000000000000018400000000000003440', - bin2hex((new WkbBinaryStrategy())->executeStrategy($points)) + bin2hex((new WkbBinaryStrategy())->encode($points)) ); } @@ -137,7 +137,7 @@ public function testMultiPointEmpty(): void // Reference geometry in WKT: MULTIPOINT ZM EMPTY static::assertSame( '01bc0b000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($points)) + bin2hex((new WkbBinaryStrategy())->encode($points)) ); } @@ -152,7 +152,7 @@ public function testMultiPolygon(): void // Reference geometry in WKT: MULTIPOLYGON ZM (((0 0 5 10, 2 0 5 10, 0 2 5 10, 0 0 5 10)), ((3 3 6 20, 5 3 6 20, 3 5 6 20, 3 3 6 20))) static::assertSame( '01be0b00000200000001bb0b00000100000004000000000000000000000000000000000000000000000000001440000000000000244000000000000000400000000000000000000000000000144000000000000024400000000000000000000000000000004000000000000014400000000000002440000000000000000000000000000000000000000000001440000000000000244001bb0b000001000000040000000000000000000840000000000000084000000000000018400000000000003440000000000000144000000000000008400000000000001840000000000000344000000000000008400000000000001440000000000000184000000000000034400000000000000840000000000000084000000000000018400000000000003440', - bin2hex((new WkbBinaryStrategy())->executeStrategy($polygons)) + bin2hex((new WkbBinaryStrategy())->encode($polygons)) ); } @@ -164,7 +164,7 @@ public function testMultiPolygonEmpty(): void // Reference geometry in WKT: MULTIPOLYGON ZM EMPTY static::assertSame( '01be0b000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($polygons)) + bin2hex((new WkbBinaryStrategy())->encode($polygons)) ); } @@ -176,7 +176,7 @@ public function testPoint(): void // Reference geometry in WKT: POINT ZM (2.5 -3 5 10) static::assertSame( '01b90b0000000000000000044000000000000008c000000000000014400000000000002440', - bin2hex((new WkbBinaryStrategy())->executeStrategy($point)) + bin2hex((new WkbBinaryStrategy())->encode($point)) ); } @@ -188,7 +188,7 @@ public function testPointEmpty(): void // Reference geometry in WKT: POINT ZM EMPTY static::assertSame( '01b90b0000000000000000f87f000000000000f87f000000000000f87f000000000000f87f', - bin2hex((new WkbBinaryStrategy())->executeStrategy($point)) + bin2hex((new WkbBinaryStrategy())->encode($point)) ); } @@ -203,7 +203,7 @@ public function testPolygon(): void // Reference geometry in WKT: POLYGON ZM ((0 0 5 10, 4 0 5 10, 4 4 5 10, 0 4 5 10, 0 0 5 10), (1 1 5 10, 1 2 5 10, 2 2 5 10, 2 1 5 10, 1 1 5 10)) static::assertSame( '01bb0b000002000000050000000000000000000000000000000000000000000000000014400000000000002440000000000000104000000000000000000000000000001440000000000000244000000000000010400000000000001040000000000000144000000000000024400000000000000000000000000000104000000000000014400000000000002440000000000000000000000000000000000000000000001440000000000000244005000000000000000000f03f000000000000f03f00000000000014400000000000002440000000000000f03f00000000000000400000000000001440000000000000244000000000000000400000000000000040000000000000144000000000000024400000000000000040000000000000f03f00000000000014400000000000002440000000000000f03f000000000000f03f00000000000014400000000000002440', - bin2hex((new WkbBinaryStrategy())->executeStrategy($polygon)) + bin2hex((new WkbBinaryStrategy())->encode($polygon)) ); } @@ -215,7 +215,7 @@ public function testPolygonEmpty(): void // Reference geometry in WKT: POLYGON ZM EMPTY static::assertSame( '01bb0b000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($polygon)) + bin2hex((new WkbBinaryStrategy())->encode($polygon)) ); } @@ -230,7 +230,7 @@ public function testPolyhedralSurface(): void // Reference geometry in WKT: POLYHEDRALSURFACE ZM (((0 0 5 10, 1 0 5 10, 1 1 5 10, 0 1 5 10, 0 0 5 10)), ((1 0 5 10, 2 0 5 10, 2 1 5 10, 1 1 5 10, 1 0 5 10))) static::assertSame( '01c70b00000200000001bb0b000001000000050000000000000000000000000000000000000000000000000014400000000000002440000000000000f03f000000000000000000000000000014400000000000002440000000000000f03f000000000000f03f000000000000144000000000000024400000000000000000000000000000f03f00000000000014400000000000002440000000000000000000000000000000000000000000001440000000000000244001bb0b00000100000005000000000000000000f03f00000000000000000000000000001440000000000000244000000000000000400000000000000000000000000000144000000000000024400000000000000040000000000000f03f00000000000014400000000000002440000000000000f03f000000000000f03f00000000000014400000000000002440000000000000f03f000000000000000000000000000014400000000000002440', - bin2hex((new WkbBinaryStrategy())->executeStrategy($surface)) + bin2hex((new WkbBinaryStrategy())->encode($surface)) ); } @@ -242,7 +242,7 @@ public function testPolyhedralSurfaceEmpty(): void // Reference geometry in WKT: POLYHEDRALSURFACE ZM EMPTY static::assertSame( '01c70b000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($surface)) + bin2hex((new WkbBinaryStrategy())->encode($surface)) ); } @@ -254,7 +254,7 @@ public function testTriangle(): void // Reference geometry in WKT: TRIANGLE ZM ((0 0 5 10, 2 0 5 10, 0 2 5 10, 0 0 5 10)) static::assertSame( '01c90b000001000000040000000000000000000000000000000000000000000000000014400000000000002440000000000000004000000000000000000000000000001440000000000000244000000000000000000000000000000040000000000000144000000000000024400000000000000000000000000000000000000000000014400000000000002440', - bin2hex((new WkbBinaryStrategy())->executeStrategy($triangle)) + bin2hex((new WkbBinaryStrategy())->encode($triangle)) ); } @@ -266,7 +266,7 @@ public function testTriangleEmpty(): void // Reference geometry in WKT: TRIANGLE ZM EMPTY static::assertSame( '01c90b000000000000', - bin2hex((new WkbBinaryStrategy())->executeStrategy($triangle)) + bin2hex((new WkbBinaryStrategy())->encode($triangle)) ); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkb/WkbRegressionTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkb/WkbRegressionTest.php similarity index 82% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkb/WkbRegressionTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkb/WkbRegressionTest.php index 7114521..eebcf43 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkb/WkbRegressionTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkb/WkbRegressionTest.php @@ -1,6 +1,6 @@ executeStrategy($collection)) + bin2hex((new WkbBinaryStrategy())->encode($collection)) ); } @@ -63,7 +63,7 @@ public function testUnsupportedInterface(): void $spatial = static::createStub(SpatialInterface::class); $spatial->method('getType')->willReturn(GeometryTypeEnum::POINT); $this->expectException(UnsupportedSpatialInterfaceException::class); - (new WkbBinaryStrategy())->executeStrategy($spatial); + (new WkbBinaryStrategy())->encode($spatial); } /** Reject enum cases without concrete supported spatial types. */ @@ -73,6 +73,6 @@ public function testUnsupportedType(): void $spatial->method('getType')->willReturn(GeometryTypeEnum::CIRCULARSTRING); $this->expectException(UnsupportedSpatialTypeException::class); $this->expectExceptionMessage('WKB adapter does not support spatial type CircularString'); - (new WkbBinaryStrategy())->executeStrategy($spatial); + (new WkbBinaryStrategy())->encode($spatial); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/WkbStrategyTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/WkbStrategyTest.php similarity index 96% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/WkbStrategyTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/WkbStrategyTest.php index 828a9a6..6729169 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/WkbStrategyTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/WkbStrategyTest.php @@ -1,6 +1,6 @@ strategy->executeStrategy($collection)))); + static::assertSame($expected, mb_strtoupper(bin2hex($this->strategy->encode($collection)))); } /** @@ -155,7 +155,7 @@ public static function collectionProvider(): \Generator #[DataProvider('lineStringProvider')] public function testLineString(LineStringInterface $lineString, string $expected): void { - static::assertSame(mb_strtolower($expected), bin2hex($this->strategy->executeStrategy($lineString))); + static::assertSame(mb_strtolower($expected), bin2hex($this->strategy->encode($lineString))); } /** @@ -208,7 +208,7 @@ public static function lineStringProvider(): \Generator #[DataProvider('multiLineStringProvider')] public function testMultiLineString(MultiLineStringInterface $multiLineString, string $expected): void { - static::assertSame(mb_strtolower($expected), bin2hex($this->strategy->executeStrategy($multiLineString))); + static::assertSame(mb_strtolower($expected), bin2hex($this->strategy->encode($multiLineString))); } /** @@ -253,7 +253,7 @@ public static function multiLineStringProvider(): \Generator #[DataProvider('multiPointProvider')] public function testMultiPoint(MultiPointInterface $multiPoint, string $expected): void { - static::assertSame(mb_strtolower($expected), bin2hex($this->strategy->executeStrategy($multiPoint))); + static::assertSame(mb_strtolower($expected), bin2hex($this->strategy->encode($multiPoint))); } /** @@ -288,7 +288,7 @@ public static function multiPointProvider(): \Generator #[DataProvider('multiPolygonProvider')] public function testMultiPolygon(MultiPolygonInterface $multiPolygon, string $expected): void { - static::assertSame(mb_strtolower($expected), bin2hex($this->strategy->executeStrategy($multiPolygon))); + static::assertSame(mb_strtolower($expected), bin2hex($this->strategy->encode($multiPolygon))); } /** @@ -336,7 +336,7 @@ public static function multiPolygonProvider(): \Generator #[DataProvider('pointProvider')] public function testPoint(PointInterface $point, string $expected): void { - static::assertSame(mb_strtolower($expected), bin2hex($this->strategy->executeStrategy($point))); + static::assertSame(mb_strtolower($expected), bin2hex($this->strategy->encode($point))); } /** @@ -409,7 +409,7 @@ public static function pointProvider(): \Generator #[DataProvider('polygonProvider')] public function testPolygon(PolygonInterface $polygon, string $expected): void { - static::assertSame(mb_strtolower($expected), bin2hex($this->strategy->executeStrategy($polygon))); + static::assertSame(mb_strtolower($expected), bin2hex($this->strategy->encode($polygon))); } /** diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkt/Examples/GeographyXyTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkt/Examples/GeographyXyTest.php similarity index 85% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkt/Examples/GeographyXyTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkt/Examples/GeographyXyTest.php index f6c6b93..5ac42ef 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkt/Examples/GeographyXyTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkt/Examples/GeographyXyTest.php @@ -1,6 +1,6 @@ executeStrategy($collection) + (new WktTextStrategy())->encode($collection) ); } @@ -57,7 +57,7 @@ public function testGeographyCollectionEmpty(): void { $collection = new GeographyCollection(4326, []); - static::assertSame('GEOMETRYCOLLECTION EMPTY', (new WktTextStrategy())->executeStrategy($collection)); + static::assertSame('GEOMETRYCOLLECTION EMPTY', (new WktTextStrategy())->encode($collection)); } /** Write three points in their original order. */ @@ -65,7 +65,7 @@ public function testLineString(): void { $line = new LineString([[0, 0], [2, 3], [4, 1]], 4326); - static::assertSame('LINESTRING (0 0, 2 3, 4 1)', (new WktTextStrategy())->executeStrategy($line)); + static::assertSame('LINESTRING (0 0, 2 3, 4 1)', (new WktTextStrategy())->encode($line)); } /** Preserve the type and dimension of an empty LineString. */ @@ -73,7 +73,7 @@ public function testLineStringEmpty(): void { $line = new LineString([], 4326); - static::assertSame('LINESTRING EMPTY', (new WktTextStrategy())->executeStrategy($line)); + static::assertSame('LINESTRING EMPTY', (new WktTextStrategy())->encode($line)); } /** Write two lines in their original order. */ @@ -84,7 +84,7 @@ public function testMultiLineString(): void [[4, 1], [5, 2]], ], 4326); - static::assertSame('MULTILINESTRING ((0 0, 2 3), (4 1, 5 2))', (new WktTextStrategy())->executeStrategy($lines)); + static::assertSame('MULTILINESTRING ((0 0, 2 3), (4 1, 5 2))', (new WktTextStrategy())->encode($lines)); } /** Preserve the type and dimension of an empty MultiLineString. */ @@ -92,7 +92,7 @@ public function testMultiLineStringEmpty(): void { $lines = new MultiLineString([], 4326); - static::assertSame('MULTILINESTRING EMPTY', (new WktTextStrategy())->executeStrategy($lines)); + static::assertSame('MULTILINESTRING EMPTY', (new WktTextStrategy())->encode($lines)); } /** Write two distinct points with separate parentheses. */ @@ -100,7 +100,7 @@ public function testMultiPoint(): void { $points = new MultiPoint([[1, 2], [3, 4]], 4326); - static::assertSame('MULTIPOINT ((1 2), (3 4))', (new WktTextStrategy())->executeStrategy($points)); + static::assertSame('MULTIPOINT ((1 2), (3 4))', (new WktTextStrategy())->encode($points)); } /** Preserve the type and dimension of an empty MultiPoint. */ @@ -108,7 +108,7 @@ public function testMultiPointEmpty(): void { $points = new MultiPoint([], 4326); - static::assertSame('MULTIPOINT EMPTY', (new WktTextStrategy())->executeStrategy($points)); + static::assertSame('MULTIPOINT EMPTY', (new WktTextStrategy())->encode($points)); } /** Write two polygons with their own closed exterior rings. */ @@ -121,7 +121,7 @@ public function testMultiPolygon(): void static::assertSame( 'MULTIPOLYGON (((0 0, 2 0, 0 2, 0 0)), ((3 3, 5 3, 3 5, 3 3)))', - (new WktTextStrategy())->executeStrategy($polygons) + (new WktTextStrategy())->encode($polygons) ); } @@ -130,7 +130,7 @@ public function testMultiPolygonEmpty(): void { $polygons = new MultiPolygon([], 4326); - static::assertSame('MULTIPOLYGON EMPTY', (new WktTextStrategy())->executeStrategy($polygons)); + static::assertSame('MULTIPOLYGON EMPTY', (new WktTextStrategy())->encode($polygons)); } /** Write a point with fractional and negative ordinates. */ @@ -138,7 +138,7 @@ public function testPoint(): void { $point = new Point(2.5, -3, 4326); - static::assertSame('POINT (2.5 -3)', (new WktTextStrategy())->executeStrategy($point)); + static::assertSame('POINT (2.5 -3)', (new WktTextStrategy())->encode($point)); } /** Preserve the type and dimension of an empty Point. */ @@ -146,7 +146,7 @@ public function testPointEmpty(): void { $point = new Point(srid: 4326); - static::assertSame('POINT EMPTY', (new WktTextStrategy())->executeStrategy($point)); + static::assertSame('POINT EMPTY', (new WktTextStrategy())->encode($point)); } /** Write an exterior ring followed by an interior hole. */ @@ -159,7 +159,7 @@ public function testPolygon(): void static::assertSame( 'POLYGON ((0 0, 4 0, 4 4, 0 4, 0 0), (1 1, 1 2, 2 2, 2 1, 1 1))', - (new WktTextStrategy())->executeStrategy($polygon) + (new WktTextStrategy())->encode($polygon) ); } @@ -168,7 +168,7 @@ public function testPolygonEmpty(): void { $polygon = new Polygon([], 4326); - static::assertSame('POLYGON EMPTY', (new WktTextStrategy())->executeStrategy($polygon)); + static::assertSame('POLYGON EMPTY', (new WktTextStrategy())->encode($polygon)); } /** Write three vertices and the closing position. */ @@ -176,7 +176,7 @@ public function testTriangle(): void { $triangle = new Triangle([[[0, 0], [2, 0], [0, 2], [0, 0]]], 4326); - static::assertSame('TRIANGLE ((0 0, 2 0, 0 2, 0 0))', (new WktTextStrategy())->executeStrategy($triangle)); + static::assertSame('TRIANGLE ((0 0, 2 0, 0 2, 0 0))', (new WktTextStrategy())->encode($triangle)); } /** Preserve the type and dimension of an empty Triangle. */ @@ -184,6 +184,6 @@ public function testTriangleEmpty(): void { $triangle = new Triangle([], 4326); - static::assertSame('TRIANGLE EMPTY', (new WktTextStrategy())->executeStrategy($triangle)); + static::assertSame('TRIANGLE EMPTY', (new WktTextStrategy())->encode($triangle)); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkt/Examples/GeographyXymTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkt/Examples/GeographyXymTest.php similarity index 84% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkt/Examples/GeographyXymTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkt/Examples/GeographyXymTest.php index 2a7b6bd..8ae7034 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkt/Examples/GeographyXymTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkt/Examples/GeographyXymTest.php @@ -1,6 +1,6 @@ executeStrategy($collection) + (new WktTextStrategy())->encode($collection) ); } @@ -57,7 +57,7 @@ public function testGeographyCollectionEmpty(): void { $collection = new GeographyCollection(4326, []); - static::assertSame('GEOMETRYCOLLECTION M EMPTY', (new WktTextStrategy())->executeStrategy($collection)); + static::assertSame('GEOMETRYCOLLECTION M EMPTY', (new WktTextStrategy())->encode($collection)); } /** Write three points in their original order. */ @@ -65,7 +65,7 @@ public function testLineString(): void { $line = new LineString([[0, 0, 10], [2, 3, 20], [4, 1, 30]], 4326); - static::assertSame('LINESTRING M (0 0 10, 2 3 20, 4 1 30)', (new WktTextStrategy())->executeStrategy($line)); + static::assertSame('LINESTRING M (0 0 10, 2 3 20, 4 1 30)', (new WktTextStrategy())->encode($line)); } /** Preserve the type and dimension of an empty LineString. */ @@ -73,7 +73,7 @@ public function testLineStringEmpty(): void { $line = new LineString([], 4326); - static::assertSame('LINESTRING M EMPTY', (new WktTextStrategy())->executeStrategy($line)); + static::assertSame('LINESTRING M EMPTY', (new WktTextStrategy())->encode($line)); } /** Write two lines in their original order. */ @@ -84,7 +84,7 @@ public function testMultiLineString(): void [[4, 1, 30], [5, 2, 40]], ], 4326); - static::assertSame('MULTILINESTRING M ((0 0 10, 2 3 20), (4 1 30, 5 2 40))', (new WktTextStrategy())->executeStrategy($lines)); + static::assertSame('MULTILINESTRING M ((0 0 10, 2 3 20), (4 1 30, 5 2 40))', (new WktTextStrategy())->encode($lines)); } /** Preserve the type and dimension of an empty MultiLineString. */ @@ -92,7 +92,7 @@ public function testMultiLineStringEmpty(): void { $lines = new MultiLineString([], 4326); - static::assertSame('MULTILINESTRING M EMPTY', (new WktTextStrategy())->executeStrategy($lines)); + static::assertSame('MULTILINESTRING M EMPTY', (new WktTextStrategy())->encode($lines)); } /** Write two distinct points with separate parentheses. */ @@ -100,7 +100,7 @@ public function testMultiPoint(): void { $points = new MultiPoint([[1, 2, 10], [3, 4, 20]], 4326); - static::assertSame('MULTIPOINT M ((1 2 10), (3 4 20))', (new WktTextStrategy())->executeStrategy($points)); + static::assertSame('MULTIPOINT M ((1 2 10), (3 4 20))', (new WktTextStrategy())->encode($points)); } /** Preserve the type and dimension of an empty MultiPoint. */ @@ -108,7 +108,7 @@ public function testMultiPointEmpty(): void { $points = new MultiPoint([], 4326); - static::assertSame('MULTIPOINT M EMPTY', (new WktTextStrategy())->executeStrategy($points)); + static::assertSame('MULTIPOINT M EMPTY', (new WktTextStrategy())->encode($points)); } /** Write two polygons with their own closed exterior rings. */ @@ -121,7 +121,7 @@ public function testMultiPolygon(): void static::assertSame( 'MULTIPOLYGON M (((0 0 10, 2 0 10, 0 2 10, 0 0 10)), ((3 3 20, 5 3 20, 3 5 20, 3 3 20)))', - (new WktTextStrategy())->executeStrategy($polygons) + (new WktTextStrategy())->encode($polygons) ); } @@ -130,7 +130,7 @@ public function testMultiPolygonEmpty(): void { $polygons = new MultiPolygon([], 4326); - static::assertSame('MULTIPOLYGON M EMPTY', (new WktTextStrategy())->executeStrategy($polygons)); + static::assertSame('MULTIPOLYGON M EMPTY', (new WktTextStrategy())->encode($polygons)); } /** Write a point with fractional and negative ordinates. */ @@ -138,7 +138,7 @@ public function testPoint(): void { $point = new Point(2.5, -3, 10, 4326); - static::assertSame('POINT M (2.5 -3 10)', (new WktTextStrategy())->executeStrategy($point)); + static::assertSame('POINT M (2.5 -3 10)', (new WktTextStrategy())->encode($point)); } /** Preserve the type and dimension of an empty Point. */ @@ -146,7 +146,7 @@ public function testPointEmpty(): void { $point = new Point(srid: 4326); - static::assertSame('POINT M EMPTY', (new WktTextStrategy())->executeStrategy($point)); + static::assertSame('POINT M EMPTY', (new WktTextStrategy())->encode($point)); } /** Write an exterior ring followed by an interior hole. */ @@ -159,7 +159,7 @@ public function testPolygon(): void static::assertSame( 'POLYGON M ((0 0 10, 4 0 10, 4 4 10, 0 4 10, 0 0 10), (1 1 10, 1 2 10, 2 2 10, 2 1 10, 1 1 10))', - (new WktTextStrategy())->executeStrategy($polygon) + (new WktTextStrategy())->encode($polygon) ); } @@ -168,7 +168,7 @@ public function testPolygonEmpty(): void { $polygon = new Polygon([], 4326); - static::assertSame('POLYGON M EMPTY', (new WktTextStrategy())->executeStrategy($polygon)); + static::assertSame('POLYGON M EMPTY', (new WktTextStrategy())->encode($polygon)); } /** Write three vertices and the closing position. */ @@ -176,7 +176,7 @@ public function testTriangle(): void { $triangle = new Triangle([[[0, 0, 10], [2, 0, 10], [0, 2, 10], [0, 0, 10]]], 4326); - static::assertSame('TRIANGLE M ((0 0 10, 2 0 10, 0 2 10, 0 0 10))', (new WktTextStrategy())->executeStrategy($triangle)); + static::assertSame('TRIANGLE M ((0 0 10, 2 0 10, 0 2 10, 0 0 10))', (new WktTextStrategy())->encode($triangle)); } /** Preserve the type and dimension of an empty Triangle. */ @@ -184,6 +184,6 @@ public function testTriangleEmpty(): void { $triangle = new Triangle([], 4326); - static::assertSame('TRIANGLE M EMPTY', (new WktTextStrategy())->executeStrategy($triangle)); + static::assertSame('TRIANGLE M EMPTY', (new WktTextStrategy())->encode($triangle)); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkt/Examples/GeographyXyzTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkt/Examples/GeographyXyzTest.php similarity index 85% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkt/Examples/GeographyXyzTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkt/Examples/GeographyXyzTest.php index bd0adac..4dcd7a9 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkt/Examples/GeographyXyzTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkt/Examples/GeographyXyzTest.php @@ -1,6 +1,6 @@ executeStrategy($collection) + (new WktTextStrategy())->encode($collection) ); } @@ -58,7 +58,7 @@ public function testGeographyCollectionEmpty(): void { $collection = new GeographyCollection(4326, []); - static::assertSame('GEOMETRYCOLLECTION Z EMPTY', (new WktTextStrategy())->executeStrategy($collection)); + static::assertSame('GEOMETRYCOLLECTION Z EMPTY', (new WktTextStrategy())->encode($collection)); } /** Write three points in their original order. */ @@ -66,7 +66,7 @@ public function testLineString(): void { $line = new LineString([[0, 0, 5], [2, 3, 6], [4, 1, 7]], 4326); - static::assertSame('LINESTRING Z (0 0 5, 2 3 6, 4 1 7)', (new WktTextStrategy())->executeStrategy($line)); + static::assertSame('LINESTRING Z (0 0 5, 2 3 6, 4 1 7)', (new WktTextStrategy())->encode($line)); } /** Preserve the type and dimension of an empty LineString. */ @@ -74,7 +74,7 @@ public function testLineStringEmpty(): void { $line = new LineString([], 4326); - static::assertSame('LINESTRING Z EMPTY', (new WktTextStrategy())->executeStrategy($line)); + static::assertSame('LINESTRING Z EMPTY', (new WktTextStrategy())->encode($line)); } /** Write two lines in their original order. */ @@ -85,7 +85,7 @@ public function testMultiLineString(): void [[4, 1, 7], [5, 2, 8]], ], 4326); - static::assertSame('MULTILINESTRING Z ((0 0 5, 2 3 6), (4 1 7, 5 2 8))', (new WktTextStrategy())->executeStrategy($lines)); + static::assertSame('MULTILINESTRING Z ((0 0 5, 2 3 6), (4 1 7, 5 2 8))', (new WktTextStrategy())->encode($lines)); } /** Preserve the type and dimension of an empty MultiLineString. */ @@ -93,7 +93,7 @@ public function testMultiLineStringEmpty(): void { $lines = new MultiLineString([], 4326); - static::assertSame('MULTILINESTRING Z EMPTY', (new WktTextStrategy())->executeStrategy($lines)); + static::assertSame('MULTILINESTRING Z EMPTY', (new WktTextStrategy())->encode($lines)); } /** Write two distinct points with separate parentheses. */ @@ -101,7 +101,7 @@ public function testMultiPoint(): void { $points = new MultiPoint([[1, 2, 5], [3, 4, 6]], 4326); - static::assertSame('MULTIPOINT Z ((1 2 5), (3 4 6))', (new WktTextStrategy())->executeStrategy($points)); + static::assertSame('MULTIPOINT Z ((1 2 5), (3 4 6))', (new WktTextStrategy())->encode($points)); } /** Preserve the type and dimension of an empty MultiPoint. */ @@ -109,7 +109,7 @@ public function testMultiPointEmpty(): void { $points = new MultiPoint([], 4326); - static::assertSame('MULTIPOINT Z EMPTY', (new WktTextStrategy())->executeStrategy($points)); + static::assertSame('MULTIPOINT Z EMPTY', (new WktTextStrategy())->encode($points)); } /** Write two polygons with their own closed exterior rings. */ @@ -122,7 +122,7 @@ public function testMultiPolygon(): void static::assertSame( 'MULTIPOLYGON Z (((0 0 5, 2 0 5, 0 2 5, 0 0 5)), ((3 3 6, 5 3 6, 3 5 6, 3 3 6)))', - (new WktTextStrategy())->executeStrategy($polygons) + (new WktTextStrategy())->encode($polygons) ); } @@ -131,7 +131,7 @@ public function testMultiPolygonEmpty(): void { $polygons = new MultiPolygon([], 4326); - static::assertSame('MULTIPOLYGON Z EMPTY', (new WktTextStrategy())->executeStrategy($polygons)); + static::assertSame('MULTIPOLYGON Z EMPTY', (new WktTextStrategy())->encode($polygons)); } /** Write a point with fractional and negative ordinates. */ @@ -139,7 +139,7 @@ public function testPoint(): void { $point = new Point(2.5, -3, 5, 4326); - static::assertSame('POINT Z (2.5 -3 5)', (new WktTextStrategy())->executeStrategy($point)); + static::assertSame('POINT Z (2.5 -3 5)', (new WktTextStrategy())->encode($point)); } /** Preserve the type and dimension of an empty Point. */ @@ -147,7 +147,7 @@ public function testPointEmpty(): void { $point = new Point(srid: 4326); - static::assertSame('POINT Z EMPTY', (new WktTextStrategy())->executeStrategy($point)); + static::assertSame('POINT Z EMPTY', (new WktTextStrategy())->encode($point)); } /** Write an exterior ring followed by an interior hole. */ @@ -160,7 +160,7 @@ public function testPolygon(): void static::assertSame( 'POLYGON Z ((0 0 5, 4 0 5, 4 4 5, 0 4 5, 0 0 5), (1 1 5, 1 2 5, 2 2 5, 2 1 5, 1 1 5))', - (new WktTextStrategy())->executeStrategy($polygon) + (new WktTextStrategy())->encode($polygon) ); } @@ -169,7 +169,7 @@ public function testPolygonEmpty(): void { $polygon = new Polygon([], 4326); - static::assertSame('POLYGON Z EMPTY', (new WktTextStrategy())->executeStrategy($polygon)); + static::assertSame('POLYGON Z EMPTY', (new WktTextStrategy())->encode($polygon)); } /** Write two adjacent polygon patches sharing an edge. */ @@ -182,7 +182,7 @@ public function testPolyhedralSurface(): void static::assertSame( 'POLYHEDRALSURFACE Z (((0 0 5, 1 0 5, 1 1 5, 0 1 5, 0 0 5)), ((1 0 5, 2 0 5, 2 1 5, 1 1 5, 1 0 5)))', - (new WktTextStrategy())->executeStrategy($surface) + (new WktTextStrategy())->encode($surface) ); } @@ -191,7 +191,7 @@ public function testPolyhedralSurfaceEmpty(): void { $surface = new PolyhedralSurface([], 4326); - static::assertSame('POLYHEDRALSURFACE Z EMPTY', (new WktTextStrategy())->executeStrategy($surface)); + static::assertSame('POLYHEDRALSURFACE Z EMPTY', (new WktTextStrategy())->encode($surface)); } /** Write three vertices and the closing position. */ @@ -199,7 +199,7 @@ public function testTriangle(): void { $triangle = new Triangle([[[0, 0, 5], [2, 0, 5], [0, 2, 5], [0, 0, 5]]], 4326); - static::assertSame('TRIANGLE Z ((0 0 5, 2 0 5, 0 2 5, 0 0 5))', (new WktTextStrategy())->executeStrategy($triangle)); + static::assertSame('TRIANGLE Z ((0 0 5, 2 0 5, 0 2 5, 0 0 5))', (new WktTextStrategy())->encode($triangle)); } /** Preserve the type and dimension of an empty Triangle. */ @@ -207,6 +207,6 @@ public function testTriangleEmpty(): void { $triangle = new Triangle([], 4326); - static::assertSame('TRIANGLE Z EMPTY', (new WktTextStrategy())->executeStrategy($triangle)); + static::assertSame('TRIANGLE Z EMPTY', (new WktTextStrategy())->encode($triangle)); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkt/Examples/GeographyXyzmTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkt/Examples/GeographyXyzmTest.php similarity index 85% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkt/Examples/GeographyXyzmTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkt/Examples/GeographyXyzmTest.php index 50729a0..f1efded 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkt/Examples/GeographyXyzmTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkt/Examples/GeographyXyzmTest.php @@ -1,6 +1,6 @@ executeStrategy($collection) + (new WktTextStrategy())->encode($collection) ); } @@ -58,7 +58,7 @@ public function testGeographyCollectionEmpty(): void { $collection = new GeographyCollection(4326, []); - static::assertSame('GEOMETRYCOLLECTION ZM EMPTY', (new WktTextStrategy())->executeStrategy($collection)); + static::assertSame('GEOMETRYCOLLECTION ZM EMPTY', (new WktTextStrategy())->encode($collection)); } /** Write three points in their original order. */ @@ -66,7 +66,7 @@ public function testLineString(): void { $line = new LineString([[0, 0, 5, 10], [2, 3, 6, 20], [4, 1, 7, 30]], 4326); - static::assertSame('LINESTRING ZM (0 0 5 10, 2 3 6 20, 4 1 7 30)', (new WktTextStrategy())->executeStrategy($line)); + static::assertSame('LINESTRING ZM (0 0 5 10, 2 3 6 20, 4 1 7 30)', (new WktTextStrategy())->encode($line)); } /** Preserve the type and dimension of an empty LineString. */ @@ -74,7 +74,7 @@ public function testLineStringEmpty(): void { $line = new LineString([], 4326); - static::assertSame('LINESTRING ZM EMPTY', (new WktTextStrategy())->executeStrategy($line)); + static::assertSame('LINESTRING ZM EMPTY', (new WktTextStrategy())->encode($line)); } /** Write two lines in their original order. */ @@ -87,7 +87,7 @@ public function testMultiLineString(): void static::assertSame( 'MULTILINESTRING ZM ((0 0 5 10, 2 3 6 20), (4 1 7 30, 5 2 8 40))', - (new WktTextStrategy())->executeStrategy($lines) + (new WktTextStrategy())->encode($lines) ); } @@ -96,7 +96,7 @@ public function testMultiLineStringEmpty(): void { $lines = new MultiLineString([], 4326); - static::assertSame('MULTILINESTRING ZM EMPTY', (new WktTextStrategy())->executeStrategy($lines)); + static::assertSame('MULTILINESTRING ZM EMPTY', (new WktTextStrategy())->encode($lines)); } /** Write two distinct points with separate parentheses. */ @@ -104,7 +104,7 @@ public function testMultiPoint(): void { $points = new MultiPoint([[1, 2, 5, 10], [3, 4, 6, 20]], 4326); - static::assertSame('MULTIPOINT ZM ((1 2 5 10), (3 4 6 20))', (new WktTextStrategy())->executeStrategy($points)); + static::assertSame('MULTIPOINT ZM ((1 2 5 10), (3 4 6 20))', (new WktTextStrategy())->encode($points)); } /** Preserve the type and dimension of an empty MultiPoint. */ @@ -112,7 +112,7 @@ public function testMultiPointEmpty(): void { $points = new MultiPoint([], 4326); - static::assertSame('MULTIPOINT ZM EMPTY', (new WktTextStrategy())->executeStrategy($points)); + static::assertSame('MULTIPOINT ZM EMPTY', (new WktTextStrategy())->encode($points)); } /** Write two polygons with their own closed exterior rings. */ @@ -125,7 +125,7 @@ public function testMultiPolygon(): void static::assertSame( 'MULTIPOLYGON ZM (((0 0 5 10, 2 0 5 10, 0 2 5 10, 0 0 5 10)), ((3 3 6 20, 5 3 6 20, 3 5 6 20, 3 3 6 20)))', - (new WktTextStrategy())->executeStrategy($polygons) + (new WktTextStrategy())->encode($polygons) ); } @@ -134,7 +134,7 @@ public function testMultiPolygonEmpty(): void { $polygons = new MultiPolygon([], 4326); - static::assertSame('MULTIPOLYGON ZM EMPTY', (new WktTextStrategy())->executeStrategy($polygons)); + static::assertSame('MULTIPOLYGON ZM EMPTY', (new WktTextStrategy())->encode($polygons)); } /** Write a point with fractional and negative ordinates. */ @@ -142,7 +142,7 @@ public function testPoint(): void { $point = new Point(2.5, -3, 5, 10, 4326); - static::assertSame('POINT ZM (2.5 -3 5 10)', (new WktTextStrategy())->executeStrategy($point)); + static::assertSame('POINT ZM (2.5 -3 5 10)', (new WktTextStrategy())->encode($point)); } /** Preserve the type and dimension of an empty Point. */ @@ -150,7 +150,7 @@ public function testPointEmpty(): void { $point = new Point(srid: 4326); - static::assertSame('POINT ZM EMPTY', (new WktTextStrategy())->executeStrategy($point)); + static::assertSame('POINT ZM EMPTY', (new WktTextStrategy())->encode($point)); } /** Write an exterior ring followed by an interior hole. */ @@ -163,7 +163,7 @@ public function testPolygon(): void static::assertSame( 'POLYGON ZM ((0 0 5 10, 4 0 5 10, 4 4 5 10, 0 4 5 10, 0 0 5 10), (1 1 5 10, 1 2 5 10, 2 2 5 10, 2 1 5 10, 1 1 5 10))', - (new WktTextStrategy())->executeStrategy($polygon) + (new WktTextStrategy())->encode($polygon) ); } @@ -172,7 +172,7 @@ public function testPolygonEmpty(): void { $polygon = new Polygon([], 4326); - static::assertSame('POLYGON ZM EMPTY', (new WktTextStrategy())->executeStrategy($polygon)); + static::assertSame('POLYGON ZM EMPTY', (new WktTextStrategy())->encode($polygon)); } /** Write two adjacent polygon patches sharing an edge. */ @@ -185,7 +185,7 @@ public function testPolyhedralSurface(): void static::assertSame( 'POLYHEDRALSURFACE ZM (((0 0 5 10, 1 0 5 10, 1 1 5 10, 0 1 5 10, 0 0 5 10)), ((1 0 5 10, 2 0 5 10, 2 1 5 10, 1 1 5 10, 1 0 5 10)))', - (new WktTextStrategy())->executeStrategy($surface) + (new WktTextStrategy())->encode($surface) ); } @@ -194,7 +194,7 @@ public function testPolyhedralSurfaceEmpty(): void { $surface = new PolyhedralSurface([], 4326); - static::assertSame('POLYHEDRALSURFACE ZM EMPTY', (new WktTextStrategy())->executeStrategy($surface)); + static::assertSame('POLYHEDRALSURFACE ZM EMPTY', (new WktTextStrategy())->encode($surface)); } /** Write three vertices and the closing position. */ @@ -202,7 +202,7 @@ public function testTriangle(): void { $triangle = new Triangle([[[0, 0, 5, 10], [2, 0, 5, 10], [0, 2, 5, 10], [0, 0, 5, 10]]], 4326); - static::assertSame('TRIANGLE ZM ((0 0 5 10, 2 0 5 10, 0 2 5 10, 0 0 5 10))', (new WktTextStrategy())->executeStrategy($triangle)); + static::assertSame('TRIANGLE ZM ((0 0 5 10, 2 0 5 10, 0 2 5 10, 0 0 5 10))', (new WktTextStrategy())->encode($triangle)); } /** Preserve the type and dimension of an empty Triangle. */ @@ -210,6 +210,6 @@ public function testTriangleEmpty(): void { $triangle = new Triangle([], 4326); - static::assertSame('TRIANGLE ZM EMPTY', (new WktTextStrategy())->executeStrategy($triangle)); + static::assertSame('TRIANGLE ZM EMPTY', (new WktTextStrategy())->encode($triangle)); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkt/Examples/GeometryXyTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkt/Examples/GeometryXyTest.php similarity index 85% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkt/Examples/GeometryXyTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkt/Examples/GeometryXyTest.php index aa926f9..9208bc3 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkt/Examples/GeometryXyTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkt/Examples/GeometryXyTest.php @@ -1,6 +1,6 @@ executeStrategy($collection) + (new WktTextStrategy())->encode($collection) ); } @@ -57,7 +57,7 @@ public function testGeometryCollectionEmpty(): void { $collection = new GeometryCollection(4326, []); - static::assertSame('GEOMETRYCOLLECTION EMPTY', (new WktTextStrategy())->executeStrategy($collection)); + static::assertSame('GEOMETRYCOLLECTION EMPTY', (new WktTextStrategy())->encode($collection)); } /** Write three points in their original order. */ @@ -65,7 +65,7 @@ public function testLineString(): void { $line = new LineString([[0, 0], [2, 3], [4, 1]], 4326); - static::assertSame('LINESTRING (0 0, 2 3, 4 1)', (new WktTextStrategy())->executeStrategy($line)); + static::assertSame('LINESTRING (0 0, 2 3, 4 1)', (new WktTextStrategy())->encode($line)); } /** Preserve the type and dimension of an empty LineString. */ @@ -73,7 +73,7 @@ public function testLineStringEmpty(): void { $line = new LineString([], 4326); - static::assertSame('LINESTRING EMPTY', (new WktTextStrategy())->executeStrategy($line)); + static::assertSame('LINESTRING EMPTY', (new WktTextStrategy())->encode($line)); } /** Write two lines in their original order. */ @@ -84,7 +84,7 @@ public function testMultiLineString(): void [[4, 1], [5, 2]], ], 4326); - static::assertSame('MULTILINESTRING ((0 0, 2 3), (4 1, 5 2))', (new WktTextStrategy())->executeStrategy($lines)); + static::assertSame('MULTILINESTRING ((0 0, 2 3), (4 1, 5 2))', (new WktTextStrategy())->encode($lines)); } /** Preserve the type and dimension of an empty MultiLineString. */ @@ -92,7 +92,7 @@ public function testMultiLineStringEmpty(): void { $lines = new MultiLineString([], 4326); - static::assertSame('MULTILINESTRING EMPTY', (new WktTextStrategy())->executeStrategy($lines)); + static::assertSame('MULTILINESTRING EMPTY', (new WktTextStrategy())->encode($lines)); } /** Write two distinct points with separate parentheses. */ @@ -100,7 +100,7 @@ public function testMultiPoint(): void { $points = new MultiPoint([[1, 2], [3, 4]], 4326); - static::assertSame('MULTIPOINT ((1 2), (3 4))', (new WktTextStrategy())->executeStrategy($points)); + static::assertSame('MULTIPOINT ((1 2), (3 4))', (new WktTextStrategy())->encode($points)); } /** Preserve the type and dimension of an empty MultiPoint. */ @@ -108,7 +108,7 @@ public function testMultiPointEmpty(): void { $points = new MultiPoint([], 4326); - static::assertSame('MULTIPOINT EMPTY', (new WktTextStrategy())->executeStrategy($points)); + static::assertSame('MULTIPOINT EMPTY', (new WktTextStrategy())->encode($points)); } /** Write two polygons with their own closed exterior rings. */ @@ -121,7 +121,7 @@ public function testMultiPolygon(): void static::assertSame( 'MULTIPOLYGON (((0 0, 2 0, 0 2, 0 0)), ((3 3, 5 3, 3 5, 3 3)))', - (new WktTextStrategy())->executeStrategy($polygons) + (new WktTextStrategy())->encode($polygons) ); } @@ -130,7 +130,7 @@ public function testMultiPolygonEmpty(): void { $polygons = new MultiPolygon([], 4326); - static::assertSame('MULTIPOLYGON EMPTY', (new WktTextStrategy())->executeStrategy($polygons)); + static::assertSame('MULTIPOLYGON EMPTY', (new WktTextStrategy())->encode($polygons)); } /** Write a point with fractional and negative ordinates. */ @@ -138,7 +138,7 @@ public function testPoint(): void { $point = new Point(2.5, -3, 4326); - static::assertSame('POINT (2.5 -3)', (new WktTextStrategy())->executeStrategy($point)); + static::assertSame('POINT (2.5 -3)', (new WktTextStrategy())->encode($point)); } /** Preserve the type and dimension of an empty Point. */ @@ -146,7 +146,7 @@ public function testPointEmpty(): void { $point = new Point(srid: 4326); - static::assertSame('POINT EMPTY', (new WktTextStrategy())->executeStrategy($point)); + static::assertSame('POINT EMPTY', (new WktTextStrategy())->encode($point)); } /** Write an exterior ring followed by an interior hole. */ @@ -159,7 +159,7 @@ public function testPolygon(): void static::assertSame( 'POLYGON ((0 0, 4 0, 4 4, 0 4, 0 0), (1 1, 1 2, 2 2, 2 1, 1 1))', - (new WktTextStrategy())->executeStrategy($polygon) + (new WktTextStrategy())->encode($polygon) ); } @@ -168,7 +168,7 @@ public function testPolygonEmpty(): void { $polygon = new Polygon([], 4326); - static::assertSame('POLYGON EMPTY', (new WktTextStrategy())->executeStrategy($polygon)); + static::assertSame('POLYGON EMPTY', (new WktTextStrategy())->encode($polygon)); } /** Write three vertices and the closing position. */ @@ -176,7 +176,7 @@ public function testTriangle(): void { $triangle = new Triangle([[[0, 0], [2, 0], [0, 2], [0, 0]]], 4326); - static::assertSame('TRIANGLE ((0 0, 2 0, 0 2, 0 0))', (new WktTextStrategy())->executeStrategy($triangle)); + static::assertSame('TRIANGLE ((0 0, 2 0, 0 2, 0 0))', (new WktTextStrategy())->encode($triangle)); } /** Preserve the type and dimension of an empty Triangle. */ @@ -184,6 +184,6 @@ public function testTriangleEmpty(): void { $triangle = new Triangle([], 4326); - static::assertSame('TRIANGLE EMPTY', (new WktTextStrategy())->executeStrategy($triangle)); + static::assertSame('TRIANGLE EMPTY', (new WktTextStrategy())->encode($triangle)); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkt/Examples/GeometryXymTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkt/Examples/GeometryXymTest.php similarity index 84% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkt/Examples/GeometryXymTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkt/Examples/GeometryXymTest.php index ef2f992..5b2d40d 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkt/Examples/GeometryXymTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkt/Examples/GeometryXymTest.php @@ -1,6 +1,6 @@ executeStrategy($collection) + (new WktTextStrategy())->encode($collection) ); } @@ -57,7 +57,7 @@ public function testGeometryCollectionEmpty(): void { $collection = new GeometryCollection(4326, []); - static::assertSame('GEOMETRYCOLLECTION M EMPTY', (new WktTextStrategy())->executeStrategy($collection)); + static::assertSame('GEOMETRYCOLLECTION M EMPTY', (new WktTextStrategy())->encode($collection)); } /** Write three points in their original order. */ @@ -65,7 +65,7 @@ public function testLineString(): void { $line = new LineString([[0, 0, 10], [2, 3, 20], [4, 1, 30]], 4326); - static::assertSame('LINESTRING M (0 0 10, 2 3 20, 4 1 30)', (new WktTextStrategy())->executeStrategy($line)); + static::assertSame('LINESTRING M (0 0 10, 2 3 20, 4 1 30)', (new WktTextStrategy())->encode($line)); } /** Preserve the type and dimension of an empty LineString. */ @@ -73,7 +73,7 @@ public function testLineStringEmpty(): void { $line = new LineString([], 4326); - static::assertSame('LINESTRING M EMPTY', (new WktTextStrategy())->executeStrategy($line)); + static::assertSame('LINESTRING M EMPTY', (new WktTextStrategy())->encode($line)); } /** Write two lines in their original order. */ @@ -84,7 +84,7 @@ public function testMultiLineString(): void [[4, 1, 30], [5, 2, 40]], ], 4326); - static::assertSame('MULTILINESTRING M ((0 0 10, 2 3 20), (4 1 30, 5 2 40))', (new WktTextStrategy())->executeStrategy($lines)); + static::assertSame('MULTILINESTRING M ((0 0 10, 2 3 20), (4 1 30, 5 2 40))', (new WktTextStrategy())->encode($lines)); } /** Preserve the type and dimension of an empty MultiLineString. */ @@ -92,7 +92,7 @@ public function testMultiLineStringEmpty(): void { $lines = new MultiLineString([], 4326); - static::assertSame('MULTILINESTRING M EMPTY', (new WktTextStrategy())->executeStrategy($lines)); + static::assertSame('MULTILINESTRING M EMPTY', (new WktTextStrategy())->encode($lines)); } /** Write two distinct points with separate parentheses. */ @@ -100,7 +100,7 @@ public function testMultiPoint(): void { $points = new MultiPoint([[1, 2, 10], [3, 4, 20]], 4326); - static::assertSame('MULTIPOINT M ((1 2 10), (3 4 20))', (new WktTextStrategy())->executeStrategy($points)); + static::assertSame('MULTIPOINT M ((1 2 10), (3 4 20))', (new WktTextStrategy())->encode($points)); } /** Preserve the type and dimension of an empty MultiPoint. */ @@ -108,7 +108,7 @@ public function testMultiPointEmpty(): void { $points = new MultiPoint([], 4326); - static::assertSame('MULTIPOINT M EMPTY', (new WktTextStrategy())->executeStrategy($points)); + static::assertSame('MULTIPOINT M EMPTY', (new WktTextStrategy())->encode($points)); } /** Write two polygons with their own closed exterior rings. */ @@ -121,7 +121,7 @@ public function testMultiPolygon(): void static::assertSame( 'MULTIPOLYGON M (((0 0 10, 2 0 10, 0 2 10, 0 0 10)), ((3 3 20, 5 3 20, 3 5 20, 3 3 20)))', - (new WktTextStrategy())->executeStrategy($polygons) + (new WktTextStrategy())->encode($polygons) ); } @@ -130,7 +130,7 @@ public function testMultiPolygonEmpty(): void { $polygons = new MultiPolygon([], 4326); - static::assertSame('MULTIPOLYGON M EMPTY', (new WktTextStrategy())->executeStrategy($polygons)); + static::assertSame('MULTIPOLYGON M EMPTY', (new WktTextStrategy())->encode($polygons)); } /** Write a point with fractional and negative ordinates. */ @@ -138,7 +138,7 @@ public function testPoint(): void { $point = new Point(2.5, -3, 10, 4326); - static::assertSame('POINT M (2.5 -3 10)', (new WktTextStrategy())->executeStrategy($point)); + static::assertSame('POINT M (2.5 -3 10)', (new WktTextStrategy())->encode($point)); } /** Preserve the type and dimension of an empty Point. */ @@ -146,7 +146,7 @@ public function testPointEmpty(): void { $point = new Point(srid: 4326); - static::assertSame('POINT M EMPTY', (new WktTextStrategy())->executeStrategy($point)); + static::assertSame('POINT M EMPTY', (new WktTextStrategy())->encode($point)); } /** Write an exterior ring followed by an interior hole. */ @@ -159,7 +159,7 @@ public function testPolygon(): void static::assertSame( 'POLYGON M ((0 0 10, 4 0 10, 4 4 10, 0 4 10, 0 0 10), (1 1 10, 1 2 10, 2 2 10, 2 1 10, 1 1 10))', - (new WktTextStrategy())->executeStrategy($polygon) + (new WktTextStrategy())->encode($polygon) ); } @@ -168,7 +168,7 @@ public function testPolygonEmpty(): void { $polygon = new Polygon([], 4326); - static::assertSame('POLYGON M EMPTY', (new WktTextStrategy())->executeStrategy($polygon)); + static::assertSame('POLYGON M EMPTY', (new WktTextStrategy())->encode($polygon)); } /** Write three vertices and the closing position. */ @@ -176,7 +176,7 @@ public function testTriangle(): void { $triangle = new Triangle([[[0, 0, 10], [2, 0, 10], [0, 2, 10], [0, 0, 10]]], 4326); - static::assertSame('TRIANGLE M ((0 0 10, 2 0 10, 0 2 10, 0 0 10))', (new WktTextStrategy())->executeStrategy($triangle)); + static::assertSame('TRIANGLE M ((0 0 10, 2 0 10, 0 2 10, 0 0 10))', (new WktTextStrategy())->encode($triangle)); } /** Preserve the type and dimension of an empty Triangle. */ @@ -184,6 +184,6 @@ public function testTriangleEmpty(): void { $triangle = new Triangle([], 4326); - static::assertSame('TRIANGLE M EMPTY', (new WktTextStrategy())->executeStrategy($triangle)); + static::assertSame('TRIANGLE M EMPTY', (new WktTextStrategy())->encode($triangle)); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkt/Examples/GeometryXyzTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkt/Examples/GeometryXyzTest.php similarity index 85% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkt/Examples/GeometryXyzTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkt/Examples/GeometryXyzTest.php index 370c340..7f34263 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkt/Examples/GeometryXyzTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkt/Examples/GeometryXyzTest.php @@ -1,6 +1,6 @@ executeStrategy($collection) + (new WktTextStrategy())->encode($collection) ); } @@ -58,7 +58,7 @@ public function testGeometryCollectionEmpty(): void { $collection = new GeometryCollection(4326, []); - static::assertSame('GEOMETRYCOLLECTION Z EMPTY', (new WktTextStrategy())->executeStrategy($collection)); + static::assertSame('GEOMETRYCOLLECTION Z EMPTY', (new WktTextStrategy())->encode($collection)); } /** Write three points in their original order. */ @@ -66,7 +66,7 @@ public function testLineString(): void { $line = new LineString([[0, 0, 5], [2, 3, 6], [4, 1, 7]], 4326); - static::assertSame('LINESTRING Z (0 0 5, 2 3 6, 4 1 7)', (new WktTextStrategy())->executeStrategy($line)); + static::assertSame('LINESTRING Z (0 0 5, 2 3 6, 4 1 7)', (new WktTextStrategy())->encode($line)); } /** Preserve the type and dimension of an empty LineString. */ @@ -74,7 +74,7 @@ public function testLineStringEmpty(): void { $line = new LineString([], 4326); - static::assertSame('LINESTRING Z EMPTY', (new WktTextStrategy())->executeStrategy($line)); + static::assertSame('LINESTRING Z EMPTY', (new WktTextStrategy())->encode($line)); } /** Write two lines in their original order. */ @@ -85,7 +85,7 @@ public function testMultiLineString(): void [[4, 1, 7], [5, 2, 8]], ], 4326); - static::assertSame('MULTILINESTRING Z ((0 0 5, 2 3 6), (4 1 7, 5 2 8))', (new WktTextStrategy())->executeStrategy($lines)); + static::assertSame('MULTILINESTRING Z ((0 0 5, 2 3 6), (4 1 7, 5 2 8))', (new WktTextStrategy())->encode($lines)); } /** Preserve the type and dimension of an empty MultiLineString. */ @@ -93,7 +93,7 @@ public function testMultiLineStringEmpty(): void { $lines = new MultiLineString([], 4326); - static::assertSame('MULTILINESTRING Z EMPTY', (new WktTextStrategy())->executeStrategy($lines)); + static::assertSame('MULTILINESTRING Z EMPTY', (new WktTextStrategy())->encode($lines)); } /** Write two distinct points with separate parentheses. */ @@ -101,7 +101,7 @@ public function testMultiPoint(): void { $points = new MultiPoint([[1, 2, 5], [3, 4, 6]], 4326); - static::assertSame('MULTIPOINT Z ((1 2 5), (3 4 6))', (new WktTextStrategy())->executeStrategy($points)); + static::assertSame('MULTIPOINT Z ((1 2 5), (3 4 6))', (new WktTextStrategy())->encode($points)); } /** Preserve the type and dimension of an empty MultiPoint. */ @@ -109,7 +109,7 @@ public function testMultiPointEmpty(): void { $points = new MultiPoint([], 4326); - static::assertSame('MULTIPOINT Z EMPTY', (new WktTextStrategy())->executeStrategy($points)); + static::assertSame('MULTIPOINT Z EMPTY', (new WktTextStrategy())->encode($points)); } /** Write two polygons with their own closed exterior rings. */ @@ -122,7 +122,7 @@ public function testMultiPolygon(): void static::assertSame( 'MULTIPOLYGON Z (((0 0 5, 2 0 5, 0 2 5, 0 0 5)), ((3 3 6, 5 3 6, 3 5 6, 3 3 6)))', - (new WktTextStrategy())->executeStrategy($polygons) + (new WktTextStrategy())->encode($polygons) ); } @@ -131,7 +131,7 @@ public function testMultiPolygonEmpty(): void { $polygons = new MultiPolygon([], 4326); - static::assertSame('MULTIPOLYGON Z EMPTY', (new WktTextStrategy())->executeStrategy($polygons)); + static::assertSame('MULTIPOLYGON Z EMPTY', (new WktTextStrategy())->encode($polygons)); } /** Write a point with fractional and negative ordinates. */ @@ -139,7 +139,7 @@ public function testPoint(): void { $point = new Point(2.5, -3, 5, 4326); - static::assertSame('POINT Z (2.5 -3 5)', (new WktTextStrategy())->executeStrategy($point)); + static::assertSame('POINT Z (2.5 -3 5)', (new WktTextStrategy())->encode($point)); } /** Preserve the type and dimension of an empty Point. */ @@ -147,7 +147,7 @@ public function testPointEmpty(): void { $point = new Point(srid: 4326); - static::assertSame('POINT Z EMPTY', (new WktTextStrategy())->executeStrategy($point)); + static::assertSame('POINT Z EMPTY', (new WktTextStrategy())->encode($point)); } /** Write an exterior ring followed by an interior hole. */ @@ -160,7 +160,7 @@ public function testPolygon(): void static::assertSame( 'POLYGON Z ((0 0 5, 4 0 5, 4 4 5, 0 4 5, 0 0 5), (1 1 5, 1 2 5, 2 2 5, 2 1 5, 1 1 5))', - (new WktTextStrategy())->executeStrategy($polygon) + (new WktTextStrategy())->encode($polygon) ); } @@ -169,7 +169,7 @@ public function testPolygonEmpty(): void { $polygon = new Polygon([], 4326); - static::assertSame('POLYGON Z EMPTY', (new WktTextStrategy())->executeStrategy($polygon)); + static::assertSame('POLYGON Z EMPTY', (new WktTextStrategy())->encode($polygon)); } /** Write two adjacent polygon patches sharing an edge. */ @@ -182,7 +182,7 @@ public function testPolyhedralSurface(): void static::assertSame( 'POLYHEDRALSURFACE Z (((0 0 5, 1 0 5, 1 1 5, 0 1 5, 0 0 5)), ((1 0 5, 2 0 5, 2 1 5, 1 1 5, 1 0 5)))', - (new WktTextStrategy())->executeStrategy($surface) + (new WktTextStrategy())->encode($surface) ); } @@ -191,7 +191,7 @@ public function testPolyhedralSurfaceEmpty(): void { $surface = new PolyhedralSurface([], 4326); - static::assertSame('POLYHEDRALSURFACE Z EMPTY', (new WktTextStrategy())->executeStrategy($surface)); + static::assertSame('POLYHEDRALSURFACE Z EMPTY', (new WktTextStrategy())->encode($surface)); } /** Write three vertices and the closing position. */ @@ -199,7 +199,7 @@ public function testTriangle(): void { $triangle = new Triangle([[[0, 0, 5], [2, 0, 5], [0, 2, 5], [0, 0, 5]]], 4326); - static::assertSame('TRIANGLE Z ((0 0 5, 2 0 5, 0 2 5, 0 0 5))', (new WktTextStrategy())->executeStrategy($triangle)); + static::assertSame('TRIANGLE Z ((0 0 5, 2 0 5, 0 2 5, 0 0 5))', (new WktTextStrategy())->encode($triangle)); } /** Preserve the type and dimension of an empty Triangle. */ @@ -207,6 +207,6 @@ public function testTriangleEmpty(): void { $triangle = new Triangle([], 4326); - static::assertSame('TRIANGLE Z EMPTY', (new WktTextStrategy())->executeStrategy($triangle)); + static::assertSame('TRIANGLE Z EMPTY', (new WktTextStrategy())->encode($triangle)); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkt/Examples/GeometryXyzmTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkt/Examples/GeometryXyzmTest.php similarity index 85% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkt/Examples/GeometryXyzmTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkt/Examples/GeometryXyzmTest.php index 884f0d7..3a2ff56 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkt/Examples/GeometryXyzmTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkt/Examples/GeometryXyzmTest.php @@ -1,6 +1,6 @@ executeStrategy($collection) + (new WktTextStrategy())->encode($collection) ); } @@ -58,7 +58,7 @@ public function testGeometryCollectionEmpty(): void { $collection = new GeometryCollection(4326, []); - static::assertSame('GEOMETRYCOLLECTION ZM EMPTY', (new WktTextStrategy())->executeStrategy($collection)); + static::assertSame('GEOMETRYCOLLECTION ZM EMPTY', (new WktTextStrategy())->encode($collection)); } /** Write three points in their original order. */ @@ -66,7 +66,7 @@ public function testLineString(): void { $line = new LineString([[0, 0, 5, 10], [2, 3, 6, 20], [4, 1, 7, 30]], 4326); - static::assertSame('LINESTRING ZM (0 0 5 10, 2 3 6 20, 4 1 7 30)', (new WktTextStrategy())->executeStrategy($line)); + static::assertSame('LINESTRING ZM (0 0 5 10, 2 3 6 20, 4 1 7 30)', (new WktTextStrategy())->encode($line)); } /** Preserve the type and dimension of an empty LineString. */ @@ -74,7 +74,7 @@ public function testLineStringEmpty(): void { $line = new LineString([], 4326); - static::assertSame('LINESTRING ZM EMPTY', (new WktTextStrategy())->executeStrategy($line)); + static::assertSame('LINESTRING ZM EMPTY', (new WktTextStrategy())->encode($line)); } /** Write two lines in their original order. */ @@ -87,7 +87,7 @@ public function testMultiLineString(): void static::assertSame( 'MULTILINESTRING ZM ((0 0 5 10, 2 3 6 20), (4 1 7 30, 5 2 8 40))', - (new WktTextStrategy())->executeStrategy($lines) + (new WktTextStrategy())->encode($lines) ); } @@ -96,7 +96,7 @@ public function testMultiLineStringEmpty(): void { $lines = new MultiLineString([], 4326); - static::assertSame('MULTILINESTRING ZM EMPTY', (new WktTextStrategy())->executeStrategy($lines)); + static::assertSame('MULTILINESTRING ZM EMPTY', (new WktTextStrategy())->encode($lines)); } /** Write two distinct points with separate parentheses. */ @@ -104,7 +104,7 @@ public function testMultiPoint(): void { $points = new MultiPoint([[1, 2, 5, 10], [3, 4, 6, 20]], 4326); - static::assertSame('MULTIPOINT ZM ((1 2 5 10), (3 4 6 20))', (new WktTextStrategy())->executeStrategy($points)); + static::assertSame('MULTIPOINT ZM ((1 2 5 10), (3 4 6 20))', (new WktTextStrategy())->encode($points)); } /** Preserve the type and dimension of an empty MultiPoint. */ @@ -112,7 +112,7 @@ public function testMultiPointEmpty(): void { $points = new MultiPoint([], 4326); - static::assertSame('MULTIPOINT ZM EMPTY', (new WktTextStrategy())->executeStrategy($points)); + static::assertSame('MULTIPOINT ZM EMPTY', (new WktTextStrategy())->encode($points)); } /** Write two polygons with their own closed exterior rings. */ @@ -125,7 +125,7 @@ public function testMultiPolygon(): void static::assertSame( 'MULTIPOLYGON ZM (((0 0 5 10, 2 0 5 10, 0 2 5 10, 0 0 5 10)), ((3 3 6 20, 5 3 6 20, 3 5 6 20, 3 3 6 20)))', - (new WktTextStrategy())->executeStrategy($polygons) + (new WktTextStrategy())->encode($polygons) ); } @@ -134,7 +134,7 @@ public function testMultiPolygonEmpty(): void { $polygons = new MultiPolygon([], 4326); - static::assertSame('MULTIPOLYGON ZM EMPTY', (new WktTextStrategy())->executeStrategy($polygons)); + static::assertSame('MULTIPOLYGON ZM EMPTY', (new WktTextStrategy())->encode($polygons)); } /** Write a point with fractional and negative ordinates. */ @@ -142,7 +142,7 @@ public function testPoint(): void { $point = new Point(2.5, -3, 5, 10, 4326); - static::assertSame('POINT ZM (2.5 -3 5 10)', (new WktTextStrategy())->executeStrategy($point)); + static::assertSame('POINT ZM (2.5 -3 5 10)', (new WktTextStrategy())->encode($point)); } /** Preserve the type and dimension of an empty Point. */ @@ -150,7 +150,7 @@ public function testPointEmpty(): void { $point = new Point(srid: 4326); - static::assertSame('POINT ZM EMPTY', (new WktTextStrategy())->executeStrategy($point)); + static::assertSame('POINT ZM EMPTY', (new WktTextStrategy())->encode($point)); } /** Write an exterior ring followed by an interior hole. */ @@ -163,7 +163,7 @@ public function testPolygon(): void static::assertSame( 'POLYGON ZM ((0 0 5 10, 4 0 5 10, 4 4 5 10, 0 4 5 10, 0 0 5 10), (1 1 5 10, 1 2 5 10, 2 2 5 10, 2 1 5 10, 1 1 5 10))', - (new WktTextStrategy())->executeStrategy($polygon) + (new WktTextStrategy())->encode($polygon) ); } @@ -172,7 +172,7 @@ public function testPolygonEmpty(): void { $polygon = new Polygon([], 4326); - static::assertSame('POLYGON ZM EMPTY', (new WktTextStrategy())->executeStrategy($polygon)); + static::assertSame('POLYGON ZM EMPTY', (new WktTextStrategy())->encode($polygon)); } /** Write two adjacent polygon patches sharing an edge. */ @@ -185,7 +185,7 @@ public function testPolyhedralSurface(): void static::assertSame( 'POLYHEDRALSURFACE ZM (((0 0 5 10, 1 0 5 10, 1 1 5 10, 0 1 5 10, 0 0 5 10)), ((1 0 5 10, 2 0 5 10, 2 1 5 10, 1 1 5 10, 1 0 5 10)))', - (new WktTextStrategy())->executeStrategy($surface) + (new WktTextStrategy())->encode($surface) ); } @@ -194,7 +194,7 @@ public function testPolyhedralSurfaceEmpty(): void { $surface = new PolyhedralSurface([], 4326); - static::assertSame('POLYHEDRALSURFACE ZM EMPTY', (new WktTextStrategy())->executeStrategy($surface)); + static::assertSame('POLYHEDRALSURFACE ZM EMPTY', (new WktTextStrategy())->encode($surface)); } /** Write three vertices and the closing position. */ @@ -202,7 +202,7 @@ public function testTriangle(): void { $triangle = new Triangle([[[0, 0, 5, 10], [2, 0, 5, 10], [0, 2, 5, 10], [0, 0, 5, 10]]], 4326); - static::assertSame('TRIANGLE ZM ((0 0 5 10, 2 0 5 10, 0 2 5 10, 0 0 5 10))', (new WktTextStrategy())->executeStrategy($triangle)); + static::assertSame('TRIANGLE ZM ((0 0 5 10, 2 0 5 10, 0 2 5 10, 0 0 5 10))', (new WktTextStrategy())->encode($triangle)); } /** Preserve the type and dimension of an empty Triangle. */ @@ -210,6 +210,6 @@ public function testTriangleEmpty(): void { $triangle = new Triangle([], 4326); - static::assertSame('TRIANGLE ZM EMPTY', (new WktTextStrategy())->executeStrategy($triangle)); + static::assertSame('TRIANGLE ZM EMPTY', (new WktTextStrategy())->encode($triangle)); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/WktStrategyTest.php b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/WktStrategyTest.php similarity index 91% rename from tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/WktStrategyTest.php rename to tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/WktStrategyTest.php index c729fb0..e1328ed 100644 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/WktStrategyTest.php +++ b/tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/WktStrategyTest.php @@ -1,6 +1,6 @@ executeStrategy($spatial)); + static::assertSame($expected, (new WktTextStrategy())->encode($spatial)); } /** @@ -153,7 +153,7 @@ public function testNestedCollections(array $coordinates, array $positions, stri static::assertSame( 'GEOMETRYCOLLECTION'.$marker.' (POINT'.$marker.' EMPTY, GEOMETRYCOLLECTION'.$marker.' (POINT'.$marker.' ('.$positions[1].')), GEOMETRYCOLLECTION'.$marker.' EMPTY)', - (new WktTextStrategy())->executeStrategy($collection) + (new WktTextStrategy())->encode($collection) ); } @@ -182,7 +182,7 @@ public static function dimensionProvider(): \Generator public function testNonFiniteCoordinate(float $coordinate): void { $this->expectException(\JsonException::class); - (new WktTextStrategy())->executeStrategy(new Point($coordinate, 0)); + (new WktTextStrategy())->encode(new Point($coordinate, 0)); } /** @return \Generator */ @@ -204,7 +204,7 @@ public function testNumericLocale(): void } try { - static::assertSame('POINT (42.42 -2.5)', (new WktTextStrategy())->executeStrategy(new Point(42.42, -2.5))); + static::assertSame('POINT (42.42 -2.5)', (new WktTextStrategy())->encode(new Point(42.42, -2.5))); } finally { setlocale(LC_NUMERIC, $previous); } @@ -216,7 +216,7 @@ public function testNumericPrecision(): void $collection = new GeometryCollection(0, [new Point(-42.42, 2.123456789012345), new Point(1.0e-20, PHP_INT_MAX)]); static::assertSame( 'GEOMETRYCOLLECTION (POINT (-42.42 2.123456789012345), POINT (1.0e-20 '.PHP_INT_MAX.'))', - (new WktTextStrategy())->executeStrategy($collection) + (new WktTextStrategy())->encode($collection) ); } @@ -229,7 +229,7 @@ public function testPolygonWithHole(): void ]); static::assertSame( 'POLYGON ((0 0, 4 0, 4 4, 0 4, 0 0), (1 1, 1 2, 2 2, 2 1, 1 1))', - (new WktTextStrategy())->executeStrategy($polygon) + (new WktTextStrategy())->encode($polygon) ); } @@ -240,7 +240,7 @@ public function testUnsupportedInterface(): void $spatial->method('getType')->willReturn(GeometryTypeEnum::POINT); $spatial->method('isEmpty')->willReturn(false); $this->expectException(UnsupportedSpatialInterfaceException::class); - (new WktTextStrategy())->executeStrategy($spatial); + (new WktTextStrategy())->encode($spatial); } /** Test unimplemented enum cases are rejected, even when empty. */ @@ -251,6 +251,6 @@ public function testUnsupportedType(): void $spatial->method('isEmpty')->willReturn(true); $this->expectException(UnsupportedSpatialTypeException::class); $this->expectExceptionMessage('WKT adapter does not support spatial type CircularString'); - (new WktTextStrategy())->executeStrategy($spatial); + (new WktTextStrategy())->encode($spatial); } } diff --git a/tests/LongitudeOne/SpatialWriter/Tests/Unit/WriterTest.php b/tests/LongitudeOne/SpatialWriter/Tests/Unit/WriterTest.php deleted file mode 100644 index dbb7330..0000000 --- a/tests/LongitudeOne/SpatialWriter/Tests/Unit/WriterTest.php +++ /dev/null @@ -1,97 +0,0 @@ - 2024-2026 - * Copyright Longitude One 2024-2026 - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - * - */ - -declare(strict_types=1); - -namespace LongitudeOne\SpatialWriter\Tests\Unit; - -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Point; -use LongitudeOne\SpatialWriter\Strategy\EwkbBinaryStrategy; -use LongitudeOne\SpatialWriter\Strategy\MySQLBinaryStrategy; -use LongitudeOne\SpatialWriter\Strategy\WkbBinaryStrategy; -use LongitudeOne\SpatialWriter\Strategy\WktTextStrategy; -use LongitudeOne\SpatialWriter\Writer; -use PHPUnit\Framework\TestCase; - -/** - * @internal - * - * @covers \LongitudeOne\SpatialWriter\Writer - */ -class WriterTest extends TestCase -{ - /** - * Test the binary writer with a mysql strategy. - */ - public function testBinaryWriterWithMysqlStrategy(): void - { - $strategy = new MySQLBinaryStrategy(); - $writer = new Writer($strategy); - $point = new Point(1, 2, 4326); - static::assertSame( - $strategy->executeStrategy($point), - $writer->convert($point) - ); - } - - /** - * Test the binary writer with the Well-Known Binary strategy. - */ - public function testBinaryWriterWithWkbStrategy(): void - { - $strategy = new WkbBinaryStrategy(); - $writer = new Writer($strategy); - $point = new Point(1, 2, 4326); - static::assertSame( - $strategy->executeStrategy($point), - $writer->convert($point) - ); - } - - /** - * Test the binary writer with the Well-Known Binary strategy. - */ - public function testEwkbWriterWithEwkbStrategy(): void - { - $badStrategy = new MySQLBinaryStrategy(); - $strategy = new EwkbBinaryStrategy(); - $writer = new Writer($badStrategy); - static::assertSame($badStrategy, $writer->getStrategy()); - $writer->setStrategy($strategy); - $point = new Point(1, 2, 4326); - static::assertSame( - $strategy->executeStrategy($point), - $writer->convert($point) - ); - static::assertNotSame( - $badStrategy->executeStrategy($point), - $writer->convert($point) - ); - } - - /** Test text strategies can be supplied and exchanged with binary strategies. */ - public function testTextWriter(): void - { - $point = new Point(1, 2, 4326); - $textStrategy = new WktTextStrategy(); - $binaryStrategy = new WkbBinaryStrategy(); - $writer = new Writer($textStrategy); - static::assertSame($textStrategy, $writer->getStrategy()); - static::assertSame('POINT (1 2)', $writer->convert($point)); - static::assertSame($writer, $writer->setStrategy($binaryStrategy)); - static::assertSame($binaryStrategy->executeStrategy($point), $writer->convert($point)); - $writer->setStrategy($textStrategy); - static::assertSame('POINT (1 2)', $writer->convert($point)); - } -} diff --git a/tests/README.md b/tests/README.md index cae9d15..638d246 100644 --- a/tests/README.md +++ b/tests/README.md @@ -1,6 +1,6 @@ # Test Execution Guide -This directory contains the automated test suite for the spatial writer library. +This directory contains the automated test suite for the spatial encoder library. ## How tests are executed @@ -28,7 +28,7 @@ it does not return the internal representation with its SRID prefix. `Strategy/MySQL/GeometryCoordinateOrderTest.php` and `Strategy/MySQL/GeographyCoordinateOrderTest.php`, under -`LongitudeOne/SpatialWriter/Tests/Unit/`, contain literal regression examples +`LongitudeOne/SpatialEncoder/Tests/Unit/`, contain literal regression examples for all seven supported types, empty and nested collections, polygon holes, and the Paris point from issue #5. Each family also has separate tests for nested MultiPoint, MultiLineString and MultiPolygon values with SRID 4326 @@ -63,7 +63,7 @@ composer test-local This command generates a coverage report at ./phpunit-cache/coverage.xml that can be imported by your IDE to track code coverage. -![Sunburst](https://codecov.io/gh/longitude-one/spatial-writer/graphs/sunburst.svg?token=NIFES3ETWH) +![Sunburst](https://codecov.io/gh/longitude-one/spatial-encoder/graphs/sunburst.svg?token=NIFES3ETWH) ## WKT strategy @@ -77,7 +77,7 @@ provides reference output; whitespace around punctuation may differ. ### Explicit WKT examples -`LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkt/Examples/` contains eight +`LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkt/Examples/` contains eight standalone test classes: `GeometryXyTest`, `GeometryXyzTest`, `GeometryXymTest`, `GeometryXyzmTest`, and their `Geography` equivalents. @@ -94,7 +94,7 @@ collections, and adjacent surface patches. Run this additional suite independently: ```bash -vendor/bin/phpunit --no-coverage tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkt/Examples +vendor/bin/phpunit --no-coverage tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkt/Examples ``` @@ -103,12 +103,12 @@ vendor/bin/phpunit --no-coverage tests/LongitudeOne/SpatialWriter/Tests/Unit/Str Run `vendor/bin/phpunit --no-coverage --filter EwktStrategyTest` for explicit EWKT examples. These tests cover nonzero, zero, and default SRIDs; empty values; Z/M/ZM dimensions; nested collections with a single outer SRID -prefix; repeated conversions; and integration with `Writer`. +prefix; repeated conversions; and integration with `Encoder`. ## Explicit ISO WKB examples -`LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkb/Examples/` contains 136 +`LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkb/Examples/` contains 136 literal examples covering all 68 concrete classes in both Geometry and Geography families and all available XY, XYZ, XYM and XYZM dimensions. Each type has a populated and an empty example, with direct constructors, @@ -123,13 +123,13 @@ with empty members and explicit failures for unsupported types/interfaces. Every example with SRID 4326 verifies that WKB omits the SRID. ```bash -vendor/bin/phpunit --no-coverage tests/LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Wkb +vendor/bin/phpunit --no-coverage tests/LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Wkb ``` ## Explicit EWKB examples -`LongitudeOne/SpatialWriter/Tests/Unit/Strategy/Ewkb/Examples/` contains 136 +`LongitudeOne/SpatialEncoder/Tests/Unit/Strategy/Ewkb/Examples/` contains 136 literal examples: populated and empty values for all 68 concrete classes. Each test includes its complete constructor, WKT comment and expected hex. The expectations use the GDAL-verified ISO coordinate payloads with EWKB