|
14 | 14 | TestPlace::factory()->create(['point' => new Point(0, 0, Srid::WGS84->value)]);
|
15 | 15 |
|
16 | 16 | /** @var TestPlace $testPlaceWithDistance */
|
17 |
| - $testPlaceWithDistance = TestPlace::withDistance('point', new Point(1, 1, Srid::WGS84->value))->firstOrFail(); |
| 17 | + $testPlaceWithDistance = TestPlace::query()->select(['id'])->selectRaw(DB::raw('id as id_new')) |
| 18 | + ->withDistance('point', new Point(1, 1, Srid::WGS84->value)) |
| 19 | + ->firstOrFail(); |
18 | 20 |
|
19 |
| - expect($testPlaceWithDistance->distance)->toBe(156897.79947260793); |
| 21 | + expect($testPlaceWithDistance->distance)->toBe(156897.79947260793) |
| 22 | + ->and($testPlaceWithDistance->id)->toBe(1) |
| 23 | + ->and($testPlaceWithDistance->id_new)->toBe(1); |
20 | 24 | })->skip(fn () => ! isSupportAxisOrder());
|
21 | 25 |
|
22 | 26 | it('calculates distance - without axis-order', function (): void {
|
23 | 27 | TestPlace::factory()->create(['point' => new Point(0, 0, Srid::WGS84->value)]);
|
24 | 28 |
|
25 | 29 | /** @var TestPlace $testPlaceWithDistance */
|
26 |
| - $testPlaceWithDistance = TestPlace::withDistance('point', new Point(1, 1, Srid::WGS84->value)) |
27 |
| - ->firstOrFail(); |
| 30 | + $testPlaceWithDistance = TestPlace::withDistance('point', new Point(1, 1, Srid::WGS84->value))->firstOrFail(); |
28 | 31 |
|
29 | 32 | expect($testPlaceWithDistance->distance)->toBe(1.4142135623730951);
|
30 |
| -})->skip(fn () => isSupportAxisOrder()); |
| 33 | +})->skip(fn() => isSupportAxisOrder()); |
31 | 34 |
|
32 | 35 | it('calculates distance with alias', function (): void {
|
33 | 36 | TestPlace::factory()->create(['point' => new Point(0, 0, Srid::WGS84->value)]);
|
|
37 | 40 | ->firstOrFail();
|
38 | 41 |
|
39 | 42 | expect($testPlaceWithDistance->distance_in_meters)->toBe(156897.79947260793);
|
40 |
| -})->skip(fn () => ! isSupportAxisOrder()); |
| 43 | +})->skip(fn() => !isSupportAxisOrder()); |
41 | 44 |
|
42 | 45 | it('calculates distance with alias - without axis-order', function (): void {
|
43 | 46 | TestPlace::factory()->create(['point' => new Point(0, 0, Srid::WGS84->value)]);
|
|
47 | 50 | ->firstOrFail();
|
48 | 51 |
|
49 | 52 | expect($testPlaceWithDistance->distance_in_meters)->toBe(1.4142135623730951);
|
50 |
| -})->skip(fn () => isSupportAxisOrder()); |
| 53 | +})->skip(fn() => isSupportAxisOrder()); |
51 | 54 |
|
52 | 55 | it('filters by distance', function (): void {
|
53 | 56 | $pointWithinDistance = new Point(0, 0, Srid::WGS84->value);
|
|
61 | 64 |
|
62 | 65 | expect($testPlacesWithinDistance)->toHaveCount(1)
|
63 | 66 | ->and($testPlacesWithinDistance[0]->point)->toEqual($pointWithinDistance);
|
64 |
| -})->skip(fn () => ! isSupportAxisOrder()); |
| 67 | +})->skip(fn() => !isSupportAxisOrder()); |
65 | 68 |
|
66 | 69 | it('filters by distance - without axis-order', function (): void {
|
67 | 70 | $pointWithinDistance = new Point(0, 0, Srid::WGS84->value);
|
|
74 | 77 |
|
75 | 78 | expect($testPlacesWithinDistance)->toHaveCount(1)
|
76 | 79 | ->and($testPlacesWithinDistance[0]->point)->toEqual($pointWithinDistance);
|
77 |
| -})->skip(fn () => isSupportAxisOrder()); |
| 80 | +})->skip(fn() => isSupportAxisOrder()); |
78 | 81 |
|
79 | 82 | it('orders by distance ASC', function (): void {
|
80 | 83 | $closerTestPlace = TestPlace::factory()->create(['point' => new Point(1, 1, Srid::WGS84->value)]);
|
|
107 | 110 |
|
108 | 111 | expect($testPlaceWithDistance->distance)->toBe(157249.59776850493)
|
109 | 112 | ->and($testPlaceWithDistance->name)->not()->toBeNull();
|
110 |
| -})->skip(fn () => ! isSupportAxisOrder()); |
| 113 | +})->skip(fn() => !isSupportAxisOrder()); |
111 | 114 |
|
112 | 115 | it('calculates distance sphere - without axis-order', function (): void {
|
113 | 116 | TestPlace::factory()->create(['point' => new Point(0, 0, Srid::WGS84->value)]);
|
|
117 | 120 |
|
118 | 121 | expect($testPlaceWithDistance->distance)->toBe(157249.0357231545)
|
119 | 122 | ->and($testPlaceWithDistance->name)->not()->toBeNull();
|
120 |
| -})->skip(fn () => isSupportAxisOrder()); |
| 123 | +})->skip(fn() => isSupportAxisOrder()); |
121 | 124 |
|
122 | 125 | it('calculates distance sphere with alias', function (): void {
|
123 | 126 | TestPlace::factory()->create(['point' => new Point(0, 0, Srid::WGS84->value)]);
|
|
127 | 130 | $testPlaceWithDistance = TestPlace::withDistanceSphere('point', $point, 'distance_in_meters')->firstOrFail();
|
128 | 131 |
|
129 | 132 | expect($testPlaceWithDistance->distance_in_meters)->toBe(157249.59776850493);
|
130 |
| -})->skip(fn () => ! isSupportAxisOrder()); |
| 133 | +})->skip(fn() => !isSupportAxisOrder()); |
131 | 134 |
|
132 | 135 | it('calculates distance sphere with alias - without axis-order', function (): void {
|
133 | 136 | TestPlace::factory()->create(['point' => new Point(0, 0, Srid::WGS84->value)]);
|
|
137 | 140 | $testPlaceWithDistance = TestPlace::withDistanceSphere('point', $point, 'distance_in_meters')->firstOrFail();
|
138 | 141 |
|
139 | 142 | expect($testPlaceWithDistance->distance_in_meters)->toBe(157249.0357231545);
|
140 |
| -})->skip(fn () => isSupportAxisOrder()); |
| 143 | +})->skip(fn() => isSupportAxisOrder()); |
141 | 144 |
|
142 | 145 | it('filters distance sphere', function (): void {
|
143 | 146 | $pointWithinDistance = new Point(0, 0, Srid::WGS84->value);
|
|
395 | 398 |
|
396 | 399 | $result = $method->invoke($model, $model->newQuery(), $polygon);
|
397 | 400 |
|
398 |
| - $grammar = $model->newQuery()->getGrammar(); |
399 | 401 | $connection = $model->newQuery()->getConnection();
|
400 |
| - $sqlSerializedPolygon = $polygon->toSqlExpression($connection)->getValue($grammar); |
| 402 | + $sqlSerializedPolygon = $polygon->toSqlExpression($connection)->getValue(); |
401 | 403 | expect($result)->toBe($sqlSerializedPolygon);
|
402 | 404 | });
|
403 | 405 |
|
|
0 commit comments