-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Setter does not get called if the property is also in the constr…
…uctor
- Loading branch information
Showing
5 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
tests/Fixtures/PropertyInSetterAndConstructor/ChildObject.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of rekalogika/mapper package. | ||
* | ||
* (c) Priyadi Iman Nurcahyo <https://rekalogika.dev> | ||
* | ||
* 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; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
tests/Fixtures/PropertyInSetterAndConstructor/ChildObjectDto.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of rekalogika/mapper package. | ||
* | ||
* (c) Priyadi Iman Nurcahyo <https://rekalogika.dev> | ||
* | ||
* 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; | ||
} |
43 changes: 43 additions & 0 deletions
43
tests/Fixtures/PropertyInSetterAndConstructor/ParentObject.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of rekalogika/mapper package. | ||
* | ||
* (c) Priyadi Iman Nurcahyo <https://rekalogika.dev> | ||
* | ||
* 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; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
tests/Fixtures/PropertyInSetterAndConstructor/ParentObjectDto.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of rekalogika/mapper package. | ||
* | ||
* (c) Priyadi Iman Nurcahyo <https://rekalogika.dev> | ||
* | ||
* 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; | ||
} |
50 changes: 50 additions & 0 deletions
50
tests/IntegrationTest/PropertyInSetterAndConstructorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of rekalogika/mapper package. | ||
* | ||
* (c) Priyadi Iman Nurcahyo <https://rekalogika.dev> | ||
* | ||
* 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()); | ||
} | ||
} |