File tree Expand file tree Collapse file tree 2 files changed +54
-0
lines changed
ProxyManagerTest/ProxyGenerator/ValueHolder/MethodGenerator Expand file tree Collapse file tree 2 files changed +54
-0
lines changed Original file line number Diff line number Diff line change 88use PHPUnit \Framework \TestCase ;
99use ProxyManager \ProxyGenerator \ValueHolder \MethodGenerator \Constructor ;
1010use ProxyManagerTestAsset \ClassWithMixedProperties ;
11+ use ProxyManagerTestAsset \ClassWithPromotedProperties ;
1112use ProxyManagerTestAsset \ClassWithVariadicConstructorArgument ;
1213use ProxyManagerTestAsset \EmptyClass ;
1314use ProxyManagerTestAsset \ProxyGenerator \LazyLoading \MethodGenerator \ClassWithTwoPublicProperties ;
@@ -133,4 +134,25 @@ public function testBodyStructureWithVariadicArguments(): void
133134
134135 self ::assertSame ($ expectedCode , $ constructor ->getBody ());
135136 }
137+
138+ public function testConstructorPropertyPromotion (): void
139+ {
140+ $ valueHolder = $ this ->createMock (PropertyGenerator::class);
141+
142+ $ valueHolder ->method ('getName ' )->willReturn ('foo ' );
143+
144+ $ constructor = Constructor::generateMethod (
145+ new ReflectionClass (ClassWithPromotedProperties::class),
146+ $ valueHolder
147+ );
148+
149+ self ::assertSame ('__construct ' , $ constructor ->getName ());
150+ $ parameters = $ constructor ->getParameters ();
151+ self ::assertCount (2 , $ parameters );
152+
153+ // Promoted constructor properties should not be doubled, since they are inherited anyway
154+ $ this ->assertSame ('int $amount ' , $ parameters ['amount ' ]->generate ());
155+ $ this ->assertSame ('?int $nullableAmount ' , $ parameters ['nullableAmount ' ]->generate ());
156+ }
157+
136158}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace ProxyManagerTestAsset ;
6+
7+ /**
8+ * Class with a promoted constructor properties
9+ *
10+ * @license MIT
11+ */
12+ class ClassWithPromotedProperties
13+ {
14+ /**
15+ * @param int $increment
16+ */
17+ public function __construct (
18+ protected int $ amount ,
19+ protected ?int $ nullableAmount
20+ ) {
21+ }
22+
23+ public function getAmount (): int
24+ {
25+ return $ this ->amount ;
26+ }
27+
28+ public function getNullableAmount (): ?int
29+ {
30+ return $ this ->nullableAmount ;
31+ }
32+ }
You can’t perform that action at this time.
0 commit comments