|
111 | 111 | ]));
|
112 | 112 |
|
113 | 113 | expect(function (): void {
|
114 |
| - // cast deserialization happens in setRawAttributes |
115 |
| - // called immediately after retrieving db record |
116 | 114 | TestPlace::firstOrFail();
|
117 | 115 | })->toThrow(InvalidArgumentException::class);
|
118 | 116 | });
|
|
127 | 125 | expect($testPlace->point)->toEqual($point);
|
128 | 126 | });
|
129 | 127 |
|
130 |
| -it('is serializeable and JSON encodeable by standard serialize / JSON encode functions', function (): void { |
| 128 | +it('serializes and json encodes a model record with geometry', function (): void { |
| 129 | + // Arrange |
131 | 130 | $point = new Point(0, 180);
|
132 |
| - |
133 | 131 | /** @var TestPlace $testPlace */
|
134 | 132 | $testPlace = TestPlace::factory()->make(['point' => $point]);
|
135 | 133 |
|
136 |
| - $serialized = serialize($testPlace); |
137 |
| - $json = json_encode($serialized); |
138 |
| - |
139 |
| - expect($json)->toBeTruthy('JSON encoding failed.'); |
140 |
| - |
| 134 | + // Act |
141 | 135 | // @phpstan-ignore-next-line
|
142 |
| - $recoveredTestPlace = unserialize(json_decode($json)); |
| 136 | + $recoveredTestPlace = unserialize(json_decode(json_encode(serialize($testPlace)))); |
143 | 137 |
|
| 138 | + // Assert |
144 | 139 | expect($recoveredTestPlace)->toEqual($testPlace);
|
145 | 140 | });
|
146 | 141 |
|
147 |
| -it('is serializeable and JSON encodeable by standard serialize / JSON encode functions when retrieved from db', function (): void { |
| 142 | +it('serializes and json encodes a model record with geometry when retrieving from database', function (): void { |
| 143 | + // Arrange |
148 | 144 | $point = new Point(0, 180);
|
149 |
| - |
150 | 145 | /** @var TestPlace $testPlace */
|
151 |
| - $testPlace = TestPlace::factory()->make(['point' => $point]); |
152 |
| - |
153 |
| - $testPlace->save(); |
154 |
| - |
| 146 | + $testPlace = TestPlace::factory()->create(['point' => $point]); |
155 | 147 | $testPlaceFromDb = TestPlace::find($testPlace->id);
|
156 | 148 |
|
157 |
| - $serialized = serialize($testPlaceFromDb); |
158 |
| - $json = json_encode($serialized); |
159 |
| - |
160 |
| - expect($json)->toBeTruthy('JSON encoding failed.'); |
161 |
| - |
| 149 | + // Act |
162 | 150 | // @phpstan-ignore-next-line
|
163 |
| - $recoveredTestPlace = unserialize(json_decode($json)); |
| 151 | + $recoveredTestPlace = unserialize(json_decode(json_encode(serialize($testPlaceFromDb)))); |
164 | 152 |
|
| 153 | + // Assert |
165 | 154 | expect($recoveredTestPlace)->toEqual($testPlaceFromDb);
|
166 | 155 | });
|
0 commit comments