Skip to content

Stacking attributes reproducer #224

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
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 = '',
) {
}
}
Loading