Skip to content

Commit

Permalink
Reverted Mockery update. Fixed some unit tests unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
grimzy committed Jun 16, 2018
1 parent 78c96b5 commit 66eecf4
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 45 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"require-dev": {
"phpunit/phpunit": "~4.8||~5.7",
"mockery/mockery": "^1.1.0",
"mockery/mockery": "^0.9.9",
"laravel/laravel": "^5.2",
"doctrine/dbal": "^2.5",
"laravel/browser-kit-testing": "^2.0",
Expand Down
32 changes: 11 additions & 21 deletions tests/Unit/Eloquent/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use BaseTestCase;
use Grimzy\LaravelMysqlSpatial\Eloquent\Builder;
use Grimzy\LaravelMysqlSpatial\Eloquent\SpatialExpression;
use Grimzy\LaravelMysqlSpatial\Eloquent\SpatialTrait;
use Grimzy\LaravelMysqlSpatial\MysqlConnection;
use Grimzy\LaravelMysqlSpatial\Types\LineString;
Expand Down Expand Up @@ -36,50 +37,39 @@ protected function setUp()

public function testUpdatePoint()
{
$this->queryBuilder
->shouldReceive('raw')
->with("ST_GeomFromText('POINT(2 1)')")
->once();

$point = new Point(1, 2);
$this->queryBuilder
->shouldReceive('update')
->with(['point' => new SpatialExpression($point)])
->once();

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

public function testUpdateLinestring()
{
$this->queryBuilder
->shouldReceive('raw')
->with("ST_GeomFromText('LINESTRING(0 0,1 1,2 2)')")
->once();
$linestring = new LineString([new Point(0, 0), new Point(1, 1), new Point(2, 2)]);

$this->queryBuilder
->shouldReceive('update')
->with(['linestring' => new SpatialExpression($linestring)])
->once();

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

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

public function testUpdatePolygon()
{
$this->queryBuilder
->shouldReceive('raw')
->with("ST_GeomFromText('POLYGON((0 0,1 0),(1 0,1 1),(1 1,0 0))')")
->once();

$this->queryBuilder
->shouldReceive('update')
->once();

$linestrings[] = new LineString([new Point(0, 0), new Point(0, 1)]);
$linestrings[] = new LineString([new Point(0, 1), new Point(1, 1)]);
$linestrings[] = new LineString([new Point(1, 1), new Point(0, 0)]);
$polygon = new Polygon($linestrings);

$this->queryBuilder
->shouldReceive('update')
->with(['polygon' => new SpatialExpression($polygon)])
->once();

$this->builder->update(['polygon' => $polygon]);
}
}
Expand Down
86 changes: 63 additions & 23 deletions tests/Unit/Eloquent/SpatialTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,10 @@ public function testScopeDistance()
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
$q = $query->getQuery();
$this->assertNotEmpty($q->wheres);
$this->assertContains("st_distance(`point`, ST_GeomFromText('POINT(2 1)')) <= 10", $q->wheres[0]['sql']);
$this->assertNotEmpty($q->bindings['where']);
$this->assertEquals('st_distance(`point`, ST_GeomFromText(?)) <= ?', $q->wheres[0]['sql']);
$this->assertEquals('POINT(2 1)', $q->bindings['where'][0]);
$this->assertEquals(10, $q->bindings['where'][1]);
}

public function testScopeDistanceExcludingSelf()
Expand All @@ -226,8 +229,12 @@ public function testScopeDistanceExcludingSelf()
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
$q = $query->getQuery();
$this->assertNotEmpty($q->wheres);
$this->assertContains("st_distance(`point`, ST_GeomFromText('POINT(2 1)')) <= 10", $q->wheres[0]['sql']);
$this->assertContains("st_distance(`point`, ST_GeomFromText('POINT(2 1)')) != 0", $q->wheres[1]['sql']);
$this->assertNotEmpty($q->bindings['where']);
$this->assertEquals('st_distance(`point`, ST_GeomFromText(?)) <= ?', $q->wheres[0]['sql']);
$this->assertEquals('st_distance(`point`, ST_GeomFromText(?)) != 0', $q->wheres[1]['sql']);
$this->assertEquals('POINT(2 1)', $q->bindings['where'][0]);
$this->assertEquals(10, $q->bindings['where'][1]);
$this->assertEquals('POINT(2 1)', $q->bindings['where'][2]);
}

public function testScopeDistanceSphere()
Expand All @@ -238,7 +245,10 @@ public function testScopeDistanceSphere()
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
$q = $query->getQuery();
$this->assertNotEmpty($q->wheres);
$this->assertContains("st_distance_sphere(`point`, ST_GeomFromText('POINT(2 1)')) <= 10", $q->wheres[0]['sql']);
$this->assertNotEmpty($q->bindings['where']);
$this->assertEquals('st_distance_sphere(`point`, ST_GeomFromText(?)) <= ?', $q->wheres[0]['sql']);
$this->assertEquals('POINT(2 1)', $q->bindings['where'][0]);
$this->assertEquals(10, $q->bindings['where'][1]);
}

