Skip to content

Commit

Permalink
Merge pull request #151 from sadortun/master
Browse files Browse the repository at this point in the history
Add test cases to improve coverage
  • Loading branch information
djlambert committed Apr 7, 2016
2 parents a455416 + 2542eee commit 9fe9658
Show file tree
Hide file tree
Showing 6 changed files with 238 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/CrEOF/Spatial/DBAL/Platform/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
28 changes: 28 additions & 0 deletions tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
67 changes: 67 additions & 0 deletions tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPolygonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(array($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(
Expand Down
43 changes: 43 additions & 0 deletions tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/PointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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]}';
Expand Down
49 changes: 49 additions & 0 deletions tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/PolygonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 9fe9658

Please sign in to comment.