Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge changes from master #153

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/CrEOF/Spatial/DBAL/Platform/AbstractPlatform.php
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
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
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
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
45 changes: 41 additions & 4 deletions tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/PointTest.php
Expand Up @@ -35,19 +35,22 @@
*/
class PointTest extends \PHPUnit_Framework_TestCase
{
public function testGoodNumericPoints()
public function testGoodNumericPoint()
{
$point1 = new Point(-73.7562317, 42.6525793);

$this->assertEquals(42.6525793, $point1->getLatitude());
$this->assertEquals(-73.7562317, $point1->getLongitude());

$point2 = new Point(0.00001, 0.00003);
$point1
->setLatitude(40.446111111111)
->setLongitude(-79.948611111111);

$this->assertEquals(0.00003, $point2->getLatitude());
$this->assertEquals(0.00001, $point2->getLongitude());
$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 @@ -225,6 +228,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
Expand Up @@ -100,6 +100,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