From fdd0908847167bec5fa5fff4056fd6a3af0ffeb2 Mon Sep 17 00:00:00 2001 From: Samuel Denis-D'Ortun Date: Wed, 6 Apr 2016 21:49:34 -0400 Subject: [PATCH 1/4] Add test cases to improve coverage --- .../DBAL/Platform/AbstractPlatform.php | 2 + .../Types/Geometry/MultiLineStringTest.php | 49 ++++++++++++++ .../PHP/Types/Geometry/MultiPointTest.php | 28 ++++++++ .../PHP/Types/Geometry/MultiPolygonTest.php | 67 +++++++++++++++++++ .../Tests/PHP/Types/Geometry/PointTest.php | 43 ++++++++++++ .../Tests/PHP/Types/Geometry/PolygonTest.php | 49 ++++++++++++++ 6 files changed, 238 insertions(+) diff --git a/lib/CrEOF/Spatial/DBAL/Platform/AbstractPlatform.php b/lib/CrEOF/Spatial/DBAL/Platform/AbstractPlatform.php index 789bc817..09afb184 100644 --- a/lib/CrEOF/Spatial/DBAL/Platform/AbstractPlatform.php +++ b/lib/CrEOF/Spatial/DBAL/Platform/AbstractPlatform.php @@ -110,7 +110,9 @@ private function newObjectFromValue(AbstractSpatialType $type, $value) $constName = sprintf('CrEOF\Spatial\PHP\Types\Geometry\GeometryInterface::%s', $typeName); if (! defined($constName)) { + // @codeCoverageIgnoreStart throw new InvalidValueException(sprintf('Unsupported %s type "%s".', $typeFamily, $typeName)); + // @codeCoverageIgnoreEnd } $class = sprintf('CrEOF\Spatial\PHP\Types\%s\%s', $typeFamily, constant($constName)); diff --git a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiLineStringTest.php b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiLineStringTest.php index f4362e63..7713d430 100644 --- a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiLineStringTest.php +++ b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiLineStringTest.php @@ -131,6 +131,55 @@ public function testSolidMultiLineStringFromArraysGetRings() $this->assertEquals($expected, $multiLineString->getLineStrings()); } + + + public function testSolidMultiLineStringAddRings() + { + $expected = array( + new LineString( + array( + new Point(0, 0), + new Point(10, 0), + new Point(10, 10), + new Point(0, 10), + new Point(0, 0) + ) + ), + new LineString( + array( + new Point(0, 0), + new Point(10, 0), + new Point(10, 10), + new Point(0, 10), + new Point(0, 0) + ) + ) + ); + $rings = array( + array( + array(0, 0), + array(10, 0), + array(10, 10), + array(0, 10), + array(0, 0) + ), + ); + + $multiLineString = new MultiLineString($rings); + + $multiLineString->addLineString( + array( + array(0, 0), + array(10, 0), + array(10, 10), + array(0, 10), + array(0, 0) + ) + ); + + $this->assertEquals($expected, $multiLineString->getLineStrings()); + } + public function testMultiLineStringFromObjectsGetSingleLineString() { $lineString1 = new LineString( diff --git a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPointTest.php b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPointTest.php index 8727c021..4f0be1ae 100644 --- a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPointTest.php +++ b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPointTest.php @@ -84,6 +84,34 @@ public function testMultiPointFromArraysGetPoints() $this->assertEquals($expected, $actual); } + + + public function testMultiPointAddPoints() + { + $expected = array( + new Point(0, 0), + new Point(1, 1), + new Point(2, 2), + new Point(3, 3) + ); + $multiPoint = new MultiPoint( + array( + array(0, 0), + array(1, 1), + ) + ); + + $multiPoint + ->addPoint( array(2, 2)) + ->addPoint(array(3, 3)) + ; + + $actual = $multiPoint->getPoints(); + + $this->assertCount(4, $actual); + $this->assertEquals($expected, $actual); + } + public function testMultiPointFromArraysGetSinglePoint() { $expected = new Point(1, 1); diff --git a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPolygonTest.php b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPolygonTest.php index 3c1e198d..945662c9 100644 --- a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPolygonTest.php +++ b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPolygonTest.php @@ -139,6 +139,73 @@ public function testSolidMultiPolygonFromArraysGetPolygons() $this->assertEquals($expected, $multiPolygon->getPolygons()); } + + public function testSolidMultiPolygonAddPolygon() + { + $expected = array( + new Polygon( + array( + new LineString( + array( + new Point(0, 0), + new Point(10, 0), + new Point(10, 10), + new Point(0, 10), + new Point(0, 0) + ) + ) + ) + ), + new Polygon( + array( + new LineString( + array( + new Point(5, 5), + new Point(7, 5), + new Point(7, 7), + new Point(5, 7), + new Point(5, 5) + ) + ) + ) + ) + ); + + + $polygon = new Polygon( + array( + new LineString( + array( + new Point(0, 0), + new Point(10, 0), + new Point(10, 10), + new Point(0, 10), + new Point(0, 0) + ) + ) + ) + ); + + + $multiPolygon = new MultiPolygon([ $polygon ]); + + $multiPolygon->addPolygon( + array ( + array ( + new Point(5, 5), + new Point(7, 5), + new Point(7, 7), + new Point(5, 7), + new Point(5, 5), + ), + ) + ); + + $this->assertEquals($expected, $multiPolygon->getPolygons()); + } + + + public function testMultiPolygonFromObjectsGetSinglePolygon() { $polygon1 = new Polygon( diff --git a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/PointTest.php b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/PointTest.php index 0628e5d8..54af3dcf 100644 --- a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/PointTest.php +++ b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/PointTest.php @@ -35,14 +35,23 @@ */ class PointTest extends \PHPUnit_Framework_TestCase { + public function testGoodNumericPoint() { $point1 = new Point(-73.7562317, 42.6525793); $this->assertEquals(42.6525793, $point1->getLatitude()); $this->assertEquals(-73.7562317, $point1->getLongitude()); + + $point1 + ->setLatitude(40.446111111111) + ->setLongitude( -79.948611111111); + + $this->assertEquals(40.446111111111, $point1->getLatitude()); + $this->assertEquals(-79.948611111111, $point1->getLongitude()); } + public function testGoodStringPoints() { $point2 = new Point('79:56:55W', '40:26:46N'); @@ -220,6 +229,40 @@ public function testPointWrongArgumentTypes() new Point(array(), array(), '1234'); } + /** + * Test bad string parameters - No parameters + * + * @expectedException \CrEOF\Spatial\Exception\InvalidValueException + * @expectedExceptionMessage Invalid parameters passed to CrEOF\Spatial\PHP\Types\Geometry\Point::__construct: + */ + public function testMissingArguments() + { + new Point(); + } + + + /** + * Test bad string parameters - Two invalid parameters + * + * @expectedException \CrEOF\Spatial\Exception\InvalidValueException + * @expectedExceptionMessage Invalid parameters passed to CrEOF\Spatial\PHP\Types\Geometry\Point::__construct: "", "" + */ + public function testTwoInvalidArguments() + { + new Point(null , null); + } + + /** + * Test bad string parameters - More than 3 parameters + * + * @expectedException \CrEOF\Spatial\Exception\InvalidValueException + * @expectedExceptionMessage Invalid parameters passed to CrEOF\Spatial\PHP\Types\Geometry\Point::__construct: "1", "2", "3", "4", "", "5" + */ + public function testUnusedArguments() + { + new Point(1 , 2 , 3 , 4, null , 5); + } + public function testJson() { $expected = '{"type":"Point","coordinates":[5,5]}'; diff --git a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/PolygonTest.php b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/PolygonTest.php index 256d2e03..226d1d99 100644 --- a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/PolygonTest.php +++ b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/PolygonTest.php @@ -99,6 +99,55 @@ public function testSolidPolygonFromArraysGetRings() $this->assertEquals($expected, $polygon->getRings()); } + + public function testSolidPolygonFromArrayAddRings() + { + $expected = array( + new LineString( + array( + new Point(0, 0), + new Point(10, 0), + new Point(10, 10), + new Point(0, 10), + new Point(0, 0) + ) + ), + new LineString( + array( + new Point(2, 2), + new Point(10, 0), + new Point(10, 10), + new Point(0, 10), + new Point(2, 2) + ) + ) + ); + + $rings = array( + array( + array(0, 0), + array(10, 0), + array(10, 10), + array(0, 10), + array(0, 0) + ) + ); + + $polygon = new Polygon($rings); + + $polygon->addRing( + array( + array(2, 2), + array(10, 0), + array(10, 10), + array(0, 10), + array(2, 2) + ) + ); + + $this->assertEquals($expected, $polygon->getRings()); + } + public function testRingPolygonFromObjectsGetSingleRing() { $ring1 = new LineString( From a3fdbe8b5206f2b4caafbbd6a4fbaef236977cf2 Mon Sep 17 00:00:00 2001 From: Samuel Denis-D'Ortun Date: Wed, 6 Apr 2016 21:55:22 -0400 Subject: [PATCH 2/4] Fix PHPCS notices --- .../PHP/Types/Geometry/MultiPointTest.php | 2 +- .../PHP/Types/Geometry/MultiPolygonTest.php | 22 +++++++++---------- .../Tests/PHP/Types/Geometry/PointTest.php | 6 ++--- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPointTest.php b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPointTest.php index 4f0be1ae..508be58a 100644 --- a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPointTest.php +++ b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPointTest.php @@ -102,7 +102,7 @@ public function testMultiPointAddPoints() ); $multiPoint - ->addPoint( array(2, 2)) + ->addPoint(array(2, 2)) ->addPoint(array(3, 3)) ; diff --git a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPolygonTest.php b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPolygonTest.php index 945662c9..dc698678 100644 --- a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPolygonTest.php +++ b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPolygonTest.php @@ -173,18 +173,18 @@ public function testSolidMultiPolygonAddPolygon() $polygon = new Polygon( - array( - new LineString( - array( - new Point(0, 0), - new Point(10, 0), - new Point(10, 10), - new Point(0, 10), - new Point(0, 0) - ) + array ( + new LineString( + array ( + new Point(0, 0), + new Point(10, 0), + new Point(10, 10), + new Point(0, 10), + new Point(0, 0), + ) + ), ) - ) - ); + ); $multiPolygon = new MultiPolygon([ $polygon ]); diff --git a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/PointTest.php b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/PointTest.php index 54af3dcf..bd14aef5 100644 --- a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/PointTest.php +++ b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/PointTest.php @@ -45,7 +45,7 @@ public function testGoodNumericPoint() $point1 ->setLatitude(40.446111111111) - ->setLongitude( -79.948611111111); + ->setLongitude(-79.948611111111); $this->assertEquals(40.446111111111, $point1->getLatitude()); $this->assertEquals(-79.948611111111, $point1->getLongitude()); @@ -249,7 +249,7 @@ public function testMissingArguments() */ public function testTwoInvalidArguments() { - new Point(null , null); + new Point(null, null); } /** @@ -260,7 +260,7 @@ public function testTwoInvalidArguments() */ public function testUnusedArguments() { - new Point(1 , 2 , 3 , 4, null , 5); + new Point(1, 2, 3, 4, null, 5); } public function testJson() From 702ac11d1ff3a68c29260dc23a1b4ea8bd3632a6 Mon Sep 17 00:00:00 2001 From: Samuel Denis-D'Ortun Date: Wed, 6 Apr 2016 22:00:43 -0400 Subject: [PATCH 3/4] PHP 5.3 tests failings due to [ ] array declaration --- .../CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPolygonTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPolygonTest.php b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPolygonTest.php index dc698678..37a1d3fa 100644 --- a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPolygonTest.php +++ b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPolygonTest.php @@ -187,7 +187,7 @@ public function testSolidMultiPolygonAddPolygon() ); - $multiPolygon = new MultiPolygon([ $polygon ]); + $multiPolygon = new MultiPolygon( array( $polygon )); $multiPolygon->addPolygon( array ( From 2542eeec28ca503d9d2aa5f5cb5ed389677f870c Mon Sep 17 00:00:00 2001 From: Samuel Denis-D'Ortun Date: Wed, 6 Apr 2016 22:10:35 -0400 Subject: [PATCH 4/4] Fix one last PHPCS issue --- .../CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPolygonTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPolygonTest.php b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPolygonTest.php index 37a1d3fa..4feb5b1f 100644 --- a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPolygonTest.php +++ b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPolygonTest.php @@ -187,7 +187,7 @@ public function testSolidMultiPolygonAddPolygon() ); - $multiPolygon = new MultiPolygon( array( $polygon )); + $multiPolygon = new MultiPolygon(array($polygon)); $multiPolygon->addPolygon( array (