[Validator] fixed the static method loader to not repeat the loading when the static method is in the parent classes
This commit is contained in:
parent
c8c9fba7d9
commit
984a857a96
@ -37,6 +37,10 @@ class StaticMethodLoader implements LoaderInterface
|
||||
throw new MappingException(sprintf('The method %s::%s should be static', $reflClass->getName(), $this->methodName));
|
||||
}
|
||||
|
||||
if ($reflMethod->getDeclaringClass()->getName() != $reflClass->getName()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$reflMethod->invoke(null, $metadata);
|
||||
|
||||
return true;
|
||||
@ -44,4 +48,4 @@ class StaticMethodLoader implements LoaderInterface
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ namespace Symfony\Tests\Component\Validator\Mapping\Loader;
|
||||
|
||||
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
||||
use Symfony\Component\Validator\Mapping\Loader\StaticMethodLoader;
|
||||
use Symfony\Component\Validator\Constraints\NotNull;
|
||||
|
||||
class StaticMethodLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
@ -32,6 +33,19 @@ class StaticMethodLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$this->assertEquals(StaticLoaderEntity::$invokedWith, $metadata);
|
||||
}
|
||||
|
||||
public function testLoadClassMetadataDoesNotRepeatLoadWithParentClasses()
|
||||
{
|
||||
$loader = new StaticMethodLoader('loadMetadata');
|
||||
$metadata = new ClassMetadata(__NAMESPACE__.'\StaticLoaderDocument');
|
||||
$loader->loadClassMetadata($metadata);
|
||||
$this->assertSame(0, count($metadata->getConstraints()));
|
||||
|
||||
$loader = new StaticMethodLoader('loadMetadata');
|
||||
$metadata = new ClassMetadata(__NAMESPACE__.'\BaseStaticLoaderDocument');
|
||||
$loader->loadClassMetadata($metadata);
|
||||
$this->assertSame(1, count($metadata->getConstraints()));
|
||||
}
|
||||
}
|
||||
|
||||
class StaticLoaderEntity
|
||||
@ -43,3 +57,15 @@ class StaticLoaderEntity
|
||||
self::$invokedWith = $metadata;
|
||||
}
|
||||
}
|
||||
|
||||
class StaticLoaderDocument extends BaseStaticLoaderDocument
|
||||
{
|
||||
}
|
||||
|
||||
class BaseStaticLoaderDocument
|
||||
{
|
||||
static public function loadMetadata(ClassMetadata $metadata)
|
||||
{
|
||||
$metadata->addConstraint(new NotNull());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user