Skip to content

Commit e8fbae4

Browse files
committed
fix mapping array of enums to setter which expects array of enums
1 parent 26f9739 commit e8fbae4

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

src/Extractor/WriteMutator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public function getTypes(string $target): ?array
161161
$reflectionMethod->getDocComment(),
162162
$target,
163163
$reflectionMethod->getDeclaringClass()->getName(),
164-
$this->property,
164+
$reflectionMethod->getParameters()[0]->name,
165165
'@param'
166166
)) {
167167
return $types;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
AutoMapper\Tests\AutoMapperTest\Issue269\Entity {
2+
-paymentMethods: [
3+
AutoMapper\Tests\AutoMapperTest\Issue269\PaymentMethod {
4+
+name: "First"
5+
+value: "First"
6+
}
7+
]
8+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace AutoMapper\Tests\AutoMapperTest\Issue269;
6+
7+
use AutoMapper\Tests\AutoMapperBuilder;
8+
9+
enum PaymentMethod: string
10+
{
11+
case First = 'First';
12+
}
13+
14+
class Dto
15+
{
16+
/** @var PaymentMethod[] */
17+
public ?array $paymentMethods = null;
18+
}
19+
20+
class Entity
21+
{
22+
/** @var PaymentMethod[] */
23+
private array $paymentMethods = [];
24+
25+
/** @param PaymentMethod[] $paymentMethods */
26+
public function setPaymentMethods(array $paymentMethods): self
27+
{
28+
$this->paymentMethods = $paymentMethods;
29+
30+
return $this;
31+
}
32+
33+
/** @return PaymentMethod[] */
34+
public function getPaymentMethods(): array
35+
{
36+
return $this->paymentMethods;
37+
}
38+
}
39+
40+
$dto = new Dto();
41+
$dto->paymentMethods = [PaymentMethod::First];
42+
43+
return AutoMapperBuilder::buildAutoMapper()->map($dto, Entity::class);

0 commit comments

Comments
 (0)