File tree 2 files changed +49
-0
lines changed
ProxyManagerTest/ProxyGenerator/ValueHolder/MethodGenerator 2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change 8
8
use PHPUnit \Framework \TestCase ;
9
9
use ProxyManager \ProxyGenerator \ValueHolder \MethodGenerator \Constructor ;
10
10
use ProxyManagerTestAsset \ClassWithMixedProperties ;
11
+ use ProxyManagerTestAsset \ClassWithPromotedProperties ;
11
12
use ProxyManagerTestAsset \ClassWithVariadicConstructorArgument ;
12
13
use ProxyManagerTestAsset \EmptyClass ;
13
14
use ProxyManagerTestAsset \ProxyGenerator \LazyLoading \MethodGenerator \ClassWithTwoPublicProperties ;
@@ -133,4 +134,23 @@ public function testBodyStructureWithVariadicArguments(): void
133
134
134
135
self ::assertSame ($ expectedCode , $ constructor ->getBody ());
135
136
}
137
+
138
+ public function testConstructorPropertyPromotion (): void
139
+ {
140
+ $ valueHolder = $ this ->createMock (PropertyGenerator::class);
141
+
142
+ $ constructor = Constructor::generateMethod (
143
+ new ReflectionClass (ClassWithPromotedProperties::class),
144
+ $ valueHolder
145
+ );
146
+
147
+ self ::assertSame ('__construct ' , $ constructor ->getName ());
148
+ $ parameters = $ constructor ->getParameters ();
149
+ self ::assertCount (2 , $ parameters );
150
+
151
+ // Promoted constructor properties should not be doubled, since they are inherited anyway
152
+ $ this ->assertSame ('int $amount ' , $ parameters ['amount ' ]->generate ());
153
+ $ this ->assertSame ('?int $nullableAmount ' , $ parameters ['nullableAmount ' ]->generate ());
154
+ }
155
+
136
156
}
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
+ public function __construct (
15
+ protected int $ amount ,
16
+ protected ?int $ nullableAmount
17
+ ) {
18
+ }
19
+
20
+ public function getAmount (): int
21
+ {
22
+ return $ this ->amount ;
23
+ }
24
+
25
+ public function getNullableAmount (): ?int
26
+ {
27
+ return $ this ->nullableAmount ;
28
+ }
29
+ }
You can’t perform that action at this time.
0 commit comments