|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/* |
| 6 | + * This file is part of rekalogika/mapper package. |
| 7 | + * |
| 8 | + * (c) Priyadi Iman Nurcahyo <https://rekalogika.dev> |
| 9 | + * |
| 10 | + * For the full copyright and license information, please view the LICENSE file |
| 11 | + * that was distributed with this source code. |
| 12 | + */ |
| 13 | + |
| 14 | +namespace Rekalogika\Mapper\Tests\IntegrationTest; |
| 15 | + |
| 16 | +use Rekalogika\Mapper\Tests\Common\FrameworkTestCase; |
| 17 | +use Rekalogika\Mapper\Tests\Fixtures\ObjectWithExistingValue\RootObject; |
| 18 | +use Rekalogika\Mapper\Tests\Fixtures\ObjectWithExistingValueDto\FurtherInnerObjectDto; |
| 19 | +use Rekalogika\Mapper\Tests\Fixtures\ObjectWithExistingValueDto\InnerObjectDto; |
| 20 | +use Rekalogika\Mapper\Tests\Fixtures\ObjectWithExistingValueDto\RootObjectDto; |
| 21 | + |
| 22 | +class ObjectWithExistingValueTest extends FrameworkTestCase |
| 23 | +{ |
| 24 | + public function testObjectWithExistingValueDtoToObject(): void |
| 25 | + { |
| 26 | + $dto = new RootObjectDto(); |
| 27 | + $dto->id = 'id'; |
| 28 | + $dto->innerObject = new InnerObjectDto(); |
| 29 | + $dto->innerObject->property = 'foo'; |
| 30 | + $dto->innerObject->furtherInnerObject = new FurtherInnerObjectDto(); |
| 31 | + $dto->innerObject->furtherInnerObject->property = 'bar'; |
| 32 | + |
| 33 | + $object = $this->mapper->map($dto, RootObject::class); |
| 34 | + |
| 35 | + $this->assertSame('id', $object->getId()); |
| 36 | + $this->assertSame('foo', $object->getInnerObject()->getProperty()); |
| 37 | + $this->assertSame('bar', $object->getInnerObject()->getFurtherInnerObject()->getProperty()); |
| 38 | + } |
| 39 | + |
| 40 | + public function testObjectWithExistingValueDtoToObjectPreinitialized(): void |
| 41 | + { |
| 42 | + $dto = new RootObjectDto(); |
| 43 | + $dto->id = 'id'; |
| 44 | + $dto->innerObject = new InnerObjectDto(); |
| 45 | + $dto->innerObject->property = 'foo'; |
| 46 | + $dto->innerObject->furtherInnerObject = new FurtherInnerObjectDto(); |
| 47 | + $dto->innerObject->furtherInnerObject->property = 'bar'; |
| 48 | + |
| 49 | + $object = new RootObject(); |
| 50 | + |
| 51 | + $this->mapper->map($dto, $object); |
| 52 | + |
| 53 | + $this->assertSame('id', $object->getId()); |
| 54 | + $this->assertSame('foo', $object->getInnerObject()->getProperty()); |
| 55 | + $this->assertSame('bar', $object->getInnerObject()->getFurtherInnerObject()->getProperty()); |
| 56 | + } |
| 57 | +} |
0 commit comments