Skip to content

Commit

Permalink
Merge pull request #53 from grimzy/build-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
grimzy authored Jun 16, 2018
2 parents 78c96b5 + 4dd729d commit 99c02b2
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 62 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ php:
- '5.6'
- '7.0'
- '7.1'
- '7.2'

env:
- MYSQL_VERSION=5.7
Expand Down
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
4 changes: 2 additions & 2 deletions src/Eloquent/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Grimzy\LaravelMysqlSpatial\Eloquent;

use Illuminate\Database\Query\Builder;
use Illuminate\Database\Query\Builder as QueryBuilder;

class BaseBuilder extends Builder
class BaseBuilder extends QueryBuilder
{
protected function cleanBindings(array $bindings)
{
Expand Down
1 change: 1 addition & 0 deletions src/MysqlConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function __construct($pdo, $database = '', $tablePrefix = '', array $conf
'multilinestring',
'multipolygon',
'geometrycollection',
'geomcollection',
];
$dbPlatform = $this->getDoctrineSchemaManager()->getDatabasePlatform();
foreach ($geometries as $type) {
Expand Down
10 changes: 9 additions & 1 deletion tests/Integration/SpatialTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ public function createApplication()
$app['config']->set('database.connections.mysql.database', 'spatial_test');
$app['config']->set('database.connections.mysql.username', 'root');
$app['config']->set('database.connections.mysql.password', '');
$app['config']->set('database.connections.mysql.modes', [
'ONLY_FULL_GROUP_BY',
'STRICT_TRANS_TABLES',
'NO_ZERO_IN_DATE',
'NO_ZERO_DATE',
'ERROR_FOR_DIVISION_BY_ZERO',
'NO_ENGINE_SUBSTITUTION',
]);

return $app;
}
Expand Down Expand Up @@ -71,7 +79,7 @@ private function isMySQL8AfterFix()
$results = DB::select(DB::raw('select version()'));
$mysql_version = $results[0]->{'version()'};

return strpos($mysql_version, '8.0.4') !== false;
return version_compare($mysql_version, '8.0.4', '>=');
}

protected function assertDatabaseHas($table, array $data, $connection = null)
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
Loading

0 comments on commit 99c02b2

Please sign in to comment.