[Validator] fixed StaticMethodLoader trying to invoke methods of abstract classes (closes #8589)
This commit is contained in:
parent
63ef3c1901
commit
b41cf82651
@ -31,7 +31,7 @@ class StaticMethodLoader implements LoaderInterface
|
||||
/** @var \ReflectionClass $reflClass */
|
||||
$reflClass = $metadata->getReflectionClass();
|
||||
|
||||
if (!$reflClass->isInterface() && $reflClass->hasMethod($this->methodName)) {
|
||||
if (!$reflClass->isInterface() && !$reflClass->isAbstract() && $reflClass->hasMethod($this->methodName)) {
|
||||
$reflMethod = $reflClass->getMethod($this->methodName);
|
||||
|
||||
if (!$reflMethod->isStatic()) {
|
||||
|
@ -48,12 +48,12 @@ class StaticMethodLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$loader = new StaticMethodLoader('loadMetadata');
|
||||
$metadata = new ClassMetadata(__NAMESPACE__.'\StaticLoaderDocument');
|
||||
$loader->loadClassMetadata($metadata);
|
||||
$this->assertSame(0, count($metadata->getConstraints()));
|
||||
$this->assertCount(0, $metadata->getConstraints());
|
||||
|
||||
$loader = new StaticMethodLoader('loadMetadata');
|
||||
$metadata = new ClassMetadata(__NAMESPACE__.'\BaseStaticLoaderDocument');
|
||||
$loader->loadClassMetadata($metadata);
|
||||
$this->assertSame(1, count($metadata->getConstraints()));
|
||||
$this->assertCount(1, $metadata->getConstraints());
|
||||
}
|
||||
|
||||
public function testLoadClassMetadataIgnoresInterfaces()
|
||||
@ -63,7 +63,17 @@ class StaticMethodLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$loader->loadClassMetadata($metadata);
|
||||
|
||||
$this->assertSame(0, count($metadata->getConstraints()));
|
||||
$this->assertCount(0, $metadata->getConstraints());
|
||||
}
|
||||
|
||||
public function testLoadClassMetadataIgnoresAbstractClasses()
|
||||
{
|
||||
$loader = new StaticMethodLoader('loadMetadata');
|
||||
$metadata = new ClassMetadata(__NAMESPACE__.'\AbstractStaticLoader');
|
||||
|
||||
$loader->loadClassMetadata($metadata);
|
||||
|
||||
$this->assertCount(0, $metadata->getConstraints());
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,6 +82,13 @@ interface StaticLoaderInterface
|
||||
public static function loadMetadata(ClassMetadata $metadata);
|
||||
}
|
||||
|
||||
abstract class AbstractStaticLoader
|
||||
{
|
||||
public static function loadMetadata(ClassMetadata $metadata)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class StaticLoaderEntity
|
||||
{
|
||||
public static $invokedWith = null;
|
||||
|
Reference in New Issue
Block a user