function MethodsTests::_methods_tester in geoPHP 7
Same name and namespace in other branches
- 8 geoPHP/tests/tests/methodsTest.php \MethodsTests::_methods_tester()
1 call to MethodsTests::_methods_tester()
- MethodsTests::testMethods in geoPHP/
tests/ tests/ methodsTest.php
File
- geoPHP/
tests/ tests/ methodsTest.php, line 60
Class
Code
function _methods_tester($geometry, $method_name, $argument, $file) {
if (!method_exists($geometry, $method_name)) {
$this
->fail("Method " . $method_name . '() doesn\'t exists.');
return;
}
switch ($method_name) {
case 'y':
case 'x':
if (!$geometry
->isEmpty()) {
if ($geometry
->geometryType() == 'Point') {
$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 . ' (test file: ' . $file . ')');
}
if ($geometry
->geometryType() == 'MultiLineString') {
$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 . ' (test file: ' . $file . ')');
}
if ($geometry
->geometryType() == 'LineString') {
$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 . ' (test file: ' . $file . ')');
}
break;
case 'startPoint':
if ($geometry
->geometryType() == 'Point') {
$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 . ' (test file: ' . $file . ')');
}
if ($geometry
->geometryType() == 'MultiLineString') {
//TODO: Add a method startPoint() to MultiLineString.
//$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 . ' (test file: ' . $file . ')');
}
if ($geometry
->geometryType() == 'LineString') {
$this
->assertNotNull($geometry
->{$method_name}($argument), 'Failed on ' . $method_name . ' (test file: ' . $file . ')');
}
if ($geometry
->geometryType() == 'MultiLineString') {
//TODO: Add a method endPoint() to MultiLineString.
//$this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name);
}
break;
case 'isRing':
if ($geometry
->geometryType() == 'Point') {
$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 . ' (test file: ' . $file . ')');
}
if ($geometry
->geometryType() == 'MultiLineString') {
$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 . ' (test file: ' . $file . ')');
}
if ($geometry
->geometryType() == 'LineString') {
$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 . ' (test file: ' . $file . ')');
}
break;
case 'pointN':
if ($geometry
->geometryType() == 'Point') {
$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 . ' (test file: ' . $file . ')');
}
if ($geometry
->geometryType() == 'MultiLineString') {
//TODO: Add a method pointN() to MultiLineString.
//$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 . ' (test file: ' . $file . ')');
}
if ($geometry
->geometryType() == 'LineString') {
$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 . ' (test file: ' . $file . ')');
}
break;
case 'numInteriorRings':
if ($geometry
->geometryType() == 'Point') {
$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 . ' (test file: ' . $file . ')');
}
if ($geometry
->geometryType() == 'MultiLineString') {
$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 . ' (test file: ' . $file . ')');
}
if ($geometry
->geometryType() == 'LineString') {
$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 . ' (test file: ' . $file . ')');
}
break;
case 'SRID':
break;
case 'getBBox':
if (!$geometry
->isEmpty()) {
if ($geometry
->geometryType() == 'Point') {
$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 . ' (test file: ' . $file . ')');
}
if ($geometry
->geometryType() == 'MultiLineString') {
$this
->assertNotNull($geometry
->{$method_name}($argument), 'Failed on ' . $method_name . ' (test file: ' . $file . ')');
}
}
break;
case 'centroid':
if ($geometry
->geometryType() == 'Point') {
$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 . ' (test file: ' . $file . ')');
}
if ($geometry
->geometryType() == 'MultiLineString') {
$this
->assertNotNull($geometry
->{$method_name}($argument), 'Failed on ' . $method_name . ' (test file: ' . $file . ')');
}
break;
case 'length':
if ($geometry
->geometryType() == 'Point') {
$this
->assertEquals($geometry
->{$method_name}($argument), 0, 'Failed on ' . $method_name . ' (test file: ' . $file . ')');
}
if ($geometry
->geometryType() == 'LineString') {
$this
->assertNotEquals($geometry
->{$method_name}($argument), 0, 'Failed on ' . $method_name . ' (test file: ' . $file . ')');
}
if ($geometry
->geometryType() == 'MultiLineString') {
$this
->assertNotEquals($geometry
->{$method_name}($argument), 0, 'Failed on ' . $method_name . ' (test file: ' . $file . ')');
}
break;
case 'numGeometries':
if ($geometry
->geometryType() == 'Point') {
$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 . ' (test file: ' . $file . ')');
}
if ($geometry
->geometryType() == 'MultiLineString') {
$this
->assertNotNull($geometry
->{$method_name}($argument), 'Failed on ' . $method_name . ' (test file: ' . $file . ')');
}
break;
case 'numPoints':
if ($geometry
->geometryType() == 'Point') {
$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 . ' (test file: ' . $file . ')');
}
if ($geometry
->geometryType() == 'MultiLineString') {
$this
->assertNotNull($geometry
->{$method_name}($argument), 'Failed on ' . $method_name . ' (test file: ' . $file . ')');
}
break;
case 'dimension':
if ($geometry
->geometryType() == 'Point') {
$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 . ' (test file: ' . $file . ')');
}
if ($geometry
->geometryType() == 'MultiLineString') {
$this
->assertNotNull($geometry
->{$method_name}($argument), 'Failed on ' . $method_name . ' (test file: ' . $file . ')');
}
break;
case 'boundary':
if ($geometry
->geometryType() == 'Point') {
$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 . ' (test file: ' . $file . ')');
}
if ($geometry
->geometryType() == 'MultiLineString') {
$this
->assertNotNull($geometry
->{$method_name}($argument), 'Failed on ' . $method_name . ' (test file: ' . $file . ')');
}
break;
case 'haversineLength':
//TODO: Check if output is a float >= 0.
//TODO: Sometimes haversineLength() returns NAN, needs to check why.
break;
case 'greatCircleLength':
case 'area':
$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 . ' (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 . ' (test file: ' . $file . ')');
}
}