diff --git a/src/Definition/CompilerDefinition.php b/src/Definition/CompilerDefinition.php index ba56e45c..0f0681d1 100644 --- a/src/Definition/CompilerDefinition.php +++ b/src/Definition/CompilerDefinition.php @@ -385,7 +385,7 @@ public function hasMethodParameters($class, $method) return false; } - return (array_key_exists($method, $this->classes[$class])); + return (array_key_exists($method, $this->classes[$class]['parameters'])); } /** diff --git a/test/Definition/CompilerDefinitionTest.php b/test/Definition/CompilerDefinitionTest.php index 4b9d54f0..fa92195a 100644 --- a/test/Definition/CompilerDefinitionTest.php +++ b/test/Definition/CompilerDefinitionTest.php @@ -131,4 +131,26 @@ public function testExcludeAwareMethodsWithoutParameters() $this->assertTrue($definition->hasMethod('ZendTest\Di\TestAsset\AwareClasses\B', 'setSomething')); $this->assertFalse($definition->hasMethod('ZendTest\Di\TestAsset\AwareClasses\B', 'getSomething')); } + + public function testHasMethodParameters() + { + $definition = new CompilerDefinition(); + $definition->addDirectory(__DIR__ . '/../TestAsset/ConstructorInjection'); + $definition->addDirectory(__DIR__ . '/../TestAsset/SetterInjection'); + $definition->addDirectory(__DIR__ . '/../TestAsset/CompilerClasses'); + $definition->compile(); + + // constructor injection + $this->assertTrue($definition->hasMethodParameters('ZendTest\Di\TestAsset\ConstructorInjection\B', '__construct')); + // setter injection + $this->assertTrue($definition->hasMethodParameters('ZendTest\Di\TestAsset\SetterInjection\B', 'setA')); + // setter injection with method from derived class + $this->assertTrue($definition->hasMethodParameters('ZendTest\Di\TestAsset\CompilerClasses\D', 'setB')); + // class does not exist + $this->assertFalse($definition->hasMethodParameters('ZendTest\Di\TestAsset\ConstructorInjection\BB', '__construct')); + // method not existing + $this->assertFalse($definition->hasMethodParameters('ZendTest\Di\TestAsset\SetterInjection\B', 'setB')); + // method exists but has no parameters + $this->assertFalse($definition->hasMethodParameters('ZendTest\Di\TestAsset\SetterInjection\StaticSetter', 'setFoo')); + } }