Skip to content

Commit f4f7f90

Browse files
authored
Bugfix: Model spatial column update using Expression v2 branch (#86)
1 parent 5c7a8b6 commit f4f7f90

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
@@ -65,6 +65,10 @@ public function set($model, string $key, $value, array $attributes): Expression|
6565
$value = Geometry::fromArray($value);
6666
}
6767

68+
if ($value instanceof Expression) {
69+
return $value;
70+
}
71+
6872
if (! ($value instanceof $this->className)) {
6973
$geometryType = is_object($value) ? $value::class : gettype($value);
7074
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)