Skip to content

Commit 1dc6ce6

Browse files
committed
Revert setRawAttributes override
1 parent a132345 commit 1dc6ce6

File tree

2 files changed

+4
-56
lines changed

2 files changed

+4
-56
lines changed

src/Traits/HasSpatial.php

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace MatanYadaev\EloquentSpatial\Traits;
44

5-
use MatanYadaev\EloquentSpatial\Objects\Geometry;
65
use MatanYadaev\EloquentSpatial\SpatialBuilder;
76

87
trait HasSpatial
@@ -11,28 +10,4 @@ public function newEloquentBuilder($query): SpatialBuilder
1110
{
1211
return new SpatialBuilder($query);
1312
}
14-
15-
/**
16-
* @param array<string, mixed> $attributes
17-
* @param bool $sync
18-
* @return $this
19-
*/
20-
public function setRawAttributes(array $attributes, $sync = false)
21-
{
22-
$result = parent::setRawAttributes($attributes, $sync);
23-
24-
foreach ($attributes as $attribute => $value) {
25-
$casts = $this->getCasts();
26-
if (isset($casts[$attribute]) && is_subclass_of($casts[$attribute], Geometry::class)) {
27-
$spatialAttribute = $this->getAttribute($attribute);
28-
29-
if ($spatialAttribute instanceof Geometry) {
30-
$this->attributes[$attribute] = $spatialAttribute;
31-
$this->original[$attribute] = $spatialAttribute;
32-
}
33-
}
34-
}
35-
36-
return $result;
37-
}
3813
}

tests/GeometryCastTest.php

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,11 @@
109109
TestPlace::insert(array_merge(TestPlace::factory()->definition(), [
110110
'point_with_line_string_cast' => DB::raw('POINT(0, 180)'),
111111
]));
112+
/** @var TestPlace $testPlace */
113+
$testPlace = TestPlace::firstOrFail();
112114

113-
expect(function (): void {
114-
TestPlace::firstOrFail();
115+
expect(function () use ($testPlace): void {
116+
$testPlace->getAttribute('point_with_line_string_cast');
115117
})->toThrow(InvalidArgumentException::class);
116118
});
117119

@@ -124,32 +126,3 @@
124126

125127
expect($testPlace->point)->toEqual($point);
126128
});
127-
128-
it('serializes and json encodes a model record with geometry', function (): void {
129-
// Arrange
130-
$point = new Point(0, 180);
131-
/** @var TestPlace $testPlace */
132-
$testPlace = TestPlace::factory()->make(['point' => $point]);
133-
134-
// Act
135-
// @phpstan-ignore-next-line
136-
$recoveredTestPlace = unserialize(json_decode(json_encode(serialize($testPlace))));
137-
138-
// Assert
139-
expect($recoveredTestPlace)->toEqual($testPlace);
140-
});
141-
142-
it('serializes and json encodes a model record with geometry when retrieving from database', function (): void {
143-
// Arrange
144-
$point = new Point(0, 180);
145-
/** @var TestPlace $testPlace */
146-
$testPlace = TestPlace::factory()->create(['point' => $point]);
147-
$testPlaceFromDb = TestPlace::find($testPlace->id);
148-
149-
// Act
150-
// @phpstan-ignore-next-line
151-
$recoveredTestPlace = unserialize(json_decode(json_encode(serialize($testPlaceFromDb))));
152-
153-
// Assert
154-
expect($recoveredTestPlace)->toEqual($testPlaceFromDb);
155-
});

0 commit comments

Comments
 (0)