55use Illuminate \Foundation \Testing \DatabaseMigrations ;
66use MatanYadaev \EloquentSpatial \Objects \MultiPolygon ;
77use MatanYadaev \EloquentSpatial \Objects \Point ;
8+ use MatanYadaev \EloquentSpatial \Objects \Polygon ;
89use MatanYadaev \EloquentSpatial \Tests \TestCase ;
910use MatanYadaev \EloquentSpatial \Tests \TestModels \TestPlace ;
1011
@@ -173,11 +174,11 @@ public function it_orders_by_distance_sphere(): void
173174 public function it_filters_by_within (): void
174175 {
175176 TestPlace::factory ()->create ([
176- 'multi_polygon ' => MultiPolygon:: fromJson ( ' {"type":"MultiPolygon","coordinates":[[[[55.5, 23.1],[ 55.6,23.2],[55.7,23.3],[55.5,23.1]]]]} ' ),
177+ 'point ' => new Point ( 23.1 , 55.5 ),
177178 ]);
178179
179180 $ testPlace = TestPlace::query ()
180- ->whereWithin ('multi_polygon ' , new Point ( 23.1 , 55.51 ))
181+ ->whereWithin ('point ' , MultiPolygon:: fromJson ( ' {"type":"MultiPolygon","coordinates":[[[[55.5, 23.0],[ 55.4,23.2],[55.8,23.3],[55.5,23.0]]]]} ' ))
181182 ->first ();
182183
183184 $ this ->assertNotNull ($ testPlace );
@@ -187,11 +188,25 @@ public function it_filters_by_within(): void
187188 public function it_filters_by_contains (): void
188189 {
189190 TestPlace::factory ()->create ([
190- 'point ' => new Point (23.1 , 55.51 ),
191+ 'multi_polygon ' => MultiPolygon::fromJson ('{"type":"MultiPolygon","coordinates":[[[[55.5,23.0],[55.4,23.2],[55.8,23.3],[55.5,23.0]]]]} ' ),
192+ ]);
193+
194+ $ testPlace = TestPlace::query ()
195+ ->whereContains ('multi_polygon ' , new Point (23.1 , 55.5 ))
196+ ->first ();
197+
198+ $ this ->assertNotNull ($ testPlace );
199+ }
200+
201+ /** @test */
202+ public function it_filters_by_touches (): void
203+ {
204+ TestPlace::factory ()->create ([
205+ 'point ' => new Point (23.1 , 55.5 ),
191206 ]);
192207
193208 $ testPlace = TestPlace::query ()
194- ->whereContains ('point ' , MultiPolygon::fromJson ('{"type":"MultiPolygon","coordinates":[[[[55.5,23.1],[55.6,23.2],[55.7,23.3],[55.5,23.1]]]]} ' ))
209+ ->whereTouches ('point ' , MultiPolygon::fromJson ('{"type":"MultiPolygon","coordinates":[[[[55.5,23.1],[55.6,23.2],[55.7,23.3],[55.5,23.1]]]]} ' ))
195210 ->first ();
196211
197212 $ this ->assertNotNull ($ testPlace );
0 commit comments