You are here

public function MethodsTests::_methods_tester in geoPHP 8

Same name and namespace in other branches
  1. 7 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 73

Class

MethodsTests

Code

public function _methods_tester($geometry, $method_name, $argument) {
  if (!method_exists($geometry, $method_name)) {
    $this
      ->fail("Method " . $method_name . '() doesn\'t exists.');
    return;
  }
  switch ($method_name) {
    case 'y':
    case 'x':
      if ($geometry
        ->geometryType() == 'Point') {
        $this
          ->assertNotNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      if ($geometry
        ->geometryType() == 'LineString') {
        $this
          ->assertNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      if ($geometry
        ->geometryType() == 'MultiLineString') {
        $this
          ->assertNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      break;
    case 'geometryN':
      if ($geometry
        ->geometryType() == 'Point') {
        $this
          ->assertNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      if ($geometry
        ->geometryType() == 'LineString') {
        $this
          ->assertNotNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      if ($geometry
        ->geometryType() == 'MultiLineString') {
        $this
          ->assertNotNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      break;
    case 'startPoint':
      if ($geometry
        ->geometryType() == 'Point') {
        $this
          ->assertNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      if ($geometry
        ->geometryType() == 'LineString') {
        $this
          ->assertNotNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      if ($geometry
        ->geometryType() == 'MultiLineString') {

        // TODO: Add a method startPoint() to MultiLineString.
        // $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name);.
      }
      break;
    case 'endPoint':
      if ($geometry
        ->geometryType() == 'Point') {
        $this
          ->assertNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      if ($geometry
        ->geometryType() == 'LineString') {
        $this
          ->assertNotNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      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);
      }
      if ($geometry
        ->geometryType() == 'LineString') {
        $this
          ->assertNotNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      if ($geometry
        ->geometryType() == 'MultiLineString') {
        $this
          ->assertNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      break;
    case 'isClosed':
      if ($geometry
        ->geometryType() == 'Point') {
        $this
          ->assertNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      if ($geometry
        ->geometryType() == 'LineString') {
        $this
          ->assertNotNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      if ($geometry
        ->geometryType() == 'MultiLineString') {
        $this
          ->assertNotNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      break;
    case 'pointN':
      if ($geometry
        ->geometryType() == 'Point') {
        $this
          ->assertNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      if ($geometry
        ->geometryType() == 'LineString') {
        $this
          ->assertNotNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      if ($geometry
        ->geometryType() == 'MultiLineString') {

        // TODO: Add a method pointN() to MultiLineString.
        // $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name);.
      }
      break;
    case 'exteriorRing':
      if ($geometry
        ->geometryType() == 'Point') {
        $this
          ->assertNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      if ($geometry
        ->geometryType() == 'LineString') {
        $this
          ->assertNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      if ($geometry
        ->geometryType() == 'MultiLineString') {
        $this
          ->assertNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      break;
    case 'numInteriorRings':
      if ($geometry
        ->geometryType() == 'Point') {
        $this
          ->assertNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      if ($geometry
        ->geometryType() == 'LineString') {
        $this
          ->assertNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      if ($geometry
        ->geometryType() == 'MultiLineString') {
        $this
          ->assertNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      break;
    case 'interiorRingN':
      if ($geometry
        ->geometryType() == 'Point') {
        $this
          ->assertNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      if ($geometry
        ->geometryType() == 'LineString') {
        $this
          ->assertNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      if ($geometry
        ->geometryType() == 'MultiLineString') {
        $this
          ->assertNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      break;
    case 'SRID':
      if ($geometry
        ->geometryType() == 'Point') {
        $this
          ->assertNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      if ($geometry
        ->geometryType() == 'LineString') {
        $this
          ->assertNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      if ($geometry
        ->geometryType() == 'MultiLineString') {
        $this
          ->assertNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      break;
    case 'getBBox':
      if ($geometry
        ->geometryType() == 'Point') {
        $this
          ->assertNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      if ($geometry
        ->geometryType() == 'LineString') {
        $this
          ->assertNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      if ($geometry
        ->geometryType() == 'MultiLineString') {
        $this
          ->assertNotNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      break;
    case 'centroid':
      if ($geometry
        ->geometryType() == 'Point') {
        $this
          ->assertNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      if ($geometry
        ->geometryType() == 'LineString') {
        $this
          ->assertNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      if ($geometry
        ->geometryType() == 'MultiLineString') {
        $this
          ->assertNotNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      break;
    case 'length':
      if ($geometry
        ->geometryType() == 'Point') {
        $this
          ->assertNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      if ($geometry
        ->geometryType() == 'LineString') {
        $this
          ->assertNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      if ($geometry
        ->geometryType() == 'MultiLineString') {
        $this
          ->assertNotNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      break;
    case 'numGeometries':
      if ($geometry
        ->geometryType() == 'Point') {
        $this
          ->assertNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      if ($geometry
        ->geometryType() == 'LineString') {
        $this
          ->assertNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      if ($geometry
        ->geometryType() == 'MultiLineString') {
        $this
          ->assertNotNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      break;
    case 'numPoints':
      if ($geometry
        ->geometryType() == 'Point') {
        $this
          ->assertNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      if ($geometry
        ->geometryType() == 'LineString') {
        $this
          ->assertNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      if ($geometry
        ->geometryType() == 'MultiLineString') {
        $this
          ->assertNotNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      break;
    case 'dimension':
      if ($geometry
        ->geometryType() == 'Point') {
        $this
          ->assertNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      if ($geometry
        ->geometryType() == 'LineString') {
        $this
          ->assertNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      if ($geometry
        ->geometryType() == 'MultiLineString') {
        $this
          ->assertNotNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      break;
    case 'boundary':
      if ($geometry
        ->geometryType() == 'Point') {
        $this
          ->assertNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      if ($geometry
        ->geometryType() == 'LineString') {
        $this
          ->assertNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      if ($geometry
        ->geometryType() == 'MultiLineString') {
        $this
          ->assertNotNull($geometry
          ->{$method_name}($argument), 'Failed on ' . $method_name);
      }
      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);
      break;
    case 'geometryType':
      $this
        ->assertNotNull($geometry
        ->{$method_name}($argument), 'Failed on ' . $method_name);
      break;
    case 'setSRID':

      // TODO: The method setSRID() should return TRUE.
      break;
    default:
      $this
        ->assertTrue($geometry
        ->{$method_name}($argument), 'Failed on ' . $method_name);
  }
}