Skip to content
This repository was archived by the owner on Jan 8, 2020. It is now read-only.

Commit 8e9ad3d

Browse files
committed
Merge pull request #5739 from michaelschiller/di_compilerdefinition_fix
[BUGFIX] DI fails with CompilerDefinition; solves #5738
2 parents 473de5e + 877b72b commit 8e9ad3d

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

library/Zend/Di/Definition/CompilerDefinition.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ public function hasMethodParameters($class, $method)
385385
return false;
386386
}
387387

388-
return (array_key_exists($method, $this->classes[$class]));
388+
return (array_key_exists($method, $this->classes[$class]['parameters']));
389389
}
390390

391391
/**

tests/ZendTest/Di/Definition/CompilerDefinitionTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,26 @@ public function testExcludeAwareMethodsWithoutParameters()
131131
$this->assertTrue($definition->hasMethod('ZendTest\Di\TestAsset\AwareClasses\B', 'setSomething'));
132132
$this->assertFalse($definition->hasMethod('ZendTest\Di\TestAsset\AwareClasses\B', 'getSomething'));
133133
}
134+
135+
public function testHasMethodParameters()
136+
{
137+
$definition = new CompilerDefinition();
138+
$definition->addDirectory(__DIR__ . '/../TestAsset/ConstructorInjection');
139+
$definition->addDirectory(__DIR__ . '/../TestAsset/SetterInjection');
140+
$definition->addDirectory(__DIR__ . '/../TestAsset/CompilerClasses');
141+
$definition->compile();
142+
143+
// constructor injection
144+
$this->assertTrue($definition->hasMethodParameters('ZendTest\Di\TestAsset\ConstructorInjection\B', '__construct'));
145+
// setter injection
146+
$this->assertTrue($definition->hasMethodParameters('ZendTest\Di\TestAsset\SetterInjection\B', 'setA'));
147+
// setter injection with method from derived class
148+
$this->assertTrue($definition->hasMethodParameters('ZendTest\Di\TestAsset\CompilerClasses\D', 'setB'));
149+
// class does not exist
150+
$this->assertFalse($definition->hasMethodParameters('ZendTest\Di\TestAsset\ConstructorInjection\BB', '__construct'));
151+
// method not existing
152+
$this->assertFalse($definition->hasMethodParameters('ZendTest\Di\TestAsset\SetterInjection\B', 'setB'));
153+
// method exists but has no parameters
154+
$this->assertFalse($definition->hasMethodParameters('ZendTest\Di\TestAsset\SetterInjection\StaticSetter', 'setFoo'));
155+
}
134156
}

0 commit comments

Comments
 (0)