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:
Fabien Potencier 2013-08-13 09:37:59 +02:00
commit cb14afca40
3 changed files with 32 additions and 2 deletions

View File

@ -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));
}

View File

@ -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);
}

View File

@ -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());
}
}