Skip to content

Commit

Permalink
Stacking attributes reproducer
Browse files Browse the repository at this point in the history
  • Loading branch information
Korbeil committed Feb 14, 2025
1 parent 44cfd9c commit 2a01c8c
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/AutoMapperMapToTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
use AutoMapper\Tests\Fixtures\MapTo\Bar;
use AutoMapper\Tests\Fixtures\MapTo\DateTimeFormatMapTo;
use AutoMapper\Tests\Fixtures\MapTo\FooMapTo;
use AutoMapper\Tests\Fixtures\MapTo\ManySourceBar;
use AutoMapper\Tests\Fixtures\MapTo\ManySourceFoo;
use AutoMapper\Tests\Fixtures\MapTo\ManyTargetBar;
use AutoMapper\Tests\Fixtures\MapTo\MapperDateTimeFormatMapTo;
use AutoMapper\Tests\Fixtures\MapTo\PriorityMapTo;
use AutoMapper\Tests\Fixtures\Transformer\CustomTransformer\FooDependency;
Expand Down Expand Up @@ -169,4 +172,27 @@ public function testDateTimeFormat(): void
self::assertArrayHasKey('interface', $result);
self::assertSame($normal->format(\DateTimeInterface::RFC822), $result['interface']);
}

public function testStackedAttributes(): void
{
$source = new ManySourceFoo('2025');
$output = $this->autoMapper->map($source, ManyTargetBar::class);
self::assertEquals('2025', $output->foo);

$source = new ManySourceBar('2025');
$output = $this->autoMapper->map($source, ManyTargetBar::class);
self::assertEquals('', $output->foo);

$source = ['foo' => '2025'];
$output = $this->autoMapper->map($source, ManyTargetBar::class);
self::assertEquals('', $output->foo);

$source = ['dateEffet' => '2025'];
$output = $this->autoMapper->map($source, ManyTargetBar::class);
self::assertEquals('2025', $output->foo);

$source = ['dateEffetDeux' => '2025'];
$output = $this->autoMapper->map($source, ManyTargetBar::class);
self::assertEquals('2025', $output->foo);
}
}
15 changes: 15 additions & 0 deletions tests/Fixtures/MapTo/ManySourceBar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace AutoMapper\Tests\Fixtures\MapTo;

use AutoMapper\Attribute\MapFrom;

class ManySourceBar
{
public function __construct(
public string $dateEffet = '',
) {
}
}
15 changes: 15 additions & 0 deletions tests/Fixtures/MapTo/ManySourceFoo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace AutoMapper\Tests\Fixtures\MapTo;

use AutoMapper\Attribute\MapFrom;

class ManySourceFoo
{
public function __construct(
public string $dateDebutEffet = '',
) {
}
}
18 changes: 18 additions & 0 deletions tests/Fixtures/MapTo/ManyTargetBar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace AutoMapper\Tests\Fixtures\MapTo;

use AutoMapper\Attribute\MapFrom;

class ManyTargetBar
{
public function __construct(
#[MapFrom(source: 'array', property: 'dateEffet')]
#[MapFrom(source: 'array', property: 'dateEffetDeux')]
#[MapFrom(source: ManySourceFoo::class, property: 'dateDebutEffet')]
public string $foo = '',
) {
}
}

0 comments on commit 2a01c8c

Please sign in to comment.