Skip to content

Commit f5ec4a2

Browse files
committed
test: Lazy loading id property from parent class.
1 parent 001efb0 commit f5ec4a2

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* test: Add mandatory config for `symfony/framework-bundle`.
99
* fix(`ProxyGenerator`): Handle readonly targets.
1010
* build: Require `symfony/console`.
11+
* test: Lazy loading id property from parent class.
1112

1213
## 0.6.7
1314

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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\Fixtures\LazyObject;
15+
16+
class AbstractObjectWithIdDto
17+
{
18+
public ?string $id = null;
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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\Fixtures\LazyObject;
15+
16+
class ChildObjectWithIdDto extends AbstractObjectWithIdDto
17+
{
18+
public ?string $name = null;
19+
}

tests/IntegrationTest/LazyObjectTest.php

+20
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
namespace Rekalogika\Mapper\Tests\IntegrationTest;
1515

1616
use Rekalogika\Mapper\Tests\Common\AbstractFrameworkTest;
17+
use Rekalogika\Mapper\Tests\Fixtures\LazyObject\ChildObjectWithIdDto;
18+
use Rekalogika\Mapper\Tests\Fixtures\LazyObject\ConcreteObjectWithId;
1719
use Rekalogika\Mapper\Tests\Fixtures\LazyObject\ObjectWithId;
1820
use Rekalogika\Mapper\Tests\Fixtures\LazyObject\ObjectWithIdDto;
1921
use Rekalogika\Mapper\Tests\Fixtures\LazyObject\ObjectWithIdFinalDto;
@@ -75,4 +77,22 @@ public function testReadOnly83(): void
7577
$source = new ObjectWithId();
7678
$target = $this->mapper->map($source, ObjectWithIdReadOnlyDto::class);
7779
}
80+
81+
82+
public function testIdInParentClass(): void
83+
{
84+
$source = new ObjectWithId();
85+
$target = $this->mapper->map($source, ChildObjectWithIdDto::class);
86+
$this->assertSame('id', $target->id);
87+
}
88+
89+
public function testIdInParentClassInitialized(): void
90+
{
91+
$this->expectException(\LogicException::class);
92+
$this->expectExceptionMessage('This method should not be called');
93+
94+
$source = new ObjectWithId();
95+
$target = $this->mapper->map($source, ChildObjectWithIdDto::class);
96+
$foo = $target->name;
97+
}
7898
}

0 commit comments

Comments
 (0)