Skip to content

Commit fe5916e

Browse files
committed
Tests: default value override with ctor promotion
1 parent 709978a commit fe5916e

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Tests\Orisai\ObjectMapper\Doubles\Php80;
4+
5+
use Orisai\ObjectMapper\Rules\StringValue;
6+
7+
final class CtorPromotionChildVo extends CtorPromotionParentVo
8+
{
9+
10+
public function __construct(
11+
string $a,
12+
public string $b,
13+
#[StringValue]
14+
public string $c = 'overriden',
15+
#[StringValue]
16+
public string $d = 'baz',
17+
)
18+
{
19+
parent::__construct($a, $b, $c);
20+
}
21+
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Tests\Orisai\ObjectMapper\Doubles\Php80;
4+
5+
use Orisai\ObjectMapper\MappedObject;
6+
use Orisai\ObjectMapper\Rules\StringValue;
7+
8+
abstract class CtorPromotionParentVo implements MappedObject
9+
{
10+
11+
public function __construct(
12+
#[StringValue]
13+
public string $a,
14+
#[StringValue]
15+
public string $b = 'foo',
16+
#[StringValue]
17+
public string $c = 'bar'
18+
)
19+
{
20+
}
21+
22+
}

tests/Unit/Processing/DefaultProcessorTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
use Tests\Orisai\ObjectMapper\Doubles\NoDefaultsVO;
5656
use Tests\Orisai\ObjectMapper\Doubles\Php80\AttributesVO;
5757
use Tests\Orisai\ObjectMapper\Doubles\Php80\ConstructorPromotedVO;
58+
use Tests\Orisai\ObjectMapper\Doubles\Php80\CtorPromotionChildVo;
5859
use Tests\Orisai\ObjectMapper\Doubles\Php80\DefaultsOverrideVO;
5960
use Tests\Orisai\ObjectMapper\Doubles\Php81\NewInInitializersVO;
6061
use Tests\Orisai\ObjectMapper\Doubles\Php81\ObjectDefaultVO;
@@ -1342,6 +1343,29 @@ public function testConstructorPromotion(): void
13421343
self::assertNull($vo->optionalUntyped);
13431344
}
13441345

1346+
public function testConstructorPromotionDefaultValueOverride(): void
1347+
{
1348+
if (PHP_VERSION_ID < 8_00_00) {
1349+
self::markTestSkipped('Ctor promotion requires PHP 8.0');
1350+
}
1351+
1352+
$data = [
1353+
'a' => '1',
1354+
];
1355+
1356+
$vo = $this->processor->process($data, CtorPromotionChildVo::class);
1357+
1358+
self::assertEquals(
1359+
$vo,
1360+
new CtorPromotionChildVo(
1361+
'1',
1362+
'foo',
1363+
'bar', // TODO - this should be 'overriden' value from child
1364+
'baz',
1365+
),
1366+
);
1367+
}
1368+
13451369
public function testNewInInitializers(): void
13461370
{
13471371
if (PHP_VERSION_ID < 8_01_00) {

0 commit comments

Comments
 (0)