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

Minor code tweaks and test cleanup #139

Merged
merged 9 commits into from
Mar 23, 2016
Merged
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
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
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
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 @@ -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
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php


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

use CrEOF\Spatial\PHP\Types\Geometry\LineString;
use CrEOF\Spatial\PHP\Types\Geometry\MultiPolygon;
use CrEOF\Spatial\PHP\Types\Geometry\Point;
use CrEOF\Spatial\PHP\Types\Geometry\Polygon;

/**
* Polygon object tests
* MultiPolygon object tests
*
* @author Derek J. Lambert <[email protected]>
* @license http://dlambert.mit-license.org MIT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use CrEOF\Spatial\PHP\Types\Geometry\LineString;
use CrEOF\Spatial\PHP\Types\Geometry\Point;
use CrEOF\Spatial\PHP\Types\Geometry\Polygon;

/**
* Polygon object tests
*
Expand Down
10 changes: 0 additions & 10 deletions tests/CrEOF/Spatial/Tests/TestInit.php

This file was deleted.

5 changes: 5 additions & 0 deletions tests/travis/composer.orm2.3.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/"
}
}
}
5 changes: 5 additions & 0 deletions tests/travis/composer.orm2.4.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/"
}
}
}
5 changes: 5 additions & 0 deletions tests/travis/composer.orm2.5.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/"
}
}
}
20 changes: 11 additions & 9 deletions tests/travis/travis.mysql.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<phpunit backupGlobals="false"
colors="true"
bootstrap="../CrEOF/Spatial/Tests/TestInit.php"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutChangesToGlobalState="true"
processUncoveredFilesFromWhitelist="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>../CrEOF/Spatial/Tests</directory>
</testsuite>
</testsuites>
Expand Down
20 changes: 11 additions & 9 deletions tests/travis/travis.pgsql.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<phpunit backupGlobals="false"
colors="true"
bootstrap="../CrEOF/Spatial/Tests/TestInit.php"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutChangesToGlobalState="true"
processUncoveredFilesFromWhitelist="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>../CrEOF/Spatial/Tests</directory>
</testsuite>
</testsuites>
Expand Down