Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/GeometryCast.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ public function set($model, string $key, $value, array $attributes): Expression|
$value = Geometry::fromArray($value);
}

if ($value instanceof Expression) {
return $value;
}

if (! ($value instanceof $this->className)) {
$geometryType = is_object($value) ? $value::class : gettype($value);
throw new InvalidArgumentException(
Expand Down
12 changes: 12 additions & 0 deletions tests/GeometryCastTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@
expect($testPlace->point)->toEqual($point2);
});

it('updates a model record with expression', function (): void {
$point = new Point(0, 180);
/** @var TestPlace $testPlace */
$testPlace = TestPlace::factory()->create(['point' => $point]);
$pointFromAttributes = $testPlace->getAttributes()['point'];

expect(function () use ($testPlace, $pointFromAttributes): void {
$testPlace->update(['point' => $pointFromAttributes]);
})->not->toThrow(InvalidArgumentException::class);
expect(true)->toBeTrue(); // because of Pest's bug: https://github.com/pestphp/pest/issues/657
});

it('updates a model record with null geometry', function (): void {
$point = new Point(0, 180);
/** @var TestPlace $testPlace */
Expand Down