From cc427393aabbfc4c1bd37e71517157e83fae8ac8 Mon Sep 17 00:00:00 2001 From: tux-rampage Date: Mon, 16 Dec 2019 14:40:09 +0100 Subject: [PATCH 1/3] Fix build failures introduced with #56 --- src/Definition/Reflection/Parameter.php | 9 ++++++--- test/CodeGenerator/AbstractInjectorTest.php | 10 +--------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/Definition/Reflection/Parameter.php b/src/Definition/Reflection/Parameter.php index c6c17cd7..cc3789ca 100644 --- a/src/Definition/Reflection/Parameter.php +++ b/src/Definition/Reflection/Parameter.php @@ -63,11 +63,14 @@ public function getPosition() : int */ public function getType() : ?string { - if ($this->reflection->hasType()) { - return $this->reflection->getType()->getName(); + if (! $this->reflection->hasType()) { + return null; } - return null; + $type = $this->reflection->getType(); + assert($type !== null); + + return $type->getName(); } /** diff --git a/test/CodeGenerator/AbstractInjectorTest.php b/test/CodeGenerator/AbstractInjectorTest.php index 0f1a5ba0..90531c80 100644 --- a/test/CodeGenerator/AbstractInjectorTest.php +++ b/test/CodeGenerator/AbstractInjectorTest.php @@ -187,17 +187,9 @@ public function testConstructionWithoutContainerUsesDefaultContainer() public function testFactoryIsCreatedFromClassNameString() { $subject = $this->createTestSubject(function () { - return ['SomeClass' => StdClassFactory::class ]; + return ['SomeClass' => StdClassFactory::class]; }); - $this->assertSame( - StdClassFactory::class, - self::readAttribute($subject, 'factories')['SomeClass'] ?? null - ); $this->assertInstanceOf(stdClass::class, $subject->create('SomeClass')); - $this->assertInstanceOf( - StdClassFactory::class, - self::readAttribute($subject, 'factoryInstances')['SomeClass'] ?? null - ); } } From e0536dc6ed7de6176af6343ca7c4c7ea4912556f Mon Sep 17 00:00:00 2001 From: tux-rampage Date: Tue, 17 Dec 2019 10:39:04 +0100 Subject: [PATCH 2/3] Revert code change and add ignore --- phpstan.neon | 2 ++ src/Definition/Reflection/Parameter.php | 9 +++------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index bc3376c9..0e600174 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -2,3 +2,5 @@ parameters: level: 7 paths: - src/ + ignoreErrors: + - '#Cannot call method getName\(\) on ReflectionType\|null.#' diff --git a/src/Definition/Reflection/Parameter.php b/src/Definition/Reflection/Parameter.php index cc3789ca..c6c17cd7 100644 --- a/src/Definition/Reflection/Parameter.php +++ b/src/Definition/Reflection/Parameter.php @@ -63,14 +63,11 @@ public function getPosition() : int */ public function getType() : ?string { - if (! $this->reflection->hasType()) { - return null; + if ($this->reflection->hasType()) { + return $this->reflection->getType()->getName(); } - $type = $this->reflection->getType(); - assert($type !== null); - - return $type->getName(); + return null; } /** From d75012d0acc9811386090ebee5361e5910c6bff5 Mon Sep 17 00:00:00 2001 From: tux-rampage Date: Tue, 17 Dec 2019 10:56:58 +0100 Subject: [PATCH 3/3] Re-Add internal state assertions --- test/CodeGenerator/AbstractInjectorTest.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/CodeGenerator/AbstractInjectorTest.php b/test/CodeGenerator/AbstractInjectorTest.php index 90531c80..daceb7b3 100644 --- a/test/CodeGenerator/AbstractInjectorTest.php +++ b/test/CodeGenerator/AbstractInjectorTest.php @@ -13,6 +13,7 @@ use Prophecy\Argument; use Prophecy\Prophecy\ObjectProphecy; use Psr\Container\ContainerInterface; +use ReflectionProperty; use stdClass; use Zend\Di\CodeGenerator\AbstractInjector; use Zend\Di\CodeGenerator\FactoryInterface; @@ -190,6 +191,19 @@ public function testFactoryIsCreatedFromClassNameString() return ['SomeClass' => StdClassFactory::class]; }); + $factoryInstancesProperty = new ReflectionProperty(AbstractInjector::class, 'factoryInstances'); + $factoriesProperty = new ReflectionProperty(AbstractInjector::class, 'factories'); + $factoryInstancesProperty->setAccessible(true); + $factoriesProperty->setAccessible(true); + + $this->assertSame( + StdClassFactory::class, + $factoriesProperty->getValue($subject)['SomeClass'] ?? null + ); $this->assertInstanceOf(stdClass::class, $subject->create('SomeClass')); + $this->assertInstanceOf( + StdClassFactory::class, + $factoryInstancesProperty->getValue($subject)['SomeClass'] ?? null + ); } }