public function testScopeDistanceSphereExcludingSelf()
Expand All @@ -249,8 +259,12 @@ public function testScopeDistanceSphereExcludingSelf()
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
$q = $query->getQuery();
$this->assertNotEmpty($q->wheres);
$this->assertContains("st_distance_sphere(`point`, ST_GeomFromText('POINT(2 1)')) <= 10", $q->wheres[0]['sql']);
$this->assertContains("st_distance_sphere(`point`, ST_GeomFromText('POINT(2 1)')) != 0", $q->wheres[1]['sql']);
$this->assertNotEmpty($q->bindings['where']);
$this->assertEquals('st_distance_sphere(`point`, ST_GeomFromText(?)) <= ?', $q->wheres[0]['sql']);
$this->assertEquals('st_distance_sphere(point, ST_GeomFromText(?)) != 0', $q->wheres[1]['sql']);
$this->assertEquals('POINT(2 1)', $q->bindings['where'][0]);
$this->assertEquals(10, $q->bindings['where'][1]);
$this->assertEquals('POINT(2 1)', $q->bindings['where'][2]);
}

public function testScopeDistanceValue()
Expand All @@ -261,9 +275,11 @@ public function testScopeDistanceValue()
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
$q = $query->getQuery();
$this->assertNotEmpty($q->columns);
$this->assertContains('*', $q->columns[0]);
$this->assertNotEmpty($q->bindings['select']);
$this->assertEquals('*', $q->columns[0]);
$this->assertInstanceOf(\Illuminate\Database\Query\Expression::class, $q->columns[1]);
$this->assertContains("st_distance(`point`, ST_GeomFromText('POINT(2 1)')) as distance", $q->columns[1]->getValue());
$this->assertEquals('st_distance(`point`, ST_GeomFromText(?)) as distance', $q->columns[1]->getValue());
$this->assertEquals('POINT(2 1)', $q->bindings['select'][0]);
}

public function testScopeDistanceValueWithSelect()
Expand All @@ -274,9 +290,11 @@ public function testScopeDistanceValueWithSelect()
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
$q = $query->getQuery();
$this->assertNotEmpty($q->columns);
$this->assertContains('some_column', $q->columns[0]);
$this->assertNotEmpty($q->bindings['select']);
$this->assertEquals('some_column', $q->columns[0]);
$this->assertInstanceOf(\Illuminate\Database\Query\Expression::class, $q->columns[1]);
$this->assertContains("st_distance(`point`, ST_GeomFromText('POINT(2 1)')) as distance", $q->columns[1]->getValue());
$this->assertEquals('st_distance(`point`, ST_GeomFromText(?)) as distance', $q->columns[1]->getValue());
$this->assertEquals('POINT(2 1)', $q->bindings['select'][0]);
}

public function testScopeDistanceSphereValue()
Expand All @@ -287,9 +305,11 @@ public function testScopeDistanceSphereValue()
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
$q = $query->getQuery();
$this->assertNotEmpty($q->columns);
$this->assertContains('*', $q->columns[0]);
$this->assertNotEmpty($q->bindings['select']);
$this->assertEquals('*', $q->columns[0]);
$this->assertInstanceOf(\Illuminate\Database\Query\Expression::class, $q->columns[1]);
$this->assertContains("st_distance_sphere(`point`, ST_GeomFromText('POINT(2 1)')) as distance", $q->columns[1]->getValue());
$this->assertEquals('st_distance_sphere(`point`, ST_GeomFromText(?)) as distance', $q->columns[1]->getValue());
$this->assertEquals('POINT(2 1)', $q->bindings['select'][0]);
}

public function testScopeDistanceSphereValueWithSelect()
Expand All @@ -300,9 +320,11 @@ public function testScopeDistanceSphereValueWithSelect()
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
$q = $query->getQuery();
$this->assertNotEmpty($q->columns);
$this->assertContains('some_column', $q->columns[0]);
$this->assertNotEmpty($q->bindings['select']);
$this->assertEquals('some_column', $q->columns[0]);
$this->assertInstanceOf(\Illuminate\Database\Query\Expression::class, $q->columns[1]);
$this->assertContains("st_distance_sphere(`point`, ST_GeomFromText('POINT(2 1)')) as distance", $q->columns[1]->getValue());
$this->assertEquals('st_distance_sphere(`point`, ST_GeomFromText(?)) as distance', $q->columns[1]->getValue());
$this->assertEquals('POINT(2 1)', $q->bindings['select'][0]);
}

