Skip to content

Commit eec4775

Browse files
MatanYadaevMatan Yadaev
andauthored
Bugfix: Model spatial column update using Expression (#81)
* add test * Fix --------- Co-authored-by: Matan Yadaev <[email protected]>
1 parent 30b6cff commit eec4775

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/GeometryCast.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ public function set($model, string $key, $value, array $attributes): ExpressionC
6666
$value = Geometry::fromArray($value);
6767
}
6868

69+
if ($value instanceof ExpressionContract) {
70+
return $value;
71+
}
72+
6973
if (! ($value instanceof $this->className)) {
7074
$geometryType = is_object($value) ? $value::class : gettype($value);
7175
throw new InvalidArgumentException(

tests/GeometryCastTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@
2727
expect($testPlace->point)->toEqual($point2);
2828
});
2929

30+
it('updates a model record with expression', function (): void {
31+
$point = new Point(0, 180);
32+
/** @var TestPlace $testPlace */
33+
$testPlace = TestPlace::factory()->create(['point' => $point]);
34+
$pointFromAttributes = $testPlace->getAttributes()['point'];
35+
36+
expect(function () use ($testPlace, $pointFromAttributes): void {
37+
$testPlace->update(['point' => $pointFromAttributes]);
38+
})->not->toThrow(InvalidArgumentException::class);
39+
expect(true)->toBeTrue(); // because of Pest's bug: https://github.com/pestphp/pest/issues/657
40+
});
41+
3042
it('updates a model record with null geometry', function (): void {
3143
$point = new Point(0, 180);
3244
/** @var TestPlace $testPlace */

0 commit comments

Comments
 (0)