You are here

class AliasesTests in geoPHP 8

Hierarchy

Expanded class hierarchy of AliasesTests

File

geoPHP/tests/tests/aliasesTest.php, line 8

View source
class AliasesTests extends PHPUnit_Framework_TestCase {

  /**
   *
   */
  public function setUp() {
  }

  /**
   *
   */
  public function testAliases() {
    foreach (scandir('./input') as $file) {
      $parts = explode('.', $file);
      if ($parts[0]) {
        $format = $parts[1];
        $value = file_get_contents('./input/' . $file);
        $geometry = geoPHP::load($value, $format);
        $aliases = [
          [
            'name' => 'getCentroid',
          ],
          [
            'name' => 'getArea',
          ],
          [
            'name' => 'getX',
          ],
          [
            'name' => 'getY',
          ],
          [
            'name' => 'getGeos',
          ],
          [
            'name' => 'getGeomType',
          ],
          [
            'name' => 'getSRID',
          ],
          [
            'name' => 'asText',
          ],
          [
            'name' => 'asBinary',
          ],
        ];
        foreach ($aliases as $alias) {
          $argument = NULL;
          $alias_name = $alias['name'];
          if (isset($alias['argument'])) {
            $argument = $alias['argument'];
          }
          switch ($alias_name) {
            case 'getSRID':
              if ($geometry
                ->geometryType() == 'Point') {
                $this
                  ->assertNotNull($geometry
                  ->{$alias_name}($argument), 'Failed on ' . $alias_name);
              }
              if ($geometry
                ->geometryType() == 'LineString') {
                $this
                  ->assertNotNull($geometry
                  ->{$alias_name}($argument), 'Failed on ' . $alias_name);
              }
              if ($geometry
                ->geometryType() == 'MultiLineString') {
                $this
                  ->assertNull($geometry
                  ->{$alias_name}($argument), 'Failed on ' . $alias_name);
              }
              break;
            case 'getGeos':
              if ($geometry
                ->geometryType() == 'Point') {
                $this
                  ->assertNotNull($geometry
                  ->{$alias_name}($argument), 'Failed on ' . $alias_name);
              }
              if ($geometry
                ->geometryType() == 'LineString') {
                $this
                  ->assertNotNull($geometry
                  ->{$alias_name}($argument), 'Failed on ' . $alias_name);
              }
              if ($geometry
                ->geometryType() == 'MultiLineString') {
                $this
                  ->assertNotNull($geometry
                  ->{$alias_name}($argument), 'Failed on ' . $alias_name);
              }
              break;
            case 'getX':
            case 'getY':
              if ($geometry
                ->geometryType() == 'Point') {
                $this
                  ->assertNotNull($geometry
                  ->{$alias_name}($argument), 'Failed on ' . $alias_name);
              }
              if ($geometry
                ->geometryType() == 'LineString') {
                $this
                  ->assertNull($geometry
                  ->{$alias_name}($argument), 'Failed on ' . $alias_name);
              }
              if ($geometry
                ->geometryType() == 'MultiLineString') {
                $this
                  ->assertNull($geometry
                  ->{$alias_name}($argument), 'Failed on ' . $alias_name);
              }
              break;
            case 'getArea':
              if ($geometry
                ->geometryType() == 'Point') {
                $this
                  ->assertNull($geometry
                  ->{$alias_name}($argument), 'Failed on ' . $alias_name);
              }
              if ($geometry
                ->geometryType() == 'LineString') {
                $this
                  ->assertNull($geometry
                  ->{$alias_name}($argument), 'Failed on ' . $alias_name);
              }
              if ($geometry
                ->geometryType() == 'MultiLineString') {
                $this
                  ->assertNotNull($geometry
                  ->{$alias_name}($argument), 'Failed on ' . $alias_name);
              }
              break;
            case 'getCentroid':
              if ($geometry
                ->geometryType() == 'Point') {
                $this
                  ->assertNotNull($geometry
                  ->{$alias_name}($argument), 'Failed on ' . $alias_name);
              }
              if ($geometry
                ->geometryType() == 'LineString') {
                $this
                  ->assertNotNull($geometry
                  ->{$alias_name}($argument), 'Failed on ' . $alias_name);
              }
              if ($geometry
                ->geometryType() == 'MultiLineString') {
                $this
                  ->assertNotNull($geometry
                  ->{$alias_name}($argument), 'Failed on ' . $alias_name);
              }
              break;
            case 'asText':
            case 'asBinary':
            case 'getGeomType':
              $this
                ->assertNotNull($geometry
                ->{$alias_name}($argument), 'Failed on ' . $alias_name);
              break;
            default:
              $this
                ->assertTrue($geometry
                ->{$alias_name}($argument), 'Failed on ' . $alias_name);
          }
        }
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AliasesTests::setUp public function Sets up the fixture, for example, open a network connection. This method is called before a test is executed.
AliasesTests::testAliases public function