Browse files

[Validator] Fixed StaticMethodLoader when used with abstract methods.

  • Loading branch information...
1 parent 098b934 commit 089188f6035619abc04cfdc5736f8e2a8eaaa510 @jakzal jakzal committed Apr 13, 2012
View
2 src/Symfony/Component/Validator/Mapping/Loader/StaticMethodLoader.php
@@ -37,7 +37,7 @@ public function loadClassMetadata(ClassMetadata $metadata)
throw new MappingException(sprintf('The method %s::%s should be static', $reflClass->getName(), $this->methodName));
}
- if ($reflMethod->getDeclaringClass()->getName() != $reflClass->getName()) {
+ if ($reflClass->isAbstract() || $reflMethod->getDeclaringClass()->getName() != $reflClass->getName()) {
return false;
}
View
13 tests/Symfony/Tests/Component/Validator/Mapping/Loader/StaticMethodLoaderTest.php
@@ -35,6 +35,14 @@ public function testLoadClassMetadataReturnsFalseIfNotSuccessful()
$this->assertFalse($loader->loadClassMetadata($metadata));
}
+ public function testLoadClassMetadataReturnsFalseIfMethodIsAbstract()
+ {
+ $loader = new StaticMethodLoader('loadMetadata');
+ $metadata = new ClassMetadata(__NAMESPACE__.'\AbstractStaticLoaderEntity');
+
+ $this->assertFalse($loader->loadClassMetadata($metadata));
+ }
+
public function testLoadClassMetadata()
{
$loader = new StaticMethodLoader('loadMetadata');
@@ -80,3 +88,8 @@ static public function loadMetadata(ClassMetadata $metadata)
$metadata->addConstraint(new ConstraintA());
}
}
+
+abstract class AbstractStaticLoaderEntity
+{
+ abstract public static function loadMetadata(ClassMetadata $metadata);
+}

0 comments on commit 089188f

Please sign in to comment.