@@ -52,10 +52,11 @@ public function tearDown()
5252
5353 protected function assertDatabaseHas ($ table , array $ data , $ connection = null )
5454 {
55- if (method_exists ($ this , 'seeInDatabase ' )) {
55+ if (method_exists ($ this , 'seeInDatabase ' )) {
5656 $ this ->seeInDatabase ($ table , $ data , $ connection );
57+ } else {
58+ parent ::assertDatabaseHas ($ table , $ data , $ connection );
5759 }
58- parent ::assertDatabaseHas ($ table , $ data , $ connection );
5960 }
6061
6162 private function onMigrations (\Closure $ closure )
@@ -101,4 +102,37 @@ public function testUpdate()
101102 $ this ->assertEquals (2 , $ updated ->location ->getLat ());
102103 $ this ->assertEquals (3 , $ updated ->location ->getLng ());
103104 }
105+
106+ public function testDistance ()
107+ {
108+ $ loc1 = new GeometryModel ();
109+ $ loc1 ->location = new Point (40.767864 , -73.971732 );
110+ $ loc1 ->save ();
111+
112+ $ loc2 = new GeometryModel ();
113+ $ loc2 ->location = new Point (40.767664 , -73.971271 ); // Distance from loc1: 44.7414064845878
114+ $ loc2 ->save ();
115+
116+ $ loc3 = new GeometryModel ();
117+ $ loc3 ->location = new Point (40.761434 , -73.977619 );
118+ $ loc3 ->save ();
119+
120+ $ a = GeometryModel::distance (45 , $ loc1 ->location , 'location ' )->get ();
121+ $ this ->assertCount (2 , $ a );
122+ $ this ->assertTrue ($ a ->contains ($ loc1 ));
123+ $ this ->assertTrue ($ a ->contains ($ loc2 ));
124+ $ this ->assertFalse ($ a ->contains ($ loc3 ));
125+
126+ $ b = GeometryModel::distance (45 , $ loc1 ->location , 'location ' , true )->get ();
127+ $ this ->assertCount (1 , $ b );
128+ $ this ->assertFalse ($ b ->contains ($ loc1 ));
129+ $ this ->assertTrue ($ b ->contains ($ loc2 ));
130+ $ this ->assertFalse ($ b ->contains ($ loc3 ));
131+
132+ $ c = GeometryModel::distance (44.741406484587 , $ loc1 ->location , 'location ' )->get ();
133+ $ this ->assertCount (1 , $ c );
134+ $ this ->assertTrue ($ c ->contains ($ loc1 ));
135+ $ this ->assertFalse ($ c ->contains ($ loc2 ));
136+ $ this ->assertFalse ($ c ->contains ($ loc3 ));
137+ }
104138}
0 commit comments