merged branch fabpot/validator-abstract-fix (PR #8592)
This PR was merged into the 2.2 branch.
Discussion
----------
[Validator] Fixed StaticMethodLoader does not try to invoke methods of abstract classes anymore
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #8589
| License | MIT
| Doc PR | n/a
Commits
-------
b41cf82
[Validator] fixed StaticMethodLoader trying to invoke methods of abstract classes (closes #8589)
This commit is contained in:
commit
bf260d7d64
@ -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