From 71fb4fa41e93984a7cac43f05dea574502083784 Mon Sep 17 00:00:00 2001 From: Patrick Hayes Date: Sun, 8 Jan 2012 16:39:16 -0800 Subject: [PATCH] Updating tests - making it so we can turn GEOS on and off for testing purposes --- geoPHP.inc | 7 ++-- lib/geometry/Geometry.class.php | 2 +- tests/test.php | 72 +++++++++++++++++++++++++++++++-- 3 files changed, 74 insertions(+), 7 deletions(-) diff --git a/geoPHP.inc b/geoPHP.inc index 19818726..8fa74eae 100644 --- a/geoPHP.inc +++ b/geoPHP.inc @@ -83,9 +83,10 @@ class geoPHP ); } - static function geosInstalled() { - static $geos_intalled = NULL; - if ($geos_intalled !== NULL) { + static function geosInstalled($force = NULL) { + static $geos_installed = NULL; + if ($force !== NULL) $geos_installed = $force; + if ($geos_installed !== NULL) { return $geos_installed; } $geos_installed = class_exists('GEOSGeometry'); diff --git a/lib/geometry/Geometry.class.php b/lib/geometry/Geometry.class.php index a5091414..54c2ffcb 100644 --- a/lib/geometry/Geometry.class.php +++ b/lib/geometry/Geometry.class.php @@ -153,7 +153,7 @@ public function asBinary() { // --------------------------- public function geos() { // If it's already been set, just return it - if ($this->geos !== NULL) { + if ($this->geos && geoPHP::geosInstalled()) { return $this->geos; } // It hasn't been set yet, generate it diff --git a/tests/test.php b/tests/test.php index cd3983d3..ea7b3674 100644 --- a/tests/test.php +++ b/tests/test.php @@ -1,12 +1,13 @@ $method(); + + // Turn GEOS off + geoPHP::geosInstalled(FALSE); + $norm_result = $geometry->$method(); + + $geos_type = gettype($geos_result); + $norm_type = gettype($norm_result); + + if ($geos_type != $norm_type) { + print 'Type mismatch on '.$method."\n"; + var_dump($geos_type); + var_dump($norm_type); + continue; + } + + // Now check base on type + if ($geos_type == 'object') { + $geos_wkt = $geos_result->out('wkt'); + $norm_wkt = $norm_result->out('wkt'); + + // Round - we can't expect them to be identitcal + $geos_wkt = preg_replace_callback("/[-+]?[0-9]*\.?[0-9]+/", create_function('$matches','return round($matches[0]);'), $geos_wkt); + $norm_wkt = preg_replace_callback("/[-+]?[0-9]*\.?[0-9]+/", create_function('$matches','return round($matches[0]);'), $norm_wkt); + + if ($geos_wkt != $norm_wkt) { + print 'Output mismatch on '.$method.":\n"; + print 'GEOS : '.$geos_wkt."\n"; + print 'NORM : '.$norm_wkt."\n"; + continue; + } + } + + //@@TODO: Run tests for output of types boolean, arrays, and text. + } + + // Turn GEOS back on + geoPHP::geosInstalled(TRUE); +} + +print "Testing Done!"; \ No newline at end of file