File tree Expand file tree Collapse file tree 3 files changed +68
-0
lines changed
Expand file tree Collapse file tree 3 files changed +68
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 5555use Tests \Orisai \ObjectMapper \Doubles \NoDefaultsVO ;
5656use Tests \Orisai \ObjectMapper \Doubles \Php80 \AttributesVO ;
5757use Tests \Orisai \ObjectMapper \Doubles \Php80 \ConstructorPromotedVO ;
58+ use Tests \Orisai \ObjectMapper \Doubles \Php80 \CtorPromotionChildVo ;
5859use Tests \Orisai \ObjectMapper \Doubles \Php80 \DefaultsOverrideVO ;
5960use Tests \Orisai \ObjectMapper \Doubles \Php81 \NewInInitializersVO ;
6061use 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 ) {
You can’t perform that action at this time.
0 commit comments