8000 [Validator] catch deprecated methods · loicfrering/symfony@07316c9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 07316c9

Browse files
committed
[Validator] catch deprecated methods
1 parent 92ecff8 commit 07316c9

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

src/Symfony/Component/Validator/Mapping/ClassMetadataFactory.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,20 @@ public function getMetadataFor($value)
7070

7171
// Include constraints from the parent class
7272
if ($parent = $metadata->getReflectionClass()->getParentClass()) {
73+
set_error_handler(array($this, 'handleBC'));
7374
$metadata->mergeConstraints($this->getClassMetadata($parent->name));
75+
restore_error_handler();
7476
}
7577

7678
// Include constraints from all implemented interfaces
79+
set_error_handler(array($this, 'handleBC'));
7780
foreach ($metadata->getReflectionClass()->getInterfaces() as $interface) {
7881
if ('Symfony\Component\Validator\GroupSequenceProviderInterface' === $interface->name) {
7982
continue;
8083
}
8184
$metadata->mergeConstraints($this->getClassMetadata($interface->name));
8285
}
86+
restore_error_handler();
8387

8488
if (null !== $this->loader) {
8589
$this->loader->loadClassMetadata($metadata);
@@ -122,4 +126,16 @@ public function getClassMetadata($class)
122126

123127
return $this->getMetadataFor($class);
124128
}
129+
130+
/**
131+
* @deprecated This is used to keep BC until deprecated methods are removed
132+
*/
133+
public function handleBC($errorNumber, $message, $file, $line, $context)
134+
{
135+
if ($errorNumber & E_USER_DEPRECATED) {
136+
return true;
137+
}
138+
139+
return false;
140+
}
125141
}

src/Symfony/Component/Validator/Mapping/ClassMetadataFactoryAdapter.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ public function __construct(ClassMetadataFactoryInterface $innerFactory)
3838
public function getMetadataFor($value)
3939
{
4040
$class = is_object($value) ? get_class($value) : $value;
41+
set_error_handler(array($this, 'handleBC'));
4142
$metadata = $this->innerFactory->getClassMetadata($class);
43+
restore_error_handler();
4244

4345
if (null === $metadata) {
4446
throw new NoSuchMetadataException('No metadata exists for class '. $class);
@@ -54,6 +56,22 @@ public function hasMetadataFor($value)
5456
{
5557
$class = is_object($value) ? get_class($value) : $value;
5658

57-
return null !== $this->innerFactory->getClassMetadata($class);
59+
set_error_handler(array($this, 'handleBC'));
60+
$return = null !== $this->innerFactory->getClassMetadata($class);
61+
restore_error_handler();
62+
63+
return $return;
64+
}
65+
66+
/**
67+
* @deprecated This is used to keep BC until deprecated methods are removed
68+
*/
69+
public function handleBC($errorNumber, $message, $file, $line, $context)
70+
{
71+
if ($errorNumber & E_USER_DEPRECATED) {
72+
return true;
73+
}
74+
75+
return false;
5876
}
5977
}

src/Symfony/Component/Validator/Tests/Mapping/ClassMetadataFactoryTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,21 @@ class ClassMetadataFactoryTest extends \PHPUnit_Framework_TestCase
2222
const CLASSNAME = 'Symfony\C 8000 omponent\Validator\Tests\Fixtures\Entity';
2323
const PARENTCLASS = 'Symfony\Component\Validator\Tests\Fixtures\EntityParent';
2424

25+
public function handle($errorNumber, $message, $file, $line, $context)
26+
{
27+
if ($errorNumber & E_USER_DEPRECATED) {
28+
return true;
29+
}
30+
31+
return \PHPUnit_Util_ErrorHandler::handleError($errorNumber, $message, $file, $line);
32+
}
33+
2534
public function testLoadClassMetadata()
2635
{
2736
$factory = new ClassMetadataFactory(new TestLoader());
37+
set_error_handler(array($this, 'handle'));
2838
$metadata = $factory->getClassMetadata(self::PARENTCLASS);
39+
restore_error_handler();
2940

3041
$constraints = array(
3142
new ConstraintA(array('groups' => array('Default', 'EntityParent'))),
@@ -37,7 +48,9 @@ public function testLoadClassMetadata()
3748
public function testMergeParentConstraints()
3849
{
3950
$factory = new ClassMetadataFactory(new TestLoader());
51+
set_error_handler(array($this, 'handle'));
4052
$metadata = $factory->getClassMetadata(self::CLASSNAME);
53+
restore_error_handler();
4154

4255
$constraints = array(
4356
new ConstraintA(array('groups' => array(
@@ -81,7 +94,9 @@ public function testWriteMetadataToCache()
8194
$tester->assertEquals($constraints, $metadata->getConstraints());
8295
}));
8396

97+
set_error_handler(array($this, 'handle'));
8498
$metadata = $factory->getClassMetadata(self::PARENTCLASS);
99+
restore_error_handler();
85100

86101
$this->assertEquals(self::PARENTCLASS, $metadata->getClassName());
87102
$this->assertEquals($constraints, $metadata->getConstraints());
@@ -106,7 +121,9 @@ public function testReadMetadataFromCache()
106121
->method('read')
107122
->will($this->returnValue($metadata));
108123

124+
set_error_handler(array($this, 'handle'));
109125
$this->assertEquals($metadata,$factory->getClassMetadata(self::PARENTCLASS));
126+
restore_error_handler();
110127
}
111128
}
112129

0 commit comments

Comments
 (0)
0