88use Grimzy \LaravelMysqlSpatial \Types \Point ;
99use Grimzy \LaravelMysqlSpatial \Types \Polygon ;
1010use Illuminate \Filesystem \Filesystem ;
11+ use Illuminate \Support \Facades \DB ;
1112use Laravel \BrowserKitTesting \TestCase as BaseTestCase ;
1213
1314class 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