private function buildTestPolygon()
Expand All @@ -327,7 +349,9 @@ public function testScopeComparison()
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
$q = $query->getQuery();
$this->assertNotEmpty($q->wheres);
$this->assertContains("st_within(`point`, ST_GeomFromText('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))'))", $q->wheres[0]['sql']);
$this->assertNotEmpty($q->bindings['where']);
$this->assertContains('st_within(`point`, ST_GeomFromText(?))', $q->wheres[0]['sql']);
$this->assertEquals('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))', $q->bindings['where'][0]);
}

public function testScopeWithin()
Expand All @@ -337,7 +361,9 @@ public function testScopeWithin()
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
$q = $query->getQuery();
$this->assertNotEmpty($q->wheres);
$this->assertContains("st_within(`point`, ST_GeomFromText('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))'))", $q->wheres[0]['sql']);
$this->assertNotEmpty($q->bindings['where']);
$this->assertContains('st_within(`point`, ST_GeomFromText(?))', $q->wheres[0]['sql']);
$this->assertEquals('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))', $q->bindings['where'][0]);
}

public function testScopeCrosses()
Expand All @@ -347,7 +373,9 @@ public function testScopeCrosses()
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
$q = $query->getQuery();
$this->assertNotEmpty($q->wheres);
$this->assertContains("st_crosses(`point`, ST_GeomFromText('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))'))", $q->wheres[0]['sql']);
$this->assertNotEmpty($q->bindings['where']);
$this->assertContains('st_crosses(`point`, ST_GeomFromText(?))', $q->wheres[0]['sql']);
$this->assertEquals('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))', $q->bindings['where'][0]);
}

public function testScopeContains()
Expand All @@ -357,7 +385,9 @@ public function testScopeContains()
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
$q = $query->getQuery();
$this->assertNotEmpty($q->wheres);
$this->assertContains("st_contains(`point`, ST_GeomFromText('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))'))", $q->wheres[0]['sql']);
$this->assertNotEmpty($q->bindings['where']);
$this->assertContains('st_contains(`point`, ST_GeomFromText(?))', $q->wheres[0]['sql']);
$this->assertEquals('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))', $q->bindings['where'][0]);
}

public function testScopeDisjoint()
Expand All @@ -367,7 +397,9 @@ public function testScopeDisjoint()
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
$q = $query->getQuery();
$this->assertNotEmpty($q->wheres);
$this->assertContains("st_disjoint(`point`, ST_GeomFromText('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))'))", $q->wheres[0]['sql']);
$this->assertNotEmpty($q->bindings['where']);
$this->assertContains('st_disjoint(`point`, ST_GeomFromText(?))', $q->wheres[0]['sql']);
$this->assertEquals('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))', $q->bindings['where'][0]);
}

public function testScopeEquals()
Expand All @@ -377,7 +409,9 @@ public function testScopeEquals()
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
$q = $query->getQuery();
$this->assertNotEmpty($q->wheres);
$this->assertContains("st_equals(`point`, ST_GeomFromText('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))'))", $q->wheres[0]['sql']);
$this->assertNotEmpty($q->bindings['where']);
$this->assertContains('st_equals(`point`, ST_GeomFromText(?))', $q->wheres[0]['sql']);
$this->assertEquals('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))', $q->bindings['where'][0]);
}

public function testScopeIntersects()
Expand All @@ -387,7 +421,9 @@ public function testScopeIntersects()
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
$q = $query->getQuery();
$this->assertNotEmpty($q->wheres);
$this->assertContains("st_intersects(`point`, ST_GeomFromText('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))'))", $q->wheres[0]['sql']);
$this->assertNotEmpty($q->bindings['where']);
$this->assertContains('st_intersects(`point`, ST_GeomFromText(?))', $q->wheres[0]['sql']);
$this->assertEquals('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))', $q->bindings['where'][0]);
}

public function testScopeOverlaps()
Expand All @@ -397,7 +433,9 @@ public function testScopeOverlaps()
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
$q = $query->getQuery();
$this->assertNotEmpty($q->wheres);
$this->assertContains("st_overlaps(`point`, ST_GeomFromText('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))'))", $q->wheres[0]['sql']);
$this->assertNotEmpty($q->bindings['where']);
$this->assertContains('st_overlaps(`point`, ST_GeomFromText(?))', $q->wheres[0]['sql']);
$this->assertEquals('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))', $q->bindings['where'][0]);
}

public function testScopeDoesTouch()
Expand All @@ -407,7 +445,9 @@ public function testScopeDoesTouch()
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
$q = $query->getQuery();
$this->assertNotEmpty($q->wheres);
$this->assertContains("st_touches(`point`, ST_GeomFromText('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))'))", $q->wheres[0]['sql']);
$this->assertNotEmpty($q->bindings['where']);
$this->assertContains('st_touches(`point`, ST_GeomFromText(?))', $q->wheres[0]['sql']);
$this->assertEquals('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))', $q->bindings['where'][0]);
}
}

Expand Down

0 comments on commit 66eecf4

Please sign in to comment.