|
21 | 21 | use Tests\Tempest\Integration\Mapper\Fixtures\ObjectWithMapToAttribute; |
22 | 22 | use Tests\Tempest\Integration\Mapper\Fixtures\ObjectWithMapToCollisions; |
23 | 23 | use Tests\Tempest\Integration\Mapper\Fixtures\ObjectWithMapToCollisionsJsonSerializable; |
| 24 | +use Tests\Tempest\Integration\Mapper\Fixtures\ObjectWithMultipleMapFrom; |
24 | 25 | use Tests\Tempest\Integration\Mapper\Fixtures\ObjectWithStrictOnClass; |
25 | 26 | use Tests\Tempest\Integration\Mapper\Fixtures\ObjectWithStrictProperty; |
26 | 27 | use Tests\Tempest\Integration\Mapper\Fixtures\Person; |
@@ -258,4 +259,33 @@ enum: EnumToCast::FOO, |
258 | 259 | ], |
259 | 260 | ); |
260 | 261 | } |
| 262 | + |
| 263 | + public function test_multiple_map_from_source(): void |
| 264 | + { |
| 265 | + $object = map(['name' => 'Guillaume'])->to(ObjectWithMultipleMapFrom::class); |
| 266 | + $this->assertSame('Guillaume', $object->fullName); |
| 267 | + |
| 268 | + $object = map(['first_name' => 'Guillaume'])->to(ObjectWithMultipleMapFrom::class); |
| 269 | + $this->assertSame('Guillaume', $object->fullName); |
| 270 | + } |
| 271 | + |
| 272 | + public function test_multiple_map_from_take_first_occurence(): void |
| 273 | + { |
| 274 | + $data = [ |
| 275 | + 'name' => 'Guillaume', |
| 276 | + 'first_name' => 'John', |
| 277 | + ]; |
| 278 | + |
| 279 | + $object = map($data)->to(ObjectWithMultipleMapFrom::class); |
| 280 | + $this->assertSame('Guillaume', $object->fullName); |
| 281 | + } |
| 282 | + |
| 283 | + public function test_multiple_map_from_fallback_to_property_name(): void |
| 284 | + { |
| 285 | + $object = map([ |
| 286 | + 'fullName' => 'Guillaume', |
| 287 | + ])->to(ObjectWithMapFromAttribute::class); |
| 288 | + |
| 289 | + $this->assertSame('Guillaume', $object->fullName); |
| 290 | + } |
261 | 291 | } |
0 commit comments