Skip to content

Commit cb73355

Browse files
authored
Merge pull request #309 from jolicode/fix/source-propery-type
fix(type): fix setting source property type, add test
2 parents ec68048 + 6452baa commit cb73355

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

src/Metadata/SourcePropertyMetadata.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public static function fromEvent(SourcePropertyMetadataEvent $metadata): self
3838
$metadata->checkExists ?? false,
3939
$metadata->groups,
4040
$metadata->dateTimeFormat ?? \DateTimeInterface::RFC3339,
41+
$metadata->type
4142
);
4243
}
4344

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
AutoMapper\Tests\AutoMapperTest\ArraySourcePropertyType\Dto {
2+
+age: [
3+
10.0
4+
]
5+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace AutoMapper\Tests\AutoMapperTest\ArraySourcePropertyType;
6+
7+
use AutoMapper\Attribute\MapFrom;
8+
use AutoMapper\Tests\AutoMapperBuilder;
9+
10+
class Dto
11+
{
12+
/** @var array<float> */
13+
#[MapFrom(source: 'array', sourcePropertyType: 'array<string>')]
14+
public array $age;
15+
}
16+
17+
return (function () {
18+
$autoMapper = AutoMapperBuilder::buildAutoMapper();
19+
20+
yield $autoMapper->map(['age' => ['10']], Dto::class);
21+
})();

0 commit comments

Comments
 (0)