Skip to content

fix mapping array of enums to setter which expects array of enums #280

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Extractor/WriteMutator.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public function getTypes(string $target): ?array
$reflectionMethod->getDocComment(),
$target,
$reflectionMethod->getDeclaringClass()->getName(),
$this->property,
$reflectionMethod->getParameters()[0]->name,
'@param'
)) {
return $types;
Expand Down
8 changes: 8 additions & 0 deletions tests/AutoMapperTest/Issue269/expected.data
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
AutoMapper\Tests\AutoMapperTest\Issue269\Entity {
-paymentMethods: [
AutoMapper\Tests\AutoMapperTest\Issue269\PaymentMethod {
+name: "First"
+value: "First"
}
]
}
43 changes: 43 additions & 0 deletions tests/AutoMapperTest/Issue269/map.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace AutoMapper\Tests\AutoMapperTest\Issue269;

use AutoMapper\Tests\AutoMapperBuilder;

enum PaymentMethod: string
{
case First = 'First';
}

class Dto
{
/** @var PaymentMethod[] */
public ?array $paymentMethods = null;
}

class Entity
{
/** @var PaymentMethod[] */
private array $paymentMethods = [];

/** @param PaymentMethod[] $paymentMethods */
public function setPaymentMethods(array $paymentMethods): self
{
$this->paymentMethods = $paymentMethods;

return $this;
}

/** @return PaymentMethod[] */
public function getPaymentMethods(): array
{
return $this->paymentMethods;
}
}

$dto = new Dto();
$dto->paymentMethods = [PaymentMethod::First];

return AutoMapperBuilder::buildAutoMapper()->map($dto, Entity::class);