[Validator] fixed the wrong isAbstract() check against the class (fixed #8589)

This commit is contained in:
marcj 2013-08-12 23:30:49 +02:00
parent 36e4b8c1c2
commit 18896d5a9e
3 changed files with 32 additions and 2 deletions

View File

@ -31,9 +31,13 @@ class StaticMethodLoader implements LoaderInterface
/** @var \ReflectionClass $reflClass */
$reflClass = $metadata->getReflectionClass();
if (!$reflClass->isInterface() && !$reflClass->isAbstract() && $reflClass->hasMethod($this->methodName)) {
if (!$reflClass->isInterface() && $reflClass->hasMethod($this->methodName)) {
$reflMethod = $reflClass->getMethod($this->methodName);
if ($reflMethod->isAbstract()) {
return false;
}
if (!$reflMethod->isStatic()) {
throw new MappingException(sprintf('The method %s::%s should be static', $reflClass->name, $this->methodName));
}

View File

@ -0,0 +1,10 @@
<?php
namespace Symfony\Component\Validator\Tests\Mapping\Loader;
use Symfony\Component\Validator\Mapping\ClassMetadata;
abstract class AbstractMethodStaticLoader
{
abstract public static function loadMetadata(ClassMetadata $metadata);
}

View File

@ -66,13 +66,28 @@ class StaticMethodLoaderTest extends \PHPUnit_Framework_TestCase
$this->assertCount(0, $metadata->getConstraints());
}
public function testLoadClassMetadataIgnoresAbstractClasses()
public function testLoadClassMetadataInAbstractClasses()
{
$loader = new StaticMethodLoader('loadMetadata');
$metadata = new ClassMetadata(__NAMESPACE__.'\AbstractStaticLoader');
$loader->loadClassMetadata($metadata);
$this->assertCount(1, $metadata->getConstraints());
}
public function testLoadClassMetadataIgnoresAbstractMethods()
{
$loader = new StaticMethodLoader('loadMetadata');
try {
include __DIR__ . '/AbstractMethodStaticLoader.php';
$this->fail('AbstractMethodStaticLoader should produce a strict standard error.');
} catch (\Exception $e) {
}
$metadata = new ClassMetadata(__NAMESPACE__.'\AbstractMethodStaticLoader');
$loader->loadClassMetadata($metadata);
$this->assertCount(0, $metadata->getConstraints());
}
}
@ -86,6 +101,7 @@ abstract class AbstractStaticLoader
{
public static function loadMetadata(ClassMetadata $metadata)
{
$metadata->addConstraint(new ConstraintA());
}
}