|
1 | 1 | <?php
|
2 | 2 |
|
3 | 3 | use Illuminate\Foundation\Testing\DatabaseMigrations;
|
| 4 | +use Illuminate\Support\Facades\DB; |
4 | 5 | use MatanYadaev\EloquentSpatial\Objects\LineString;
|
5 | 6 | use MatanYadaev\EloquentSpatial\Objects\Point;
|
6 | 7 | use MatanYadaev\EloquentSpatial\Objects\Polygon;
|
|
28 | 29 | ->firstOrFail();
|
29 | 30 |
|
30 | 31 | expect($testPlaceWithDistance->distance)->toBe(156897.79947260793);
|
31 |
| -}); |
| 32 | +})->skip(fn () => DB::isMaria()); |
| 33 | + |
| 34 | +it('calculates distance between column and geometry - MariaDB', function (): void { |
| 35 | + TestPlace::factory()->create(['point' => new Point(0, 0, 4326)]); |
| 36 | + |
| 37 | + /** @var TestPlace $testPlaceWithDistance */ |
| 38 | + $testPlaceWithDistance = TestPlace::query() |
| 39 | + ->withDistance('point', new Point(1, 1, 4326)) |
| 40 | + ->firstOrFail(); |
| 41 | + |
| 42 | + expect($testPlaceWithDistance->distance)->toBe(1.4142135623730951); |
| 43 | +})->skip(fn () => ! DB::isMaria()); |
32 | 44 |
|
33 | 45 | it('calculates distance with alias', function (): void {
|
34 | 46 | TestPlace::factory()->create(['point' => new Point(0, 0, 4326)]);
|
|
39 | 51 | ->firstOrFail();
|
40 | 52 |
|
41 | 53 | expect($testPlaceWithDistance->distance_in_meters)->toBe(156897.79947260793);
|
42 |
| -}); |
| 54 | +})->skip(fn () => DB::isMaria()); |
| 55 | + |
| 56 | +it('calculates distance with alias - MariaDB', function (): void { |
| 57 | + TestPlace::factory()->create(['point' => new Point(0, 0, 4326)]); |
| 58 | + |
| 59 | + /** @var TestPlace $testPlaceWithDistance */ |
| 60 | + $testPlaceWithDistance = TestPlace::query() |
| 61 | + ->withDistance('point', new Point(1, 1, 4326), 'distance_in_meters') |
| 62 | + ->firstOrFail(); |
| 63 | + |
| 64 | + expect($testPlaceWithDistance->distance_in_meters)->toBe(1.4142135623730951); |
| 65 | +})->skip(fn () => ! DB::isMaria()); |
43 | 66 |
|
44 | 67 | it('filters by distance', function (): void {
|
45 | 68 | $pointWithinDistance = new Point(0, 0, 4326);
|
|
54 | 77 |
|
55 | 78 | expect($testPlacesWithinDistance)->toHaveCount(1);
|
56 | 79 | expect($testPlacesWithinDistance[0]->point)->toEqual($pointWithinDistance);
|
57 |
| -}); |
| 80 | +})->skip(fn () => DB::isMaria()); |
| 81 | + |
| 82 | +it('filters by distance - MariaDB', function (): void { |
| 83 | + $pointWithinDistance = new Point(0, 0, 4326); |
| 84 | + $pointNotWithinDistance = new Point(50, 50, 4326); |
| 85 | + TestPlace::factory()->create(['point' => $pointWithinDistance]); |
| 86 | + TestPlace::factory()->create(['point' => $pointNotWithinDistance]); |
| 87 | + |
| 88 | + /** @var TestPlace[] $testPlacesWithinDistance */ |
| 89 | + $testPlacesWithinDistance = TestPlace::query() |
| 90 | + ->whereDistance('point', new Point(1, 1, 4326), '<', 2) |
| 91 | + ->get(); |
| 92 | + |
| 93 | + expect($testPlacesWithinDistance)->toHaveCount(1); |
| 94 | + expect($testPlacesWithinDistance[0]->point)->toEqual($pointWithinDistance); |
| 95 | +})->skip(fn () => ! DB::isMaria()); |
58 | 96 |
|
59 | 97 | it('orders by distance ASC', function (): void {
|
60 | 98 | $closerTestPlace = TestPlace::factory()->create(['point' => new Point(1, 1, 4326)]);
|
|
102 | 140 | ->firstOrFail();
|
103 | 141 |
|
104 | 142 | expect($testPlaceWithDistance->distance)->toBe(157249.59776850493);
|
105 |
| -}); |
| 143 | +})->skip(fn () => DB::isMaria()); |
| 144 | + |
| 145 | +it('calculates distance sphere column and geometry - MariaDB', function (): void { |
| 146 | + TestPlace::factory()->create(['point' => new Point(0, 0, 4326)]); |
| 147 | + |
| 148 | + /** @var TestPlace $testPlaceWithDistance */ |
| 149 | + $testPlaceWithDistance = TestPlace::query() |
| 150 | + ->withDistanceSphere('point', new Point(1, 1, 4326)) |
| 151 | + ->firstOrFail(); |
| 152 | + |
| 153 | + expect($testPlaceWithDistance->distance)->toBe(157249.0357231545); |
| 154 | +})->skip(fn () => ! DB::isMaria()); |
106 | 155 |
|
107 | 156 | it('calculates distance sphere with alias', function (): void {
|
108 | 157 | TestPlace::factory()->create(['point' => new Point(0, 0, 4326)]);
|
|
113 | 162 | ->firstOrFail();
|
114 | 163 |
|
115 | 164 | expect($testPlaceWithDistance->distance_in_meters)->toBe(157249.59776850493);
|
116 |
| -}); |
| 165 | +})->skip(fn () => DB::isMaria()); |
| 166 | + |
| 167 | +it('calculates distance sphere with alias - MariaDB', function (): void { |
| 168 | + TestPlace::factory()->create(['point' => new Point(0, 0, 4326)]); |
| 169 | + |
| 170 | + /** @var TestPlace $testPlaceWithDistance */ |
| 171 | + $testPlaceWithDistance = TestPlace::query() |
| 172 | + ->withDistanceSphere('point', new Point(1, 1, 4326), 'distance_in_meters') |
| 173 | + ->firstOrFail(); |
| 174 | + |
| 175 | + expect($testPlaceWithDistance->distance_in_meters)->toBe(157249.0357231545); |
| 176 | +})->skip(fn () => ! DB::isMaria()); |
117 | 177 |
|
118 | 178 | it('filters distance sphere', function (): void {
|
119 | 179 | $pointWithinDistance = new Point(0, 0, 4326);
|
|
0 commit comments