Skip to content

Commit a2c8ff0

Browse files
committed
Fixed integration tests accounting for MySQL 8.0.4 covering Bug #26941370, Bug #88031. Fix for change in MySQL default auth plugin.
1 parent f37254c commit a2c8ff0

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

Makefile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
V=5.7
22
DB_DIR=$(shell pwd)/_db-$(V)
3+
mV=10.3
4+
mDB_DIR=$(shell pwd)/_db-$(mV)
35

46
start_db:
57
@echo Starting MySQL $(V)
@@ -8,7 +10,17 @@ start_db:
810
-v $(DB_DIR):/var/lib/mysql \
911
-e MYSQL_DATABASE=spatial_test \
1012
-e MYSQL_ALLOW_EMPTY_PASSWORD=yes \
11-
mysql:$(V) --character-set-server=utf8 --collation-server=utf8_general_ci
13+
mysql:$(V) --character-set-server=utf8 --collation-server=utf8_general_ci --default-auth=mysql_native_password
14+
15+
start_db_maria:
16+
@echo Starting MariaDB $(mV)
17+
docker run --rm -d --name spatial-mysql \
18+
-p 3306:3306 \
19+
-v $(DB_DIR):/var/lib/mysql \
20+
-e MYSQL_DATABASE=spatial_test \
21+
-e MYSQL_ALLOW_EMPTY_PASSWORD=yes \
22+
mariadb:$(mV) --character-set-server=utf8 --collation-server=utf8_general_ci --default-auth=mysql_native_password
23+
1224

1325
rm_db:
1426
docker stop spatial-mysql || true

tests/Integration/SpatialTest.php

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88
use Grimzy\LaravelMysqlSpatial\Types\Point;
99
use Grimzy\LaravelMysqlSpatial\Types\Polygon;
1010
use Illuminate\Filesystem\Filesystem;
11+
use Illuminate\Support\Facades\DB;
1112
use Laravel\BrowserKitTesting\TestCase as BaseTestCase;
1213

1314
class SpatialTest extends BaseTestCase
1415
{
16+
protected $after_fix = false;
17+
1518
/**
1619
* Boots the application.
1720
*
@@ -42,9 +45,15 @@ public function setUp()
4245
{
4346
parent::setUp();
4447

48+
$this->after_fix = $this->isMySQL8AfterFix();
49+
4550
$this->onMigrations(function ($migrationClass) {
4651
(new $migrationClass())->up();
4752
});
53+
54+
//\DB::listen(function($sql) {
55+
// var_dump($sql);
56+
//});
4857
}
4958

5059
public function tearDown()
@@ -56,6 +65,13 @@ public function tearDown()
5665
parent::tearDown();
5766
}
5867

68+
// MySQL 8.0.4 fixed bug #26941370 and bug #88031
69+
private function isMySQL8AfterFix() {
70+
$results = DB::select(DB::raw("select version()"));
71+
$mysql_version = $results[0]->{'version()'};
72+
return (strpos($mysql_version, '8.0.4') !== false);
73+
}
74+
5975
protected function assertDatabaseHas($table, array $data, $connection = null)
6076
{
6177
if (method_exists($this, 'seeInDatabase')) {
@@ -249,7 +265,11 @@ public function testDistanceSphere()
249265
$this->assertTrue($b->contains('location', $loc2->location));
250266
$this->assertFalse($b->contains('location', $loc3->location));
251267

252-
$c = GeometryModel::distanceSphere('location', $loc1->location, 44.741406484587)->get();
268+
if ($this->after_fix) {
269+
$c = GeometryModel::distanceSphere('location', $loc1->location, 44.741406484236)->get();
270+
} else {
271+
$c = GeometryModel::distanceSphere('location', $loc1->location, 44.741406484587)->get();
272+
}
253273
$this->assertCount(1, $c);
254274
$this->assertTrue($c->contains('location', $loc1->location));
255275
$this->assertFalse($c->contains('location', $loc2->location));
@@ -279,13 +299,18 @@ public function testDistanceSphereValue()
279299
$loc1->save();
280300

281301
$loc2 = new GeometryModel();
282-
$loc2->location = new Point(40.767664, -73.971271); // Distance from loc1: 44.741406484588
302+
$loc2->location = new Point(40.767664, -73.971271); // Distance from loc1: 44.741406484236
283303
$loc2->save();
284304

285305
$a = GeometryModel::distanceSphereValue('location', $loc1->location)->get();
286306
$this->assertCount(2, $a);
287307
$this->assertEquals(0, $a[0]->distance);
288-
$this->assertEquals(44.7414064845, $a[1]->distance); // PHP floats' 11th+ digits don't matter
308+
309+
if ($this->after_fix) {
310+
$this->assertEquals(44.7414064842, $a[1]->distance); // PHP floats' 11th+ digits don't matter
311+
} else {
312+
$this->assertEquals(44.7414064845, $a[1]->distance); // PHP floats' 11th+ digits don't matter
313+
}
289314
}
290315

291316
//public function testBounding() {

0 commit comments

Comments
 (0)