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

Develop #219

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,10 @@
"psr-0": {
"CrEOF\\Spatial": "lib/"
}
},
"autoload-dev": {
"psr-0": {
"CrEOF\\Spatial\\Tests": "tests/"
}
}
}
13 changes: 4 additions & 9 deletions lib/CrEOF/Spatial/PHP/Types/AbstractGeometry.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ protected function validatePointValue($point)
case ($point instanceof AbstractPoint):
return $point->toArray();
break;
case (is_array($point) && count($point) == 2 && is_numeric($point[0]) && is_numeric($point[1])):
case (is_array($point) && count($point) === 2 && is_numeric($point[0]) && is_numeric($point[1])):
return array_values($point);
break;
default:
Expand All @@ -115,14 +115,8 @@ protected function validatePointValue($point)
*/
protected function validateRingValue($ring)
{
switch (true) {
case ($ring instanceof AbstractLineString):
$ring = $ring->toArray();
break;
case (is_array($ring)):
break;
default:
throw new InvalidValueException(sprintf('Invalid %s LineString value of type "%s"', $this->getType(), (is_object($ring) ? get_class($ring) : gettype($ring))));
if (! (is_array($ring) || $ring instanceof AbstractLineString)) {
throw new InvalidValueException(sprintf('Invalid %s LineString value of type "%s"', $this->getType(), (is_object($ring) ? get_class($ring) : gettype($ring))));
}

$ring = $this->validateLineStringValue($ring);
Expand Down Expand Up @@ -187,6 +181,7 @@ protected function validateMultiPolygonValue(array $polygons)
if ($polygon instanceof GeometryInterface) {
$polygon = $polygon->toArray();
}

$polygon = $this->validatePolygonValue($polygon);
}

Expand Down
52 changes: 29 additions & 23 deletions lib/CrEOF/Spatial/PHP/Types/AbstractPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,20 @@ public function __construct()
*/
public function setX($x)
{
$parser = new Parser($x);

try {
$this->x = (float) $parser->parse();
} catch (RangeException $e) {
throw new InvalidValueException($e->getMessage(), $e->getCode(), $e->getPrevious());
} catch (UnexpectedValueException $e) {
throw new InvalidValueException($e->getMessage(), $e->getCode(), $e->getPrevious());
if (! is_numeric($x)) {
$parser = new Parser($x);

try {
$x = $parser->parse();
} catch (RangeException $e) {
throw new InvalidValueException($e->getMessage(), $e->getCode(), $e->getPrevious());
} catch (UnexpectedValueException $e) {
throw new InvalidValueException($e->getMessage(), $e->getCode(), $e->getPrevious());
}
}

$this->x = (float) $x;

return $this;
}

Expand All @@ -93,16 +97,20 @@ public function getX()
*/
public function setY($y)
{
$parser = new Parser($y);

try {
$this->y = (float) $parser->parse();
} catch (RangeException $e) {
throw new InvalidValueException($e->getMessage(), $e->getCode(), $e->getPrevious());
} catch (UnexpectedValueException $e) {
throw new InvalidValueException($e->getMessage(), $e->getCode(), $e->getPrevious());
if (! is_numeric($y)) {
$parser = new Parser($y);

try {
$y = $parser->parse();
} catch (RangeException $e) {
throw new InvalidValueException($e->getMessage(), $e->getCode(), $e->getPrevious());
} catch (UnexpectedValueException $e) {
throw new InvalidValueException($e->getMessage(), $e->getCode(), $e->getPrevious());
}
}

$this->y = (float) $y;

return $this;
}

Expand Down Expand Up @@ -177,12 +185,12 @@ protected function validateArguments(array $argv = null)
{
$argc = count($argv);

if (1 == $argc && is_array($argv[0])) {
if (1 === $argc && is_array($argv[0])) {
return $argv[0];
}

if (2 == $argc) {
if (is_array($argv[0]) && (is_numeric($argv[1]) || is_null($argv[1]) || is_string($argv[1]))) {
if (2 === $argc) {
if (is_array($argv[0]) && (is_numeric($argv[1]) || null === $argv[1] || is_string($argv[1]))) {
$argv[0][] = $argv[1];

return $argv[0];
Expand All @@ -193,10 +201,8 @@ protected function validateArguments(array $argv = null)
}
}

if (3 == $argc) {
if ((is_numeric($argv[0]) || is_string($argv[0])) && (is_numeric($argv[1]) || is_string($argv[1])) && (is_numeric($argv[2]) || is_null($argv[2]) || is_string($argv[2]))) {
return $argv;
}
if (3 === $argc && ((is_numeric($argv[0]) || is_string($argv[0])) && (is_numeric($argv[1]) || is_string($argv[1])) && (is_numeric($argv[2]) || null === $argv[2] || is_string($argv[2])))) {
return $argv;
}

array_walk($argv, function (&$value) {
Expand Down
2 changes: 1 addition & 1 deletion lib/CrEOF/Spatial/PHP/Types/AbstractPolygon.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function getRings()
*/
public function getRing($index)
{
if (-1 == $index) {
if (-1 === $index) {
$index = count($this->rings) - 1;
}

Expand Down
34 changes: 20 additions & 14 deletions lib/CrEOF/Spatial/PHP/Types/Geography/Point.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,19 @@ class Point extends AbstractPoint implements GeographyInterface
*/
public function setX($x)
{
$parser = new Parser($x);
if (!is_numeric($x)) {
$parser = new Parser($x);

try {
$x = (float) $parser->parse();
} catch (RangeException $e) {
throw new InvalidValueException($e->getMessage(), $e->getCode(), $e->getPrevious());
} catch (UnexpectedValueException $e) {
throw new InvalidValueException($e->getMessage(), $e->getCode(), $e->getPrevious());
try {
$x = $parser->parse();
} catch (RangeException $e) {
throw new InvalidValueException($e->getMessage(), $e->getCode(), $e->getPrevious());
} catch (UnexpectedValueException $e) {
throw new InvalidValueException($e->getMessage(), $e->getCode(), $e->getPrevious());
}
}

$x = (float) $x;
if ($x < -180 || $x > 180) {
throw new InvalidValueException(sprintf('Invalid longitude value "%s", must be in range -180 to 180.', $x));
}
Expand All @@ -72,16 +75,19 @@ public function setX($x)
*/
public function setY($y)
{
$parser = new Parser($y);
if (!is_numeric($y)) {
$parser = new Parser($y);

try {
$y = (float) $parser->parse();
} catch (RangeException $e) {
throw new InvalidValueException($e->getMessage(), $e->getCode(), $e->getPrevious());
} catch (UnexpectedValueException $e) {
throw new InvalidValueException($e->getMessage(), $e->getCode(), $e->getPrevious());
try {
$y = $parser->parse();
} catch (RangeException $e) {
throw new InvalidValueException($e->getMessage(), $e->getCode(), $e->getPrevious());
} catch (UnexpectedValueException $e) {
throw new InvalidValueException($e->getMessage(), $e->getCode(), $e->getPrevious());
}
}

$y = (float) $y;
if ($y < -90 || $y > 90) {
throw new InvalidValueException(sprintf('Invalid latitude value "%s", must be in range -90 to 90.', $y));
}
Expand Down
19 changes: 11 additions & 8 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<phpunit backupGlobals="false"
colors="true"
bootstrap="./tests/CrEOF/Spatial/Tests/TestInit.php"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutChangesToGlobalState="true"
>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.2/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="./vendor/autoload.php"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutChangesToGlobalState="true"
>

<testsuites>
<testsuite>
<testsuite name="Tests">
<directory>./tests/CrEOF/Spatial/Tests</directory>
</testsuite>
</testsuites>
Expand Down
2 changes: 1 addition & 1 deletion tests/CrEOF/Spatial/Tests/DBAL/Types/SchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function testDoctrineTypeMapping()
$databaseTypes = $type->getMappedDatabaseTypes($platform);

foreach ($databaseTypes as $databaseType) {
$typeMapping = $this->getPlatform()->getDoctrineTypeMapping($databaseType);
$typeMapping = $platform->getDoctrineTypeMapping($databaseType);

$this->assertEquals($doctrineType, $typeMapping);
}
Expand Down
5 changes: 3 additions & 2 deletions tests/CrEOF/Spatial/Tests/OrmTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ protected function setUp()
*/
protected function getEntityManager()
{
if (isset($this->entityManager)) {
if (null !== $this->entityManager) {
return $this->entityManager;
}

Expand All @@ -209,7 +209,8 @@ protected function getEntityManager()

$config = new Configuration();

$config->setMetadataCacheImpl(new ArrayCache);
$config->setMetadataCacheImpl(new ArrayCache());
$config->setResultCacheImpl(new ArrayCache());
$config->setProxyDir(__DIR__ . '/Proxies');
$config->setProxyNamespace('CrEOF\Spatial\Tests\Proxies');
$config->setMetadataDriverImpl($config->newDefaultAnnotationDriver(array(realpath(__DIR__ . '/Fixtures')), true));
Expand Down
89 changes: 89 additions & 0 deletions tests/CrEOF/Spatial/Tests/PHP/Types/Geography/LineStringTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
/**
* Copyright (C) 2015 Derek J. Lambert
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

namespace CrEOF\Spatial\Tests\PHP\Types\Geography;

use CrEOF\Spatial\Exception\InvalidValueException;
use CrEOF\Spatial\PHP\Types\Geography\LineString;
use CrEOF\Spatial\PHP\Types\Geography\Point;

/**
* LineString object tests
*
* @author Derek J. Lambert <[email protected]>
* @license http://dlambert.mit-license.org MIT
*
* @group php
*/
class LineStringTest extends \PHPUnit_Framework_TestCase
{

/**
* @expectedException \CrEOF\Spatial\Exception\InvalidValueException
* @expectedExceptionMessage Invalid longitude value "550", must be in range -180 to 180.
*/
public function testLineStringFromObjectsToArray()
{
$expected = array(
array(550, 550),
array(551, 551),
array(552, 552),
array(553, 553)
);
$lineString = new LineString(array(
new Point(550, 550),
new Point(551, 551),
new Point(552, 552),
new Point(553, 553)
));

$this->assertCount(4, $lineString->getPoints());
$this->assertEquals($expected, $lineString->toArray());
}

/**
* @expectedException \CrEOF\Spatial\Exception\InvalidValueException
* @expectedExceptionMessage Invalid longitude value "550", must be in range -180 to 180.
*/
public function testLineStringFromArraysGetPoints()
{
$expected = array(
array(550, 550),
array(551, 551),
array(552, 552),
array(553, 553)
);
$lineString = new LineString(
array(
array(550, 550),
array(551, 551),
array(552, 552),
array(553, 553)
)
);
$actual = $lineString->getPoints();

$this->assertCount(4, $actual);
$this->assertEquals($expected, $actual);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* SOFTWARE.
*/

namespace CrEOF\Spatial\Tests\PHP\Types\Spatial\Geometry;
namespace CrEOF\Spatial\Tests\PHP\Types\Geometry;

use CrEOF\Spatial\PHP\Types\Geometry\LineString;
use CrEOF\Spatial\PHP\Types\Geometry\Point;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ public function testSolidMultiLineStringFromArraysGetRings()
$this->assertEquals($expected, $multiLineString->getLineStrings());
}



public function testSolidMultiLineStringAddRings()
{
$expected = array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* SOFTWARE.
*/

namespace CrEOF\Spatial\Tests\PHP\Types\Spatial\Geometry;
namespace CrEOF\Spatial\Tests\PHP\Types\Geometry;

use CrEOF\Spatial\PHP\Types\Geometry\MultiPoint;
use CrEOF\Spatial\PHP\Types\Geometry\Point;
Expand Down Expand Up @@ -84,8 +84,6 @@ public function testMultiPointFromArraysGetPoints()
$this->assertEquals($expected, $actual);
}



public function testMultiPointAddPoints()
{
$expected = array(
Expand Down
Loading