Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixed DefinitionList::hasMethod() #3329

Closed
wants to merge 2 commits into from

3 participants

Nicolas Eeckeloo Marco Pivetta Matthew Weier O'Phinney
Nicolas Eeckeloo

The method DefinitionList::hasMethods() was simply duplicated to create method DefinitionList::hasMethod() and therefore it did not work correctly.

Nicolas Eeckeloo neeckeloo closed this
Nicolas Eeckeloo

I just realize that this bug was fixed recently, but maybe this pull requests may interest you since I refactored some methods and added unit tests.

Nicolas Eeckeloo neeckeloo reopened this
Marco Pivetta
Collaborator

@neeckeloo what do you mean by "did not work correctly"? It may be useful to just have the tests to avoid regressions.

Nicolas Eeckeloo

I was referring to #3229 which fixed the fact that the method DefinitionList::hasMethod() has the same behavior as the method DefinitionList::hasMethods().

I updated unit tests.

Matthew Weier O'Phinney weierophinney referenced this pull request from a commit
Matthew Weier O'Phinney weierophinney Merge branch 'hotfix/3329' into develop
Forward port #3329
af768c1
Matthew Weier O'Phinney weierophinney was assigned
Deleted user Unknown referenced this pull request from a commit
Matthew Weier O'Phinney weierophinney Merge branch 'hotfix/3329'
Close #3329
75135b9
Deleted user Unknown referenced this pull request from a commit
Matthew Weier O'Phinney weierophinney Merge branch 'hotfix/3329' into develop
Forward port #3329
986de72
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 2, 2013
  1. Nicolas Eeckeloo
  2. Nicolas Eeckeloo

    Update unit tests

    neeckeloo authored
This page is out of date. Refresh to see the latest.
9 library/Zend/Di/Config.php
View
@@ -59,11 +59,9 @@ public function configure(Di $di)
if (isset($this->data['definition'])) {
$this->configureDefinition($di, $this->data['definition']);
}
-
if (isset($this->data['instance'])) {
$this->configureInstance($di, $this->data['instance']);
}
-
}
/**
@@ -90,8 +88,8 @@ public function configureDefinition(Di $di, $definition)
$definitions[] = $definition;
}
}
- $definitions = new DefinitionList($definitions);
- $di->setDefinitionList($definitions);
+ $definitionList = new DefinitionList($definitions);
+ $di->setDefinitionList($definitionList);
} elseif (isset($definitionData['use_annotations']) && $definitionData['use_annotations']) {
/* @var $runtimeDefinition Definition\RuntimeDefinition */
$runtimeDefinition = $di
@@ -146,9 +144,7 @@ public function configureDefinition(Di $di, $definition)
}
}
}
-
}
-
}
/**
@@ -200,7 +196,6 @@ public function configureInstance(Di $di, $instanceData)
}
}
}
-
}
}
32 library/Zend/Di/DefinitionList.php
View
@@ -146,9 +146,11 @@ public function getClassSupertypes($class)
foreach ($this as $definition) {
if ($definition->hasClass($class)) {
$supertypes = array_merge($supertypes, $definition->getClassSupertypes($class));
- if (!$definition instanceof Definition\PartialMarker) {
- return $supertypes;
+ if ($definition instanceof Definition\PartialMarker) {
+ continue;
}
+
+ return $supertypes;
}
}
return $supertypes;
@@ -165,9 +167,9 @@ public function getInstantiator($class)
$value = $definition->getInstantiator($class);
if ($value === null && $definition instanceof Definition\PartialMarker) {
continue;
- } else {
- return $value;
}
+
+ return $value;
}
}
@@ -184,9 +186,9 @@ public function hasMethods($class)
if ($definition->hasClass($class)) {
if ($definition->hasMethods($class) === false && $definition instanceof Definition\PartialMarker) {
continue;
- } else {
- return $definition->hasMethods($class);
}
+
+ return $definition->hasMethods($class);
}
}
@@ -198,14 +200,14 @@ public function hasMethods($class)
*/
public function hasMethod($class, $method)
{
+ if (!$this->hasMethods($class)) {
+ return false;
+ }
+
/** @var $definition Definition\DefinitionInterface */
foreach ($this as $definition) {
- if ($definition->hasClass($class)) {
- if ($definition->hasMethods($class) === false && $definition instanceof Definition\PartialMarker) {
- continue;
- } else {
- return $definition->hasMethods($class);
- }
+ if ($definition->hasMethod($class, $method)) {
+ return true;
}
}
@@ -221,11 +223,11 @@ public function getMethods($class)
$methods = array();
foreach ($this as $definition) {
if ($definition->hasClass($class)) {
- if ($definition instanceof Definition\PartialMarker) {
- $methods = array_merge($definition->getMethods($class), $methods);
- } else {
+ if (!$definition instanceof Definition\PartialMarker) {
return array_merge($definition->getMethods($class), $methods);
}
+
+ $methods = array_merge($definition->getMethods($class), $methods);
}
}
13 tests/ZendTest/Di/DefinitionListTest.php
View
@@ -29,6 +29,19 @@ public function testGetClassSupertypes()
$definitionList = new DefinitionList(array($definitionClassA, $definitionClassB));
$this->assertEquals($superTypesA, $definitionList->getClassSupertypes("A"));
+ }
+
+ public function testHasMethod()
+ {
+ $definitionClass = new ClassDefinition('foo');
+ $definitionClass->addMethod('doFoo');
+ $definitionList = new DefinitionList(array($definitionClass));
+
+ $this->assertTrue($definitionList->hasMethod('foo', 'doFoo'));
+ $this->assertFalse($definitionList->hasMethod('foo', 'doBar'));
+ $definitionClass->addMethod('doBar');
+
+ $this->assertTrue($definitionList->hasMethod('foo', 'doBar'));
}
}
Something went wrong with that request. Please try again.