|
7 | 7 | use MatanYadaev\EloquentSpatial\Enums\Srid;
|
8 | 8 | use MatanYadaev\EloquentSpatial\GeometryExpression;
|
9 | 9 | use MatanYadaev\EloquentSpatial\Objects\Geometry;
|
| 10 | +use MatanYadaev\EloquentSpatial\Objects\GeometryCollection; |
10 | 11 | use MatanYadaev\EloquentSpatial\Objects\LineString;
|
| 12 | +use MatanYadaev\EloquentSpatial\Objects\MultiLineString; |
| 13 | +use MatanYadaev\EloquentSpatial\Objects\MultiPoint; |
| 14 | +use MatanYadaev\EloquentSpatial\Objects\MultiPolygon; |
11 | 15 | use MatanYadaev\EloquentSpatial\Objects\Point;
|
| 16 | +use MatanYadaev\EloquentSpatial\Objects\Polygon; |
12 | 17 | use MatanYadaev\EloquentSpatial\Tests\TestModels\TestPlace;
|
13 | 18 |
|
14 | 19 | it('throws exception when generating geometry from other geometry WKB', function (): void {
|
|
135 | 140 | LineString::fromArray($pointGeoJsonArray);
|
136 | 141 | })->toThrow(InvalidArgumentException::class);
|
137 | 142 | });
|
| 143 | + |
| 144 | +it('creates a model record with geometry (point)', function (): void { |
| 145 | + // Arrange |
| 146 | + $point = Point::fromJson('{"type":"Point","coordinates":[0,180]}'); |
| 147 | + |
| 148 | + // Act |
| 149 | + /** @var TestPlace $testPlace */ |
| 150 | + $testPlace = TestPlace::factory()->create(['geometry' => $point]); |
| 151 | + |
| 152 | + // Assert |
| 153 | + expect($testPlace->geometry)->toBeInstanceOf(Point::class); |
| 154 | + expect($testPlace->geometry)->toEqual($point); |
| 155 | +}); |
| 156 | + |
| 157 | +it('creates a model record with geometry (line string)', function (): void { |
| 158 | + // Arrange |
| 159 | + $lineString = LineString::fromJson('{"type":"LineString","coordinates":[[180,0],[179,1]]}'); |
| 160 | + |
| 161 | + // Act |
| 162 | + /** @var TestPlace $testPlace */ |
| 163 | + $testPlace = TestPlace::factory()->create(['geometry' => $lineString]); |
| 164 | + |
| 165 | + // Assert |
| 166 | + expect($testPlace->geometry)->toBeInstanceOf(LineString::class); |
| 167 | + expect($testPlace->geometry)->toEqual($lineString); |
| 168 | +}); |
| 169 | + |
| 170 | +it('creates a model record with geometry (multi point)', function (): void { |
| 171 | + // Arrange |
| 172 | + $multiPoint = MultiPoint::fromJson('{"type":"MultiPoint","coordinates":[[180,0],[179,1]]}'); |
| 173 | + |
| 174 | + // Act |
| 175 | + /** @var TestPlace $testPlace */ |
| 176 | + $testPlace = TestPlace::factory()->create(['geometry' => $multiPoint]); |
| 177 | + |
| 178 | + // Assert |
| 179 | + expect($testPlace->geometry)->toBeInstanceOf(MultiPoint::class); |
| 180 | + expect($testPlace->geometry)->toEqual($multiPoint); |
| 181 | +}); |
| 182 | + |
| 183 | +it('creates a model record with geometry (multi line string)', function (): void { |
| 184 | + // Arrange |
| 185 | + $multiLineString = MultiLineString::fromJson('{"type":"MultiLineString","coordinates":[[[180,0],[179,1]]]}'); |
| 186 | + |
| 187 | + // Act |
| 188 | + /** @var TestPlace $testPlace */ |
| 189 | + $testPlace = TestPlace::factory()->create(['geometry' => $multiLineString]); |
| 190 | + |
| 191 | + // Assert |
| 192 | + expect($testPlace->geometry)->toBeInstanceOf(MultiLineString::class); |
| 193 | + expect($testPlace->geometry)->toEqual($multiLineString); |
| 194 | +}); |
| 195 | + |
| 196 | +it('creates a model record with geometry (polygon)', function (): void { |
| 197 | + // Arrange |
| 198 | + $polygon = Polygon::fromJson('{"type":"Polygon","coordinates":[[[180,0],[179,1],[180,1],[180,0]]]}'); |
| 199 | + |
| 200 | + // Act |
| 201 | + /** @var TestPlace $testPlace */ |
| 202 | + $testPlace = TestPlace::factory()->create(['geometry' => $polygon]); |
| 203 | + |
| 204 | + // Assert |
| 205 | + expect($testPlace->geometry)->toBeInstanceOf(Polygon::class); |
| 206 | + expect($testPlace->geometry)->toEqual($polygon); |
| 207 | +}); |
| 208 | + |
| 209 | +it('creates a model record with geometry (multi polygon)', function (): void { |
| 210 | + // Arrange |
| 211 | + $multiPolygon = MultiPolygon::fromJson('{"type":"MultiPolygon","coordinates":[[[[180,0],[179,1],[180,1],[180,0]]]]}'); |
| 212 | + |
| 213 | + // Act |
| 214 | + /** @var TestPlace $testPlace */ |
| 215 | + $testPlace = TestPlace::factory()->create(['geometry' => $multiPolygon]); |
| 216 | + |
| 217 | + // Assert |
| 218 | + expect($testPlace->geometry)->toBeInstanceOf(MultiPolygon::class); |
| 219 | + expect($testPlace->geometry)->toEqual($multiPolygon); |
| 220 | +}); |
| 221 | + |
| 222 | +it('creates a model record with geometry (geometry collection)', function (): void { |
| 223 | + // Arrange |
| 224 | + $geometryCollection = GeometryCollection::fromJson('{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[0,180]}]}'); |
| 225 | + |
| 226 | + // Act |
| 227 | + /** @var TestPlace $testPlace */ |
| 228 | + $testPlace = TestPlace::factory()->create(['geometry' => $geometryCollection]); |
| 229 | + |
| 230 | + // Assert |
| 231 | + expect($testPlace->geometry)->toBeInstanceOf(GeometryCollection::class); |
| 232 | + expect($testPlace->geometry)->toEqual($geometryCollection); |
| 233 | +}); |
0 commit comments