|
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,25 @@ 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 | + $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 | + |
136 | 158 | }
|
0 commit comments