merged branch marcj/ticket_8589 (PR #8728)
This PR was merged into the 2.2 branch.
Discussion
----------
[Validator] Fixed the wrong isAbstract() call in PR #8592
| 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
-------
18896d5a
[Validator] fixed the wrong isAbstract() check against the class (fixed #8589)
This commit is contained in:
commit
cb14afca40
@ -31,9 +31,13 @@ class StaticMethodLoader implements LoaderInterface
|
|||||||
/** @var \ReflectionClass $reflClass */
|
/** @var \ReflectionClass $reflClass */
|
||||||
$reflClass = $metadata->getReflectionClass();
|
$reflClass = $metadata->getReflectionClass();
|
||||||
|
|
||||||
if (!$reflClass->isInterface() && !$reflClass->isAbstract() && $reflClass->hasMethod($this->methodName)) {
|
if (!$reflClass->isInterface() && $reflClass->hasMethod($this->methodName)) {
|
||||||
$reflMethod = $reflClass->getMethod($this->methodName);
|
$reflMethod = $reflClass->getMethod($this->methodName);
|
||||||
|
|
||||||
|
if ($reflMethod->isAbstract()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!$reflMethod->isStatic()) {
|
if (!$reflMethod->isStatic()) {
|
||||||
throw new MappingException(sprintf('The method %s::%s should be static', $reflClass->name, $this->methodName));
|
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());
|
$this->assertCount(0, $metadata->getConstraints());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLoadClassMetadataIgnoresAbstractClasses()
|
public function testLoadClassMetadataInAbstractClasses()
|
||||||
{
|
{
|
||||||
$loader = new StaticMethodLoader('loadMetadata');
|
$loader = new StaticMethodLoader('loadMetadata');
|
||||||
$metadata = new ClassMetadata(__NAMESPACE__.'\AbstractStaticLoader');
|
$metadata = new ClassMetadata(__NAMESPACE__.'\AbstractStaticLoader');
|
||||||
|
|
||||||
$loader->loadClassMetadata($metadata);
|
$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());
|
$this->assertCount(0, $metadata->getConstraints());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -86,6 +101,7 @@ abstract class AbstractStaticLoader
|
|||||||
{
|
{
|
||||||
public static function loadMetadata(ClassMetadata $metadata)
|
public static function loadMetadata(ClassMetadata $metadata)
|
||||||
{
|
{
|
||||||
|
$metadata->addConstraint(new ConstraintA());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user