8
8
use Grimzy \LaravelMysqlSpatial \Types \Point ;
9
9
use Grimzy \LaravelMysqlSpatial \Types \Polygon ;
10
10
use Illuminate \Filesystem \Filesystem ;
11
+ use Illuminate \Support \Facades \DB ;
11
12
use Laravel \BrowserKitTesting \TestCase as BaseTestCase ;
12
13
13
14
class SpatialTest extends BaseTestCase
14
15
{
16
+ protected $ after_fix = false ;
17
+
15
18
/**
16
19
* Boots the application.
17
20
*
@@ -42,9 +45,15 @@ public function setUp()
42
45
{
43
46
parent ::setUp ();
44
47
48
+ $ this ->after_fix = $ this ->isMySQL8AfterFix ();
49
+
45
50
$ this ->onMigrations (function ($ migrationClass ) {
46
51
(new $ migrationClass ())->up ();
47
52
});
53
+
54
+ //\DB::listen(function($sql) {
55
+ // var_dump($sql);
56
+ //});
48
57
}
49
58
50
59
public function tearDown ()
@@ -56,6 +65,13 @@ public function tearDown()
56
65
parent ::tearDown ();
57
66
}
58
67
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
+
59
75
protected function assertDatabaseHas ($ table , array $ data , $ connection = null )
60
76
{
61
77
if (method_exists ($ this , 'seeInDatabase ' )) {
@@ -249,7 +265,11 @@ public function testDistanceSphere()
249
265
$ this ->assertTrue ($ b ->contains ('location ' , $ loc2 ->location ));
250
266
$ this ->assertFalse ($ b ->contains ('location ' , $ loc3 ->location ));
251
267
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
+ }
253
273
$ this ->assertCount (1 , $ c );
254
274
$ this ->assertTrue ($ c ->contains ('location ' , $ loc1 ->location ));
255
275
$ this ->assertFalse ($ c ->contains ('location ' , $ loc2 ->location ));
@@ -279,13 +299,18 @@ public function testDistanceSphereValue()
279
299
$ loc1 ->save ();
280
300
281
301
$ 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
283
303
$ loc2 ->save ();
284
304
285
305
$ a = GeometryModel::distanceSphereValue ('location ' , $ loc1 ->location )->get ();
286
306
$ this ->assertCount (2 , $ a );
287
307
$ 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
+ }
289
314
}
290
315
291
316
//public function testBounding() {
0 commit comments