Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
v1r0x committed Aug 1, 2018
1 parent d5c86b1 commit 1a691ea
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 0 deletions.
45 changes: 45 additions & 0 deletions tests/Eloquent/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,51 @@ public function testUpdateLinestring()

$builder->update(['linestring' => $linestring]);
}

public function testUpdate3d()
{
$this->queryBuilder
->shouldReceive('raw')
->with("public.ST_GeogFromText('POINT Z(2 1 0)')")
->andReturn(new Expression("public.ST_GeogFromText('POINT Z(2 1 0)')"));

$this->queryBuilder
->shouldReceive('update')
->andReturn(1);

$builder = m::mock(Builder::class, [$this->queryBuilder])->makePartial();
$builder->shouldAllowMockingProtectedMethods();
$builder
->shouldReceive('addUpdatedAtColumn')
->andReturn(['point' => new Point(1, 2, 0)]);

$builder->update(['point' => new Point(1, 2, 0)]);
}

public function testUpdateLinestring3d()
{
$this->queryBuilder
->shouldReceive('raw')
->with("public.ST_GeogFromText('LINESTRING Z(0 0 0, 1 1 1, 2 2 2)')")
->andReturn(new Expression("public.ST_GeogFromText('LINESTRING Z(0 0 0, 1 1 1, 2 2 2)')"));

$this->queryBuilder
->shouldReceive('update')
->andReturn(1);

$linestring = new LineString([new Point(0, 0, 0), new Point(1, 1, 1), new Point(2, 2, 2)]);

$builder = m::mock(Builder::class, [$this->queryBuilder])->makePartial();
$builder->shouldAllowMockingProtectedMethods();
$builder
->shouldReceive('addUpdatedAtColumn')
->andReturn(['linestring' => $linestring]);

$builder
->shouldReceive('asWKT')->with($linestring)->once();

$builder->update(['linestring' => $linestring]);
}
}

class TestBuilderModel extends Model
Expand Down
25 changes: 25 additions & 0 deletions tests/Eloquent/PostgisTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,31 @@ public function testUpdatePointHasCorrectSql()

$this->assertContains("public.ST_GeogFromText('POINT(4 2)')", $this->queries[0]);
}

public function testInsertPoint3dHasCorrectSql()
{
$this->model->point = new Point(1, 2, 3);
$this->model->save();

$this->assertContains("public.ST_GeogFromText('POINT Z(2 1 3)')", $this->queries[0]);
}

public function testInsertPoint3dGeometryHasCorrectSql()
{
$this->model->point2 = new Point(1, 2, 3);
$this->model->save();

$this->assertContains("public.ST_GeomFromText('POINT Z(2 1 3)', '27700')", $this->queries[0]);
}

public function testUpdatePoint3dHasCorrectSql()
{
$this->model->exists = true;
$this->model->point = new Point(2, 4, 6);
$this->model->save();

$this->assertContains("public.ST_GeogFromText('POINT Z(4 2 6)')", $this->queries[0]);
}
}

class TestModel extends Model
Expand Down
50 changes: 50 additions & 0 deletions tests/Geometries/GeometryCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class GeometryCollectionTest extends BaseTestCase
* @var GeometryCollection
*/
private $collection;
private $collection3d;

protected function setUp()
{
Expand All @@ -26,6 +27,20 @@ protected function setUp()
$point = new Point(100, 200);

$this->collection = new GeometryCollection([$collection, $point]);

$collection = new LineString(
[
new Point(1, 1, 1),
new Point(1, 2, 3),
new Point(2, 2, 2),
new Point(2, 1, 0),
new Point(1, 1, 1)
]
);

$point = new Point(100, 200, 300);

$this->collection3d = new GeometryCollection([$collection, $point]);
}


Expand All @@ -42,6 +57,19 @@ public function testFromWKT()
$this->assertInstanceOf(LineString::class, $geometryCollection->getGeometries()[1]);
}

public function testFromWKT3d()
{
/**
* @var GeometryCollection $geometryCollection
*/
$geometryCollection = GeometryCollection::fromWKT('GEOMETRYCOLLECTION(POINT Z(2 3 4),LINESTRING Z(2 3 4,3 4 5))');
$this->assertInstanceOf(GeometryCollection::class, $geometryCollection);

$this->assertEquals(2, $geometryCollection->count());
$this->assertInstanceOf(Point::class, $geometryCollection->getGeometries()[0]);
$this->assertInstanceOf(LineString::class, $geometryCollection->getGeometries()[1]);
}

public function testToWKT()
{
$this->assertEquals(
Expand All @@ -50,6 +78,14 @@ public function testToWKT()
);
}

public function testToWKT3d()
{
$this->assertEquals(
'GEOMETRYCOLLECTION(LINESTRING Z(1 1 1,2 1 3,2 2 2,1 2 0,1 1 1),POINT Z(200 100 300))',
$this->collection3d->toWKT()
);
}

public function testJsonSerialize()
{
$this->assertInstanceOf(
Expand All @@ -63,4 +99,18 @@ public function testJsonSerialize()
);

}

public function testJsonSerialize3d()
{
$this->assertInstanceOf(
\GeoJson\Geometry\GeometryCollection::class,
$this->collection3d->jsonSerialize()
);

$this->assertSame(
'{"type":"GeometryCollection","geometries":[{"type":"LineString","coordinates":[[1,1,1],[2,1,3],[2,2,2],[1,2,0],[1,1,1]]},{"type":"Point","coordinates":[200,100,300]}]}',
json_encode($this->collection3d->jsonSerialize())
);

}
}

0 comments on commit 1a691ea

Please sign in to comment.