diff --git a/composer.json b/composer.json index 8660b2a0..5d509621 100644 --- a/composer.json +++ b/composer.json @@ -18,8 +18,8 @@ "homepage": "http://ocramius.github.io/" }, { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" + "name": "Nicolas Grekas", + "email": "p@tchwork.com" } ], "replace": { @@ -36,7 +36,7 @@ }, "require-dev": { "ext-phar": "*", - "symfony/phpunit-bridge": "^5.2" + "symfony/phpunit-bridge": "^5.2|^6.0" }, "autoload": { "psr-4": { diff --git a/src/ProxyManager/Generator/MagicMethodGenerator.php b/src/ProxyManager/Generator/MagicMethodGenerator.php index ac4ba269..ea7447b1 100644 --- a/src/ProxyManager/Generator/MagicMethodGenerator.php +++ b/src/ProxyManager/Generator/MagicMethodGenerator.php @@ -4,6 +4,7 @@ namespace ProxyManager\Generator; +use Laminas\Code\Generator\ParameterGenerator; use ReflectionClass; use function strtolower; @@ -14,7 +15,7 @@ class MagicMethodGenerator extends MethodGenerator { /** - * @param mixed[] $parameters + * @param ParameterGenerator[]|array[]|string[] $parameters */ public function __construct(ReflectionClass $originalClass, string $name, array $parameters = []) { diff --git a/src/ProxyManager/GeneratorStrategy/FileWriterGeneratorStrategy.php b/src/ProxyManager/GeneratorStrategy/FileWriterGeneratorStrategy.php index 7f8bd551..36cdb481 100644 --- a/src/ProxyManager/GeneratorStrategy/FileWriterGeneratorStrategy.php +++ b/src/ProxyManager/GeneratorStrategy/FileWriterGeneratorStrategy.php @@ -44,7 +44,7 @@ public function __construct(FileLocatorInterface $fileLocator) public function generate(ClassGenerator $classGenerator): string { $generatedCode = $classGenerator->generate(); - $className = $classGenerator->getNamespaceName() . '\\' . $classGenerator->getName(); + $className = (string) $classGenerator->getNamespaceName() . '\\' . $classGenerator->getName(); $fileName = $this->fileLocator->getProxyFileName($className); set_error_handler($this->emptyErrorHandler); diff --git a/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/PropertyGenerator/InitializationTrackerTest.php b/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/PropertyGenerator/InitializationTrackerTest.php index 31b5aa8d..008e0b81 100644 --- a/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/PropertyGenerator/InitializationTrackerTest.php +++ b/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/PropertyGenerator/InitializationTrackerTest.php @@ -23,8 +23,10 @@ protected function createProperty(): PropertyGenerator public function testInitializationFlagIsFalseByDefault(): void { - $property = $this->createProperty(); + $defaultValue = $this->createProperty() + ->getDefaultValue(); - self::assertFalse($property->getDefaultValue()->getValue()); + self::assertNotNull($defaultValue); + self::assertFalse($defaultValue->getValue()); } } diff --git a/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/PropertyGenerator/PrivatePropertiesMapTest.php b/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/PropertyGenerator/PrivatePropertiesMapTest.php index 3eb76d99..598dc626 100644 --- a/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/PropertyGenerator/PrivatePropertiesMapTest.php +++ b/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/PropertyGenerator/PrivatePropertiesMapTest.php @@ -30,27 +30,29 @@ protected function createProperty(): PropertyGenerator public function testExtractsProtectedProperties(): void { - $map = new PrivatePropertiesMap( + $defaultValue = (new PrivatePropertiesMap( Properties::fromReflectionClass(new ReflectionClass(ClassWithMixedProperties::class)) - ); + ))->getDefaultValue(); + self::assertNotNull($defaultValue); self::assertSame( [ 'privateProperty0' => [ClassWithMixedProperties::class => true], 'privateProperty1' => [ClassWithMixedProperties::class => true], 'privateProperty2' => [ClassWithMixedProperties::class => true], ], - $map->getDefaultValue()->getValue() + $defaultValue->getValue() ); } public function testSkipsAbstractProtectedMethods(): void { - $map = new PrivatePropertiesMap( + $defaultValue = (new PrivatePropertiesMap( Properties::fromReflectionClass(new ReflectionClass(ClassWithAbstractProtectedMethod::class)) - ); + ))->getDefaultValue(); - self::assertSame([], $map->getDefaultValue()->getValue()); + self::assertNotNull($defaultValue); + self::assertSame([], $defaultValue->getValue()); } public function testIsStaticPrivate(): void diff --git a/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/PropertyGenerator/ProtectedPropertiesMapTest.php b/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/PropertyGenerator/ProtectedPropertiesMapTest.php index d225d577..2f999400 100644 --- a/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/PropertyGenerator/ProtectedPropertiesMapTest.php +++ b/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/PropertyGenerator/ProtectedPropertiesMapTest.php @@ -29,27 +29,29 @@ protected function createProperty(): PropertyGenerator public function testExtractsProtectedProperties(): void { - $map = new ProtectedPropertiesMap( + $defaultValue = (new ProtectedPropertiesMap( Properties::fromReflectionClass(new ReflectionClass(ClassWithMixedProperties::class)) - ); + ))->getDefaultValue(); + self::assertNotNull($defaultValue); self::assertSame( [ 'protectedProperty0' => ClassWithMixedProperties::class, 'protectedProperty1' => ClassWithMixedProperties::class, 'protectedProperty2' => ClassWithMixedProperties::class, ], - $map->getDefaultValue()->getValue() + $defaultValue->getValue() ); } public function testSkipsAbstractProtectedMethods(): void { - $map = new ProtectedPropertiesMap( + $defaultValue = (new ProtectedPropertiesMap( Properties::fromReflectionClass(new ReflectionClass(ClassWithAbstractProtectedMethod::class)) - ); + ))->getDefaultValue(); - self::assertSame([], $map->getDefaultValue()->getValue()); + self::assertNotNull($defaultValue); + self::assertSame([], $defaultValue->getValue()); } public function testIsStaticPrivate(): void diff --git a/tests/ProxyManagerTest/ProxyGenerator/PropertyGenerator/PublicPropertiesMapTest.php b/tests/ProxyManagerTest/ProxyGenerator/PropertyGenerator/PublicPropertiesMapTest.php index ade49f03..1b2bb84b 100644 --- a/tests/ProxyManagerTest/ProxyGenerator/PropertyGenerator/PublicPropertiesMapTest.php +++ b/tests/ProxyManagerTest/ProxyGenerator/PropertyGenerator/PublicPropertiesMapTest.php @@ -26,8 +26,11 @@ public function testEmptyClass(): void Properties::fromReflectionClass(new ReflectionClass(EmptyClass::class)) ); - self::assertIsArray($publicProperties->getDefaultValue()->getValue()); - self::assertEmpty($publicProperties->getDefaultValue()->getValue()); + $defaultValue = $publicProperties->getDefaultValue(); + + self::assertNotNull($defaultValue); + self::assertIsArray($defaultValue->getValue()); + self::assertEmpty($defaultValue->getValue()); self::assertTrue($publicProperties->isStatic()); self::assertSame('private', $publicProperties->getVisibility()); self::assertTrue($publicProperties->isEmpty()); @@ -39,9 +42,12 @@ public function testClassWithPublicProperties(): void Properties::fromReflectionClass(new ReflectionClass(ClassWithPublicProperties::class)) ); + $defaultValue = $publicProperties->getDefaultValue(); + self::assertTrue($publicProperties->isStatic()); self::assertSame('private', $publicProperties->getVisibility()); self::assertFalse($publicProperties->isEmpty()); + self::assertNotNull($defaultValue); self::assertSame( [ 'property0' => true, @@ -55,21 +61,24 @@ public function testClassWithPublicProperties(): void 'property8' => true, 'property9' => true, ], - $publicProperties->getDefaultValue()->getValue() + $defaultValue->getValue() ); } public function testClassWithMixedProperties(): void { + $defaultValue = (new PublicPropertiesMap( + Properties::fromReflectionClass(new ReflectionClass(ClassWithMixedProperties::class)) + ))->getDefaultValue(); + + self::assertNotNull($defaultValue); self::assertSame( [ 'publicProperty0' => true, 'publicProperty1' => true, 'publicProperty2' => true, ], - (new PublicPropertiesMap( - Properties::fromReflectionClass(new ReflectionClass(ClassWithMixedProperties::class)) - ))->getDefaultValue()->getValue() + $defaultValue->getValue() ); } } diff --git a/tests/ProxyManagerTest/Signature/ClassSignatureGeneratorTest.php b/tests/ProxyManagerTest/Signature/ClassSignatureGeneratorTest.php index e191d921..b6c32ca8 100644 --- a/tests/ProxyManagerTest/Signature/ClassSignatureGeneratorTest.php +++ b/tests/ProxyManagerTest/Signature/ClassSignatureGeneratorTest.php @@ -37,10 +37,13 @@ public function testAddSignature(): void ->expects(self::once()) ->method('addPropertyFromGenerator') ->with(self::callback(static function (PropertyGenerator $property): bool { + $defaultValue = $property->getDefaultValue(); + return $property->getName() === 'signaturePropertyName' && $property->isStatic() && $property->getVisibility() === 'private' - && $property->getDefaultValue()->getValue() === 'valid-signature'; + && $defaultValue !== null + && $defaultValue->getValue() === 'valid-signature'; })); $this