Skip to content

Commit f79770c

Browse files
committed
improve coverage; fixed wrong variable names
1 parent 7acabe7 commit f79770c

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

src/GeometryCast.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@ public function __construct(string $className)
2626
/**
2727
* @param Model $model
2828
* @param string $key
29-
* @param string|null $wkt
29+
* @param string|null $wkb
3030
* @param array<string, mixed> $attributes
3131
*
3232
* @return Geometry|null
3333
*/
34-
public function get($model, string $key, $wkt, array $attributes): ?Geometry
34+
public function get($model, string $key, $wkb, array $attributes): ?Geometry
3535
{
36-
if (! $wkt) {
36+
if (! $wkb) {
3737
return null;
3838
}
3939

40-
return $this->className::fromWkb($wkt);
40+
return $this->className::fromWkb($wkb);
4141
}
4242

4343
/**

src/Objects/GeometryCollection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,12 @@ protected function validateGeometriesType(): void
152152

153153
protected function toCollectionWkt(): Expression
154154
{
155-
$wkb = $this->geometries
155+
$wkt = $this->geometries
156156
->map(static function (Geometry $geometry): string {
157157
return (string) $geometry->toWkt();
158158
})
159159
->join(',');
160160

161-
return DB::raw($wkb);
161+
return DB::raw($wkt);
162162
}
163163
}

tests/GeometryTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
namespace MatanYadaev\EloquentSpatial\Tests;
44

55
use Illuminate\Foundation\Testing\DatabaseMigrations;
6+
use Illuminate\Support\Facades\DB;
67
use InvalidArgumentException;
78
use MatanYadaev\EloquentSpatial\Objects\Point;
9+
use MatanYadaev\EloquentSpatial\Tests\TestModels\TestPlace;
810

911
class GeometryTest extends TestCase
1012
{
@@ -18,6 +20,19 @@ public function it_throws_exception_when_generating_geometry_from_invalid_value(
1820
Point::fromJson('invalid-value');
1921
}
2022

23+
/** @test */
24+
public function it_throws_exception_when_generating_geometry_from_other_geometry_wkb(): void
25+
{
26+
$this->expectException(InvalidArgumentException::class);
27+
28+
TestPlace::insert([
29+
'point_with_line_string_cast' => DB::raw('POINT(0, 180)'),
30+
]);
31+
32+
TestPlace::firstOrFail()->getAttribute('point_with_line_string_cast');
33+
34+
}
35+
2136
/** @test */
2237
public function it_throws_exception_when_generating_geometry_from_invalid_geo_json(): void
2338
{

tests/TestModels/TestPlace.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* @property GeometryCollection $geometry_collection
2525
* @property float|null $distance
2626
* @property float|null $distance_in_meters
27+
* @mixin Model
2728
* @method static SpatialBuilder query()
2829
*/
2930
class TestPlace extends Model

0 commit comments

Comments
 (0)