|
10 | 10 |
|
11 | 11 | uses(DatabaseMigrations::class); |
12 | 12 |
|
13 | | -it('calculates distance between column and column', function (): void { |
14 | | - TestPlace::factory()->create(['point' => new Point(0, 0, 4326)]); |
15 | | - |
16 | | - /** @var TestPlace $testPlaceWithDistance */ |
17 | | - $testPlaceWithDistance = TestPlace::query() |
18 | | - ->withDistance('point', 'point') |
19 | | - ->firstOrFail(); |
20 | | - |
21 | | - expect($testPlaceWithDistance->distance)->toBe(0.0); |
22 | | -}); |
23 | | - |
24 | | -it('calculates distance between column and geometry', function (): void { |
| 13 | +it('calculates distance', function (): void { |
25 | 14 | TestPlace::factory()->create(['point' => new Point(0, 0, 4326)]); |
26 | 15 |
|
27 | 16 | /** @var TestPlace $testPlaceWithDistance */ |
|
32 | 21 | expect($testPlaceWithDistance->distance)->toBe(156897.79947260793); |
33 | 22 | })->skip(fn () => ! (new AxisOrder)->supported(DB::connection())); |
34 | 23 |
|
35 | | -it('calculates distance between column and geometry - without axis-order', function (): void { |
| 24 | +it('calculates distance - without axis-order', function (): void { |
36 | 25 | TestPlace::factory()->create(['point' => new Point(0, 0, 4326)]); |
37 | 26 |
|
38 | 27 | /** @var TestPlace $testPlaceWithDistance */ |
|
121 | 110 | expect($testPlacesOrderedByDistance[0]->id)->toBe($fartherTestPlace->id); |
122 | 111 | }); |
123 | 112 |
|
124 | | -it('calculates distance sphere column and column', function (): void { |
125 | | - TestPlace::factory()->create(['point' => new Point(0, 0, 4326)]); |
126 | | - |
127 | | - /** @var TestPlace $testPlaceWithDistance */ |
128 | | - $testPlaceWithDistance = TestPlace::query() |
129 | | - ->withDistanceSphere('point', 'point') |
130 | | - ->firstOrFail(); |
131 | | - |
132 | | - expect($testPlaceWithDistance->distance)->toBe(0.0); |
133 | | -}); |
134 | | - |
135 | | -it('calculates distance sphere column and geometry', function (): void { |
| 113 | +it('calculates distance sphere', function (): void { |
136 | 114 | TestPlace::factory()->create(['point' => new Point(0, 0, 4326)]); |
137 | 115 |
|
138 | 116 | /** @var TestPlace $testPlaceWithDistance */ |
|
143 | 121 | expect($testPlaceWithDistance->distance)->toBe(157249.59776850493); |
144 | 122 | })->skip(fn () =>! (new AxisOrder)->supported(DB::connection())); |
145 | 123 |
|
146 | | -it('calculates distance sphere column and geometry - without axis-order', function (): void { |
| 124 | +it('calculates distance sphere - without axis-order', function (): void { |
147 | 125 | TestPlace::factory()->create(['point' => new Point(0, 0, 4326)]); |
148 | 126 |
|
149 | 127 | /** @var TestPlace $testPlaceWithDistance */ |
|
393 | 371 | expect($testPlaces[0]->point)->toEqual($point1); |
394 | 372 | }); |
395 | 373 |
|
396 | | -it('uses spatial function on column that contains its table name', function (): void { |
| 374 | +it('uses spatial function with column', function (): void { |
| 375 | + TestPlace::factory()->create(['point' => new Point(0, 0, 4326)]); |
| 376 | + |
| 377 | + /** @var TestPlace $testPlaceWithDistance */ |
| 378 | + $testPlaceWithDistance = TestPlace::query() |
| 379 | + ->withDistance('point', 'point') |
| 380 | + ->firstOrFail(); |
| 381 | + |
| 382 | + expect($testPlaceWithDistance->distance)->toBe(0.0); |
| 383 | +}); |
| 384 | + |
| 385 | +it('uses spatial function with column that contains table name', function (): void { |
397 | 386 | TestPlace::factory()->create(['point' => new Point(0, 0, 4326)]); |
398 | 387 |
|
399 | 388 | /** @var TestPlace $testPlaceWithDistance */ |
|
404 | 393 | expect($testPlaceWithDistance->distance)->toBe(0.0); |
405 | 394 | }); |
406 | 395 |
|
407 | | -it('uses spatial function on raw expression', function (): void { |
| 396 | +it('uses spatial function with expression', function (): void { |
408 | 397 | $polygon = Polygon::fromJson('{"type":"Polygon","coordinates":[[[-1,-1],[1,-1],[1,1],[-1,1],[-1,-1]]]}'); |
409 | 398 | TestPlace::factory()->create([ |
| 399 | + 'polygon' => $polygon, |
410 | 400 | 'longitude' => 0, |
411 | 401 | 'latitude' => 0, |
412 | | - 'polygon' => $polygon, |
413 | 402 | ]); |
414 | 403 |
|
415 | 404 | /** @var TestPlace $testPlaceWithDistance */ |
416 | 405 | $testPlaceWithDistance = TestPlace::query() |
417 | | - ->whereWithin(DB::raw('POINT(longitude, latitude)'), 'polygon') |
| 406 | + ->whereWithin(DB::raw('POINT(longitude, latitude)'), DB::raw('polygon')) |
418 | 407 | ->firstOrFail(); |
419 | 408 |
|
420 | 409 | expect($testPlaceWithDistance)->not()->toBeNull(); |
421 | 410 | }); |
422 | 411 |
|
423 | | -it('toExpressionString can handle Expression', function (): void { |
| 412 | +it('toExpressionString can handle a Expression input', function (): void { |
424 | 413 | $spatialBuilder = TestPlace::query(); |
425 | 414 | $toExpressionStringMethod = (new ReflectionClass($spatialBuilder))->getMethod('toExpressionString'); |
426 | 415 |
|
|
429 | 418 | expect($result)->toBe('POINT(longitude, latitude)'); |
430 | 419 | }); |
431 | 420 |
|
432 | | -it('toExpressionString can handle Geometry', function (): void { |
433 | | - $polygon = Polygon::fromJson('{"type":"Polygon","coordinates":[[[-1,-1],[1,-1],[1,1],[-1,1],[-1,-1]]]}'); |
434 | | - |
| 421 | +it('toExpressionString can handle a Geometry input', function (): void { |
435 | 422 | $spatialBuilder = TestPlace::query(); |
436 | | - $grammar = $spatialBuilder->getQuery()->getGrammar(); |
437 | 423 | $toExpressionStringMethod = (new ReflectionClass($spatialBuilder))->getMethod('toExpressionString'); |
| 424 | + $polygon = Polygon::fromJson('{"type":"Polygon","coordinates":[[[-1,-1],[1,-1],[1,1],[-1,1],[-1,-1]]]}'); |
438 | 425 |
|
439 | 426 | $result = $toExpressionStringMethod->invoke($spatialBuilder, $polygon); |
440 | 427 |
|
441 | | - $sqlSerializedPolygon = $polygon->toSqlExpression($spatialBuilder->getConnection())->getValue($grammar); |
442 | | - |
| 428 | + $grammar = $spatialBuilder->getGrammar(); |
| 429 | + $connection = $spatialBuilder->getConnection(); |
| 430 | + $sqlSerializedPolygon = $polygon->toSqlExpression($connection)->getValue($grammar); |
443 | 431 | expect($result)->toBe($sqlSerializedPolygon); |
444 | 432 | }); |
445 | 433 |
|
446 | | -it('toExpressionString can handle string', function (): void { |
| 434 | +it('toExpressionString can handle a string input', function (): void { |
447 | 435 | $spatialBuilder = TestPlace::query(); |
448 | 436 | $toExpressionStringMethod = (new ReflectionClass($spatialBuilder))->getMethod('toExpressionString'); |
449 | 437 |
|
|
0 commit comments