diff --git a/tests/Fixtures/PropertyInSetterAndConstructor/ChildObject.php b/tests/Fixtures/PropertyInSetterAndConstructor/ChildObject.php new file mode 100644 index 0000000..3942ddc --- /dev/null +++ b/tests/Fixtures/PropertyInSetterAndConstructor/ChildObject.php @@ -0,0 +1,32 @@ + + * + * For the full copyright and license information, please view the LICENSE file + * that was distributed with this source code. + */ + +namespace Rekalogika\Mapper\Tests\Fixtures\PropertyInSetterAndConstructor; + +class ChildObject +{ + public function __construct( + private string $a, + ) { + } + + public function getA(): string + { + return $this->a; + } + + public function setA(string $a): void + { + $this->a = $a; + } +} diff --git a/tests/Fixtures/PropertyInSetterAndConstructor/ChildObjectDto.php b/tests/Fixtures/PropertyInSetterAndConstructor/ChildObjectDto.php new file mode 100644 index 0000000..e4da05d --- /dev/null +++ b/tests/Fixtures/PropertyInSetterAndConstructor/ChildObjectDto.php @@ -0,0 +1,20 @@ + + * + * For the full copyright and license information, please view the LICENSE file + * that was distributed with this source code. + */ + +namespace Rekalogika\Mapper\Tests\Fixtures\PropertyInSetterAndConstructor; + +/** @psalm-suppress MissingConstructor */ +class ChildObjectDto +{ + public string $a; +} diff --git a/tests/Fixtures/PropertyInSetterAndConstructor/ParentObject.php b/tests/Fixtures/PropertyInSetterAndConstructor/ParentObject.php new file mode 100644 index 0000000..51c7e2d --- /dev/null +++ b/tests/Fixtures/PropertyInSetterAndConstructor/ParentObject.php @@ -0,0 +1,43 @@ + + * + * For the full copyright and license information, please view the LICENSE file + * that was distributed with this source code. + */ + +namespace Rekalogika\Mapper\Tests\Fixtures\PropertyInSetterAndConstructor; + +class ParentObject +{ + public function __construct( + private string $name, + private ChildObject $child, + ) { + } + + public function getChild(): ChildObject + { + return $this->child; + } + + public function setChild(ChildObject $child): void + { + $this->child = $child; + } + + public function getName(): string + { + return $this->name; + } + + public function setName(string $name): void + { + $this->name = $name; + } +} diff --git a/tests/Fixtures/PropertyInSetterAndConstructor/ParentObjectDto.php b/tests/Fixtures/PropertyInSetterAndConstructor/ParentObjectDto.php new file mode 100644 index 0000000..44c9fc1 --- /dev/null +++ b/tests/Fixtures/PropertyInSetterAndConstructor/ParentObjectDto.php @@ -0,0 +1,21 @@ + + * + * For the full copyright and license information, please view the LICENSE file + * that was distributed with this source code. + */ + +namespace Rekalogika\Mapper\Tests\Fixtures\PropertyInSetterAndConstructor; + +/** @psalm-suppress MissingConstructor */ +class ParentObjectDto +{ + public string $name; + public ChildObjectDto $child; +} diff --git a/tests/IntegrationTest/PropertyInSetterAndConstructorTest.php b/tests/IntegrationTest/PropertyInSetterAndConstructorTest.php new file mode 100644 index 0000000..def2cda --- /dev/null +++ b/tests/IntegrationTest/PropertyInSetterAndConstructorTest.php @@ -0,0 +1,50 @@ + + * + * For the full copyright and license information, please view the LICENSE file + * that was distributed with this source code. + */ + +namespace Rekalogika\Mapper\Tests\IntegrationTest; + +use Rekalogika\Mapper\Tests\Common\FrameworkTestCase; +use Rekalogika\Mapper\Tests\Fixtures\PropertyInSetterAndConstructor\ChildObject; +use Rekalogika\Mapper\Tests\Fixtures\PropertyInSetterAndConstructor\ChildObjectDto; +use Rekalogika\Mapper\Tests\Fixtures\PropertyInSetterAndConstructor\ParentObject; +use Rekalogika\Mapper\Tests\Fixtures\PropertyInSetterAndConstructor\ParentObjectDto; + +class PropertyInSetterAndConstructorTest extends FrameworkTestCase +{ + public function testIssue57(): void + { + $dto = new ParentObjectDto(); + $dto->name = 'dto-name'; + $dto->child = new ChildObjectDto(); + $dto->child->a = 'dto-a'; + + $entity = $this->mapper->map($dto, ParentObject::class); + + $this->assertSame('dto-name', $entity->getName()); + $this->assertSame('dto-a', $entity->getChild()->getA()); + } + + public function testIssue57Preinitialized(): void + { + $dto = new ParentObjectDto(); + $dto->name = 'dto-name'; + $dto->child = new ChildObjectDto(); + $dto->child->a = 'dto-a'; + + $entity = new ParentObject('entity-name', new ChildObject('entity-a')); + $this->mapper->map($dto, $entity); + + $this->assertSame('dto-name', $entity->getName()); + $this->assertSame('dto-a', $entity->getChild()->getA()); + } +}