From 4d60e3a0b3763f31546eff07c61921a2f6c02e75 Mon Sep 17 00:00:00 2001 From: mprins Date: Mon, 16 Jun 2014 16:32:06 +0200 Subject: [PATCH 1/7] Add a Travis-ci configuration And modify test classes so they can be tested using Travis-CI. --- .gitignore | 1 + .travis.yml | 20 ++++++++++++++++++++ composer.json | 5 ++++- tests/input/an_empty_polygon.wkt | 2 +- tests/tests/20120702Test.php | 2 -- tests/tests/adaptersTest.php | 3 +-- tests/tests/aliasesTest.php | 3 +-- tests/tests/bootstrap.php | 7 +++++++ tests/tests/geosTest.php | 3 +-- tests/tests/methodsTest.php | 3 +-- tests/tests/placeholdersTest.php | 3 +-- 11 files changed, 38 insertions(+), 14 deletions(-) create mode 100644 .gitignore create mode 100644 .travis.yml create mode 100644 tests/tests/bootstrap.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..61ead866 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/vendor diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..d6fbc18d --- /dev/null +++ b/.travis.yml @@ -0,0 +1,20 @@ +# docs available at http://docs.travis-ci.com/user/languages/php/ +# example available at https://github.com/travis-ci/travis-ci-php-example +language: php + +before_script: + - composer self-update + +install: + - composer install + # TODO optionally install geos library + # TODO optionally set up a postgis database for testing + +script: cd tests && phpunit --verbose --colors --stderr tests + +# run tests on the following versions +php: + - 5.5 + - 5.4 + - 5.3 + - hhvm \ No newline at end of file diff --git a/composer.json b/composer.json index 577acf4f..a02eba8a 100644 --- a/composer.json +++ b/composer.json @@ -11,5 +11,8 @@ { "name":"Patrick Hayes" } - ] + ], + "require-dev": { + "phpunit/phpunit": "4.1.*" + } } diff --git a/tests/input/an_empty_polygon.wkt b/tests/input/an_empty_polygon.wkt index ecaad4f7..04c7519b 100644 --- a/tests/input/an_empty_polygon.wkt +++ b/tests/input/an_empty_polygon.wkt @@ -1 +1 @@ -POLYGON EMPTY +POLYGON EMPTY \ No newline at end of file diff --git a/tests/tests/20120702Test.php b/tests/tests/20120702Test.php index da056aa7..5486e0a5 100644 --- a/tests/tests/20120702Test.php +++ b/tests/tests/20120702Test.php @@ -1,7 +1,5 @@ Date: Thu, 28 Aug 2014 14:45:06 +0200 Subject: [PATCH 2/7] add php 5.6 --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d6fbc18d..348a4681 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,8 @@ script: cd tests && phpunit --verbose --colors --stderr tests # run tests on the following versions php: + - 5.6 - 5.5 - 5.4 - 5.3 - - hhvm \ No newline at end of file + - hhvm From dd363b482172fdba201557775ff434cc496ae537 Mon Sep 17 00:00:00 2001 From: mprins Date: Fri, 29 Aug 2014 09:20:43 +0200 Subject: [PATCH 3/7] fix parsing of EMPTY wkt geometries --- lib/adapters/WKT.class.php | 62 ++++++++++++++++++++----------------- tests/input/empty_point.wkt | 1 + 2 files changed, 35 insertions(+), 28 deletions(-) create mode 100644 tests/input/empty_point.wkt diff --git a/lib/adapters/WKT.class.php b/lib/adapters/WKT.class.php index cc1b8d78..c364644e 100644 --- a/lib/adapters/WKT.class.php +++ b/lib/adapters/WKT.class.php @@ -4,7 +4,7 @@ */ class WKT extends GeoAdapter { - + /** * Read WKT string into geometry objects * @@ -14,7 +14,7 @@ class WKT extends GeoAdapter */ public function read($wkt) { $wkt = trim($wkt); - + // If it contains a ';', then it contains additional SRID data if (strpos($wkt,';')) { $parts = explode(';', $wkt); @@ -25,7 +25,7 @@ public function read($wkt) { else { $srid = NULL; } - + // If geos is installed, then we take a shortcut and let it parse the WKT if (geoPHP::geosInstalled()) { $reader = new GEOSWKTReader(); @@ -34,35 +34,39 @@ public function read($wkt) { $geom->setSRID($srid); return $geom; } - else { + else { return geoPHP::geosToGeometry($reader->read($wkt)); } } $wkt = str_replace(', ', ',', $wkt); - + // For each geometry type, check to see if we have a match at the - // beggining of the string. If we do, then parse using that type + // beginning of the string. If we do, then parse using that type foreach (geoPHP::geometryList() as $geom_type) { $wkt_geom = strtoupper($geom_type); if (strtoupper(substr($wkt, 0, strlen($wkt_geom))) == $wkt_geom) { $data_string = $this->getDataString($wkt); $method = 'parse'.$geom_type; - + if ($srid) { $geom = $this->$method($data_string); $geom->setSRID($srid); return $geom; } - else { + else { return $this->$method($data_string); } - + } } } - + private function parsePoint($data_string) { $data_string = $this->trimParens($data_string); + + // If it's marked as empty, then return an empty point + if ($data_string == 'EMPTY') return new Point(); + $parts = explode(' ',$data_string); return new Point($parts[0], $parts[1]); } @@ -72,7 +76,7 @@ private function parseLineString($data_string) { // If it's marked as empty, then return an empty line if ($data_string == 'EMPTY') return new LineString(); - + $parts = explode(',',$data_string); $points = array(); foreach ($parts as $part) { @@ -83,10 +87,10 @@ private function parseLineString($data_string) { private function parsePolygon($data_string) { $data_string = $this->trimParens($data_string); - + // If it's marked as empty, then return an empty polygon if ($data_string == 'EMPTY') return new Polygon(); - + $parts = explode('),(',$data_string); $lines = array(); foreach ($parts as $part) { @@ -99,10 +103,10 @@ private function parsePolygon($data_string) { private function parseMultiPoint($data_string) { $data_string = $this->trimParens($data_string); - + // If it's marked as empty, then return an empty MutiPoint if ($data_string == 'EMPTY') return new MultiPoint(); - + $parts = explode(',',$data_string); $points = array(); foreach ($parts as $part) { @@ -110,13 +114,13 @@ private function parseMultiPoint($data_string) { } return new MultiPoint($points); } - + private function parseMultiLineString($data_string) { $data_string = $this->trimParens($data_string); // If it's marked as empty, then return an empty multi-linestring if ($data_string == 'EMPTY') return new MultiLineString(); - + $parts = explode('),(',$data_string); $lines = array(); foreach ($parts as $part) { @@ -133,7 +137,7 @@ private function parseMultiPolygon($data_string) { // If it's marked as empty, then return an empty multi-polygon if ($data_string == 'EMPTY') return new MultiPolygon(); - + $parts = explode(')),((',$data_string); $polys = array(); foreach ($parts as $part) { @@ -150,12 +154,12 @@ private function parseGeometryCollection($data_string) { // If it's marked as empty, then return an empty geom-collection if ($data_string == 'EMPTY') return new GeometryCollection(); - + $geometries = array(); $matches = array(); $str = preg_replace('/,\s*([A-Za-z])/', '|$1', $data_string); $components = explode('|', trim($str)); - + foreach ($components as $component) { $geometries[] = $this->read($component); } @@ -167,23 +171,25 @@ protected function getDataString($wkt) { if ($first_paren !== FALSE) { return substr($wkt, $first_paren); - } - return FALSE; + } elseif (strstr($wkt,'EMPTY')) { + return 'EMPTY'; + } else + return FALSE; } - + /** * Trim the parenthesis and spaces */ protected function trimParens($str) { $str = trim($str); - + // We want to only strip off one set of parenthesis if ($this->beginsWith($str, '(')) { return substr($str,1,-1); } else return $str; } - + protected function beginsWith($str, $char) { if (substr($str,0,strlen($char)) == $char) return TRUE; else return FALSE; @@ -193,7 +199,7 @@ protected function endsWith($str, $char) { if (substr($str,(0 - strlen($char))) == $char) return TRUE; else return FALSE; } - + /** * Serialize geometries into a WKT string. * @@ -208,7 +214,7 @@ public function write(Geometry $geometry) { $writer->setTrim(TRUE); return $writer->write($geometry->geos()); } - + if ($geometry->isEmpty()) { return strtoupper($geometry->geometryType()).' EMPTY'; } @@ -216,7 +222,7 @@ public function write(Geometry $geometry) { return strtoupper($geometry->geometryType()).' ('.$data.')'; } } - + /** * Extract geometry to a WKT string * diff --git a/tests/input/empty_point.wkt b/tests/input/empty_point.wkt new file mode 100644 index 00000000..41dec0b7 --- /dev/null +++ b/tests/input/empty_point.wkt @@ -0,0 +1 @@ +POINT EMPTY \ No newline at end of file From fe93d105887228d2d96eee9ce1d6d41a5169ae33 Mon Sep 17 00:00:00 2001 From: mprins Date: Fri, 29 Aug 2014 11:18:25 +0200 Subject: [PATCH 4/7] make failures output some useful information --- tests/tests/adaptersTest.php | 4 +- tests/tests/aliasesTest.php | 34 ++++----- tests/tests/geosTest.php | 12 ++-- tests/tests/methodsTest.php | 116 +++++++++++++++---------------- tests/tests/placeholdersTest.php | 14 ++-- 5 files changed, 90 insertions(+), 90 deletions(-) diff --git a/tests/tests/adaptersTest.php b/tests/tests/adaptersTest.php index 109fe5f0..69d0a603 100644 --- a/tests/tests/adaptersTest.php +++ b/tests/tests/adaptersTest.php @@ -24,7 +24,7 @@ function testAdapters() { $adapter_loader = new $adapter_class(); $test_geom_1 = $adapter_loader->read($output); $test_geom_2 = $adapter_loader->read($test_geom_1->out($adapter_key)); - $this->assertEquals($test_geom_1->out('wkt'), $test_geom_2->out('wkt'), "Mismatched adapter output in ".$adapter_class); + $this->assertEquals($test_geom_1->out('wkt'), $test_geom_2->out('wkt'), "Mismatched adapter output in ".$adapter_class .' (test file: ' . $file . ')'); } } } @@ -53,7 +53,7 @@ function testAdapters() { geoPHP::geosInstalled(TRUE); // Check to make sure a both are the same with geos and without - $this->assertEquals($test_geom_1->out('wkt'), $test_geom_2->out('wkt'), "Mismatched adapter output between GEOS and NORM in ".$adapter_class); + $this->assertEquals($test_geom_1->out('wkt'), $test_geom_2->out('wkt'), "Mismatched adapter output between GEOS and NORM in ".$adapter_class .' (test file: ' . $file . ')'); } } } diff --git a/tests/tests/aliasesTest.php b/tests/tests/aliasesTest.php index dd3a4a8d..6e23644a 100644 --- a/tests/tests/aliasesTest.php +++ b/tests/tests/aliasesTest.php @@ -37,67 +37,67 @@ function testAliases() { switch ($alias_name) { case 'getSRID': if ($geometry->geometryType() == 'Point') { - $this->assertNotNull($geometry->$alias_name($argument), 'Failed on ' . $alias_name); + $this->assertNotNull($geometry->$alias_name($argument), 'Failed on ' . $alias_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'LineString') { - $this->assertNotNull($geometry->$alias_name($argument), 'Failed on ' . $alias_name); + $this->assertNotNull($geometry->$alias_name($argument), 'Failed on ' . $alias_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'MultiLineString') { - $this->assertNull($geometry->$alias_name($argument), 'Failed on ' . $alias_name); + $this->assertNull($geometry->$alias_name($argument), 'Failed on ' . $alias_name .' (test file: ' . $file . ')'); } break; case 'getGeos': if ($geometry->geometryType() == 'Point') { - $this->assertNotNull($geometry->$alias_name($argument), 'Failed on ' . $alias_name); + $this->assertNotNull($geometry->$alias_name($argument), 'Failed on ' . $alias_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'LineString') { - $this->assertNotNull($geometry->$alias_name($argument), 'Failed on ' . $alias_name); + $this->assertNotNull($geometry->$alias_name($argument), 'Failed on ' . $alias_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'MultiLineString') { - $this->assertNotNull($geometry->$alias_name($argument), 'Failed on ' . $alias_name); + $this->assertNotNull($geometry->$alias_name($argument), 'Failed on ' . $alias_name .' (test file: ' . $file . ')'); } break; case 'getX': case 'getY': if ($geometry->geometryType() == 'Point') { - $this->assertNotNull($geometry->$alias_name($argument), 'Failed on ' . $alias_name); + $this->assertNotNull($geometry->$alias_name($argument), 'Failed on ' . $alias_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'LineString') { - $this->assertNull($geometry->$alias_name($argument), 'Failed on ' . $alias_name); + $this->assertNull($geometry->$alias_name($argument), 'Failed on ' . $alias_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'MultiLineString') { - $this->assertNull($geometry->$alias_name($argument), 'Failed on ' . $alias_name); + $this->assertNull($geometry->$alias_name($argument), 'Failed on ' . $alias_name .' (test file: ' . $file . ')'); } break; case 'getArea': if ($geometry->geometryType() == 'Point') { - $this->assertNull($geometry->$alias_name($argument), 'Failed on ' . $alias_name); + $this->assertNull($geometry->$alias_name($argument), 'Failed on ' . $alias_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'LineString') { - $this->assertNull($geometry->$alias_name($argument), 'Failed on ' . $alias_name); + $this->assertNull($geometry->$alias_name($argument), 'Failed on ' . $alias_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'MultiLineString') { - $this->assertNotNull($geometry->$alias_name($argument), 'Failed on ' . $alias_name); + $this->assertNotNull($geometry->$alias_name($argument), 'Failed on ' . $alias_name .' (test file: ' . $file . ')'); } break; case 'getCentroid': if ($geometry->geometryType() == 'Point') { - $this->assertNotNull($geometry->$alias_name($argument), 'Failed on ' . $alias_name); + $this->assertNotNull($geometry->$alias_name($argument), 'Failed on ' . $alias_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'LineString') { - $this->assertNotNull($geometry->$alias_name($argument), 'Failed on ' . $alias_name); + $this->assertNotNull($geometry->$alias_name($argument), 'Failed on ' . $alias_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'MultiLineString') { - $this->assertNotNull($geometry->$alias_name($argument), 'Failed on ' . $alias_name); + $this->assertNotNull($geometry->$alias_name($argument), 'Failed on ' . $alias_name .' (test file: ' . $file . ')'); } break; case 'asText': case 'asBinary': case 'getGeomType': - $this->assertNotNull($geometry->$alias_name($argument), 'Failed on ' . $alias_name); + $this->assertNotNull($geometry->$alias_name($argument), 'Failed on ' . $alias_name .' (test file: ' . $file . ')'); break; default: - $this->assertTrue($geometry->$alias_name($argument), 'Failed on ' . $alias_name); + $this->assertTrue($geometry->$alias_name($argument), 'Failed on ' . $alias_name .' (test file: ' . $file . ')'); } } diff --git a/tests/tests/geosTest.php b/tests/tests/geosTest.php index 0624897f..371ff84d 100644 --- a/tests/tests/geosTest.php +++ b/tests/tests/geosTest.php @@ -56,24 +56,24 @@ function testGeos() { case 'equals': case 'geos': if ($geometry->geometryType() == 'Point') { - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'LineString') { - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'MultiLineString') { - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } break; default: if ($geometry->geometryType() == 'Point') { - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'LineString') { - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'MultiLineString') { - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } } } diff --git a/tests/tests/methodsTest.php b/tests/tests/methodsTest.php index 9f3715be..5d85ffeb 100644 --- a/tests/tests/methodsTest.php +++ b/tests/tests/methodsTest.php @@ -49,7 +49,7 @@ function testMethods() { $argument = $method['argument']; } - $this->_methods_tester($geometry, $method_name, $argument); + $this->_methods_tester($geometry, $method_name, $argument, $file); } $this->_methods_tester_with_geos($geometry); @@ -57,7 +57,7 @@ function testMethods() { } } - function _methods_tester($geometry, $method_name, $argument) { + function _methods_tester($geometry, $method_name, $argument, $file) { if (!method_exists($geometry, $method_name)) { $this->fail("Method ".$method_name.'() doesn\'t exists.'); @@ -68,44 +68,44 @@ function _methods_tester($geometry, $method_name, $argument) { case 'y': case 'x': if ($geometry->geometryType() == 'Point') { - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'LineString') { - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'MultiLineString') { - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } break; case 'geometryN': if ($geometry->geometryType() == 'Point') { - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'LineString') { - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'MultiLineString') { - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } break; case 'startPoint': if ($geometry->geometryType() == 'Point') { - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'LineString') { - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'MultiLineString') { //TODO: Add a method startPoint() to MultiLineString. - //$this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + //$this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } break; case 'endPoint': if ($geometry->geometryType() == 'Point') { - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'LineString') { - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'MultiLineString') { //TODO: Add a method endPoint() to MultiLineString. @@ -114,157 +114,157 @@ function _methods_tester($geometry, $method_name, $argument) { break; case 'isRing': if ($geometry->geometryType() == 'Point') { - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'LineString') { - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'MultiLineString') { - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } break; case 'isClosed': if ($geometry->geometryType() == 'Point') { - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'LineString') { - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'MultiLineString') { - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } break; case 'pointN': if ($geometry->geometryType() == 'Point') { - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'LineString') { - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'MultiLineString') { //TODO: Add a method pointN() to MultiLineString. - //$this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + //$this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } break; case 'exteriorRing': if ($geometry->geometryType() == 'Point') { - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'LineString') { - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'MultiLineString') { - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } break; case 'numInteriorRings': if ($geometry->geometryType() == 'Point') { - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'LineString') { - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'MultiLineString') { - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } break; case 'interiorRingN': if ($geometry->geometryType() == 'Point') { - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'LineString') { - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'MultiLineString') { - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } break; case 'SRID': if ($geometry->geometryType() == 'Point') { - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'LineString') { - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'MultiLineString') { - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } break; case 'getBBox': if ($geometry->geometryType() == 'Point') { - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'LineString') { - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'MultiLineString') { - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } break; case 'centroid': if ($geometry->geometryType() == 'Point') { - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'LineString') { - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'MultiLineString') { - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } break; case 'length': if ($geometry->geometryType() == 'Point') { - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'LineString') { - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'MultiLineString') { - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } break; case 'numGeometries': if ($geometry->geometryType() == 'Point') { - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'LineString') { - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'MultiLineString') { - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } break; case 'numPoints': if ($geometry->geometryType() == 'Point') { - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'LineString') { - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'MultiLineString') { - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } break; case 'dimension': if ($geometry->geometryType() == 'Point') { - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'LineString') { - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'MultiLineString') { - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } break; case 'boundary': if ($geometry->geometryType() == 'Point') { - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'LineString') { - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'MultiLineString') { - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } break; case 'haversineLength': @@ -273,16 +273,16 @@ function _methods_tester($geometry, $method_name, $argument) { break; case 'greatCircleLength': case 'area': - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); break; case 'geometryType': - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); break; case 'setSRID': //TODO: The method setSRID() should return TRUE. break; default: - $this->assertTrue($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertTrue($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } } diff --git a/tests/tests/placeholdersTest.php b/tests/tests/placeholdersTest.php index e6a0f4c5..0af3192e 100644 --- a/tests/tests/placeholdersTest.php +++ b/tests/tests/placeholdersTest.php @@ -36,13 +36,13 @@ function testPlaceholders() { case 'm': case 'z': if ($geometry->geometryType() == 'Point') { - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'LineString') { - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'MultiLineString') { - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } break; case 'coordinateDimension': @@ -51,17 +51,17 @@ function testPlaceholders() { case 'is3D': case 'hasZ': if ($geometry->geometryType() == 'Point') { - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'LineString') { - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'MultiLineString') { - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } break; default: - $this->assertTrue($geometry->$method_name($argument), 'Failed on ' . $method_name); + $this->assertTrue($geometry->$method_name($argument), 'Failed on ' . $method_name .' (test file: ' . $file . ')'); } } From 73a69fb3ec49c11fae70167e9aae26fd536efbe9 Mon Sep 17 00:00:00 2001 From: mprins Date: Fri, 29 Aug 2014 13:51:05 +0200 Subject: [PATCH 5/7] fix typo --- lib/adapters/KML.class.php | 3 +-- lib/geometry/Geometry.class.php | 6 +++--- lib/geometry/Point.class.php | 10 +++++----- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/adapters/KML.class.php b/lib/adapters/KML.class.php index b576e288..7bd24d2c 100644 --- a/lib/adapters/KML.class.php +++ b/lib/adapters/KML.class.php @@ -50,12 +50,11 @@ public function write(Geometry $geometry, $namespace = FALSE) { } public function geomFromText($text) { - // Change to lower-case and strip all CDATA $text = mb_strtolower($text, mb_detect_encoding($text)); $text = preg_replace('//s','',$text); - // Load into DOMDOcument + // Load into DOMDocument $xmlobj = new DOMDocument(); @$xmlobj->loadXML($text); if ($xmlobj === false) { diff --git a/lib/geometry/Geometry.class.php b/lib/geometry/Geometry.class.php index db38db63..2da2cd79 100644 --- a/lib/geometry/Geometry.class.php +++ b/lib/geometry/Geometry.class.php @@ -330,17 +330,17 @@ public function isMeasured() { } public function coordinateDimension() { - // geoPHP only supports 2-dimentional space + // geoPHP only supports 2-dimensional space return 2; } public function z() { - // geoPHP only supports 2-dimentional space + // geoPHP only supports 2-dimensional space return NULL; } public function m() { - // geoPHP only supports 2-dimentional space + // geoPHP only supports 2-dimensional space return NULL; } diff --git a/lib/geometry/Point.class.php b/lib/geometry/Point.class.php index f49771e7..420b3e38 100644 --- a/lib/geometry/Point.class.php +++ b/lib/geometry/Point.class.php @@ -8,7 +8,7 @@ class Point extends Geometry { public $coords = array(2); protected $geom_type = 'Point'; - protected $dimention = 2; + protected $dimension = 2; /** * Constructor @@ -28,7 +28,7 @@ public function __construct($x, $y, $z = NULL) { if (!is_numeric($z)) { throw new Exception("Cannot construct Point. z should be numeric"); } - $this->dimention = 3; + $this->dimension = 3; } // Convert to floatval in case they are passed in as a string or integer etc. @@ -37,10 +37,10 @@ public function __construct($x, $y, $z = NULL) { $z = floatval($z); // Add poitional elements - if ($this->dimention == 2) { + if ($this->dimension == 2) { $this->coords = array($x, $y); } - if ($this->dimention == 3) { + if ($this->dimension == 3) { $this->coords = array($x, $y, $z); } } @@ -69,7 +69,7 @@ public function y() { * @return float The Z coordinate or NULL is not a 3D point */ public function z() { - if ($this->dimention == 3) { + if ($this->dimension == 3) { return $this->coords[2]; } else return NULL; From 55d9d5ce599d731948043097d2c1c760dacc8be0 Mon Sep 17 00:00:00 2001 From: mprins Date: Fri, 29 Aug 2014 15:50:39 +0200 Subject: [PATCH 6/7] randomize testinput and fix some area tests --- .travis.yml | 6 ++++++ tests/postgis.php | 2 +- tests/test.php | 2 +- tests/tests/adaptersTest.php | 2 +- tests/tests/aliasesTest.php | 6 +++--- tests/tests/geosTest.php | 2 +- tests/tests/methodsTest.php | 2 +- tests/tests/placeholdersTest.php | 2 +- 8 files changed, 15 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 348a4681..0f117353 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,3 +19,9 @@ php: - 5.4 - 5.3 - hhvm + +matrix: + fast_finish: false + allow_failures: + # php 5.3 does not support random file list as an argument to scandir + - php: 5.3 diff --git a/tests/postgis.php b/tests/postgis.php index c2318588..1804da24 100644 --- a/tests/postgis.php +++ b/tests/postgis.php @@ -24,7 +24,7 @@ function run_test() { // Working with PostGIS and EWKB // ---------------------------- - foreach (scandir('./input') as $file) { + foreach (scandir('./input', SCANDIR_SORT_NONE) as $file) { $parts = explode('.',$file); if ($parts[0]) { $name = $parts[0]; diff --git a/tests/test.php b/tests/test.php index d2259a0e..09670560 100644 --- a/tests/test.php +++ b/tests/test.php @@ -17,7 +17,7 @@ function run_test() { print "GEOS is not installed.\n"; } - foreach (scandir('./input') as $file) { + foreach (scandir('./input', SCANDIR_SORT_NONE) as $file) { $parts = explode('.',$file); if ($parts[0]) { $format = $parts[1]; diff --git a/tests/tests/adaptersTest.php b/tests/tests/adaptersTest.php index 69d0a603..5952e10f 100644 --- a/tests/tests/adaptersTest.php +++ b/tests/tests/adaptersTest.php @@ -7,7 +7,7 @@ function setUp() { } function testAdapters() { - foreach (scandir('./input') as $file) { + foreach (scandir('./input', SCANDIR_SORT_NONE) as $file) { $parts = explode('.',$file); if ($parts[0]) { $format = $parts[1]; diff --git a/tests/tests/aliasesTest.php b/tests/tests/aliasesTest.php index 6e23644a..dd45c895 100644 --- a/tests/tests/aliasesTest.php +++ b/tests/tests/aliasesTest.php @@ -7,7 +7,7 @@ function setUp() { } function testAliases() { - foreach (scandir('./input') as $file) { + foreach (scandir('./input', SCANDIR_SORT_NONE) as $file) { $parts = explode('.',$file); if ($parts[0]) { $format = $parts[1]; @@ -71,10 +71,10 @@ function testAliases() { break; case 'getArea': if ($geometry->geometryType() == 'Point') { - $this->assertNull($geometry->$alias_name($argument), 'Failed on ' . $alias_name .' (test file: ' . $file . ')'); + $this->assertEquals(0, $geometry->$alias_name($argument), 'Failed on ' . $alias_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'LineString') { - $this->assertNull($geometry->$alias_name($argument), 'Failed on ' . $alias_name .' (test file: ' . $file . ')'); + $this->assertEquals(0, $geometry->$alias_name($argument), 'Failed on ' . $alias_name .' (test file: ' . $file . ')'); } if ($geometry->geometryType() == 'MultiLineString') { $this->assertNotNull($geometry->$alias_name($argument), 'Failed on ' . $alias_name .' (test file: ' . $file . ')'); diff --git a/tests/tests/geosTest.php b/tests/tests/geosTest.php index 371ff84d..80b7f7f6 100644 --- a/tests/tests/geosTest.php +++ b/tests/tests/geosTest.php @@ -7,7 +7,7 @@ function setUp() { } function testGeos() { - foreach (scandir('./input') as $file) { + foreach (scandir('./input', SCANDIR_SORT_NONE) as $file) { $parts = explode('.',$file); if ($parts[0]) { $format = $parts[1]; diff --git a/tests/tests/methodsTest.php b/tests/tests/methodsTest.php index 5d85ffeb..097a9378 100644 --- a/tests/tests/methodsTest.php +++ b/tests/tests/methodsTest.php @@ -7,7 +7,7 @@ function setUp() { } function testMethods() { - foreach (scandir('./input') as $file) { + foreach (scandir('./input', SCANDIR_SORT_NONE) as $file) { $parts = explode('.',$file); if ($parts[0]) { $format = $parts[1]; diff --git a/tests/tests/placeholdersTest.php b/tests/tests/placeholdersTest.php index 0af3192e..42e6c5e9 100644 --- a/tests/tests/placeholdersTest.php +++ b/tests/tests/placeholdersTest.php @@ -7,7 +7,7 @@ function setUp() { } function testPlaceholders() { - foreach (scandir('./input') as $file) { + foreach (scandir('./input', SCANDIR_SORT_NONE) as $file) { $parts = explode('.',$file); if ($parts[0]) { $format = $parts[1]; From d90eff9e36018928f90687a022cb7188a2d70ef1 Mon Sep 17 00:00:00 2001 From: mprins Date: Fri, 29 Aug 2014 16:14:26 +0200 Subject: [PATCH 7/7] initialize variable str --- lib/adapters/KML.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/adapters/KML.class.php b/lib/adapters/KML.class.php index 7bd24d2c..346ffbff 100644 --- a/lib/adapters/KML.class.php +++ b/lib/adapters/KML.class.php @@ -234,6 +234,7 @@ private function linestringToKML($geom, $type = FALSE) { public function polygonToKML($geom) { $components = $geom->getComponents(); + $str = ''; if (!empty($components)) { $str = '<'.$this->nss.'outerBoundaryIs>' . $this->linestringToKML($components[0], 'LinearRing') . 'nss.'outerBoundaryIs>'; foreach (array_slice($components, 1) as $comp) {