Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

[BUGFIX] DI fails with CompilerDefinition; solves #5738 #5739

Closed
wants to merge 4 commits into from

4 participants

@michaelschiller

No description provided.

@Ocramius
Collaborator

@michaelschiller missing tests

tests/ZendTest/Di/Definition/CompilerDefinitionTest.php
@@ -131,4 +131,16 @@ 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();
+ $this->assertTrue($definition->hasMethodParameters('ZendTest\Di\TestAsset\ConstructorInjection\B', '__construct'));
+ $this->assertTrue($definition->hasMethodParameters('ZendTest\Di\TestAsset\SetterInjection\B', 'setA'));
+ $this->assertTrue($definition->hasMethodParameters('ZendTest\Di\TestAsset\CompilerClasses\D', 'setB'));
@Maks3w Collaborator
Maks3w added a note

Please add or change some assert for test false.

If possible one false when class does not exists and another one when method don't exists

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@weierophinney weierophinney added this to the 2.2.6 milestone
@weierophinney weierophinney self-assigned this
@weierophinney weierophinney referenced this pull request from a commit
@weierophinney weierophinney [#5739] CS fixes
- trailing whitespace
3f6675d
@weierophinney weierophinney referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/5739' into develop
Forward port #5739
45b1422
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-di
@weierophinney weierophinney Merge pull request zendframework/zf2#5739 from michaelschiller/di_com…
…pilerdefinition_fix

[BUGFIX] DI fails with CompilerDefinition; solves zendframework/zf2#5738
b1c0800
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-di
@weierophinney weierophinney [zendframework/zf2#5739] CS fixes
- trailing whitespace
ade7323
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-di
@weierophinney weierophinney Merge branch 'hotfix/5739' 2856dbd
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-di
@weierophinney weierophinney Merge branch 'hotfix/5739' into develop 3b70e47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
2  library/Zend/Di/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']));
}
/**
View
22 tests/ZendTest/Di/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'));
+ }
}
Something went wrong with that request. Please try again.