[Validator] fixed the wrong isAbstract() check against the class (fixed #8589)
This commit is contained in:
parent
36e4b8c1c2
commit
18896d5a9e
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Reference in New Issue