Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a9d4beb

Browse filesBrowse files
committed
[Validator] fixed usage of deprecate Validator features
1 parent 1f99a7b commit a9d4beb
Copy full SHA for a9d4beb

File tree

Expand file treeCollapse file tree

8 files changed

+52
-83
lines changed
Filter options
Expand file treeCollapse file tree

8 files changed

+52
-83
lines changed

‎autoload.php.dist

Copy file name to clipboardExpand all lines: autoload.php.dist
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ class DeprecationErrorHandler
4444
$class = isset($trace[$i]['object']) ? get_class($trace[$i]['object']) : $trace[$i]['class'];
4545
$method = $trace[$i]['function'];
4646

47-
$type = 0 === strpos($method, 'testLegacy') || 0 === strpos($method, 'provideLegacy') || strpos($class, '\Legacy') ? 'legacy' : 'remaining';
47+
$type =
48+
0 === strpos($method, 'testLegacy')
49+
|| 0 === strpos($method, 'testSilence')
50+
|| 0 === strpos($method, 'provideLegacy')
51+
|| strpos($class, '\Legacy')
52+
|| strpos(get_parent_class($class), '\AbstractLegacy')
53+
? 'legacy' : 'remaining';
4854

4955
if ('legacy' === $type && 0 === (error_reporting() & E_USER_DEPRECATED)) {
5056
@++$deprecations[$type]['Silenced']['count'];

‎src/Symfony/Component/Validator/Constraints/Callback.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/Callback.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function __construct($options = null)
4848
}
4949

5050
if (is_array($options) && !isset($options['callback']) && !isset($options['methods']) && !isset($options['groups'])) {
51-
if (is_callable($options)) {
51+
if (is_callable($options) || !$options) {
5252
$options = array('callback' => $options);
5353
} else {
5454
// BC with Symfony < 2.4

‎src/Symfony/Component/Validator/Mapping/ClassMetadata.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Mapping/ClassMetadata.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public function accept(ValidationVisitorInterface $visitor, $value, $group, $pro
138138
if (null === $propagatedGroup && Constraint::DEFAULT_GROUP === $group
139139
&& ($this->hasGroupSequence() || $this->isGroupSequenceProvider())) {
140140
if ($this->hasGroupSequence()) {
141-
$groups = $this->getGroupSequence();
141+
$groups = $this->getGroupSequence()->groups;
142142
} else {
143143
$groups = $value->getGroupSequence();
144144
}
@@ -479,7 +479,7 @@ public function setGroupSequence($groupSequence)
479479
*/
480480
public function hasGroupSequence()
481481
{
482-
return count($this->groupSequence) > 0;
482+
return $this->groupSequence && count($this->groupSequence->groups) > 0;
483483
}
484484

485485
/**

‎src/Symfony/Component/Validator/Tests/Constraints/CallbackValidatorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Tests/Constraints/CallbackValidatorTest.php
+23-11Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ protected function createValidator()
5858

5959
public function testNullIsValid()
6060
{
61-
$this->validator->validate(null, new Callback(array('foo')));
61+
$this->validator->validate(null, new Callback());
6262

6363
$this->assertNoViolation();
6464
}
@@ -186,7 +186,7 @@ public function testArrayCallableExplicitName()
186186
}
187187

188188
// BC with Symfony < 2.4
189-
public function testSingleMethodBc()
189+
public function testLegacySingleMethodBc()
190190
{
191191
$object = new CallbackValidatorTest_Object();
192192
$constraint = new Callback(array('validate'));
@@ -199,7 +199,7 @@ public function testSingleMethodBc()
199199
}
200200

201201
// BC with Symfony < 2.4
202-
public function testSingleMethodBcExplicitName()
202+
public function testLegacySingleMethodBcExplicitName()
203203
{
204204
$object = new CallbackValidatorTest_Object();
205205
$constraint = new Callback(array('methods' => array('validate')));
@@ -212,7 +212,7 @@ public function testSingleMethodBcExplicitName()
212212
}
213213

214214
// BC with Symfony < 2.4
215-
public function testMultipleMethodsBc()
215+
public function testLegacyMultipleMethodsBc()
216216
{
217217
$object = new CallbackValidatorTest_Object();
218218
$constraint = new Callback(array('validate', 'validateStatic'));
@@ -227,7 +227,7 @@ public function testMultipleMethodsBc()
227227
}
228228

229229
// BC with Symfony < 2.4
230-
public function testMultipleMethodsBcExplicitName()
230+
public function testLegacyMultipleMethodsBcExplicitName()
231231
{
232232
$object = new CallbackValidatorTest_Object();
233233
$constraint = new Callback(array(
@@ -244,7 +244,7 @@ public function testMultipleMethodsBcExplicitName()
244244
}
245245

246246
// BC with Symfony < 2.4
247-
public function testSingleStaticMethodBc()
247+
public function testLegacySingleStaticMethodBc()
248248
{
249249
$object = new CallbackValidatorTest_Object();
250250
$constraint = new Callback(array(
@@ -259,7 +259,7 @@ public function testSingleStaticMethodBc()
259259
}
260260

261261
// BC with Symfony < 2.4
262-
public function testSingleStaticMethodBcExplicitName()
262+
public function testLegacySingleStaticMethodBcExplicitName()
263263
{
264264
$object = new CallbackValidatorTest_Object();
265265
$constraint = new Callback(array(
@@ -276,8 +276,14 @@ public function testSingleStaticMethodBcExplicitName()
276276
/**
277277
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
278278
*/
279-
public function testExpectValidMethods()
279+
public function testSilenceExpectValidMethods()
280280
{
281+
// as the callback does not exist, which is what we want to test
282+
// the Callback fallbacks to populate the deprecated method
283+
// so, we need to silence it here
284+
// this iniSet call should be simply removed in 3.0
285+
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
286+
281287
$object = new CallbackValidatorTest_Object();
282288

283289
$this->validator->validate($object, new Callback(array('foobar')));
@@ -286,8 +292,14 @@ public function testExpectValidMethods()
286292
/**
287293
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
288294
*/
289-
public function testExpectValidCallbacks()
295+
public function testSilenceExpectValidCallbacks()
290296
{
297+
// as the callback does not exist, which is what we want to test
298+
// the Callback fallbacks to populate the deprecated method
299+
// so, we need to silence it here
300+
// this iniSet call should be simply removed in 3.0
301+
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
302+
291303
$object = new CallbackValidatorTest_Object();
292304

293305
$this->validator->validate($object, new Callback(array(array('foo', 'bar'))));
@@ -296,7 +308,7 @@ public function testExpectValidCallbacks()
296308
/**
297309
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
298310
*/
299-
public function testExpectEitherCallbackOrMethods()
311+
public function testLegacyExpectEitherCallbackOrMethods()
300312
{
301313
$object = new CallbackValidatorTest_Object();
302314

@@ -308,7 +320,7 @@ public function testExpectEitherCallbackOrMethods()
308320

309321
public function testConstraintGetTargets()
310322
{
311-
$constraint = new Callback(array('foo'));
323+
$constraint = new Callback(array());
312324
$targets = array(Constraint::CLASS_CONSTRAINT, Constraint::PROPERTY_CONSTRAINT);
313325

314326
$this->assertEquals($targets, $constraint->getTargets());

‎src/Symfony/Component/Validator/Tests/Constraints/GroupSequenceTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Tests/Constraints/GroupSequenceTest.php
+15-5Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,28 @@ public function testCreateDoctrineStyle()
3232
$this->assertSame(array('Group 1', 'Group 2'), $sequence->groups);
3333
}
3434

35-
public function testIterate()
35+
public function testLegacyIterate()
3636
{
37+
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
38+
3739
$sequence = new GroupSequence(array('Group 1', 'Group 2'));
3840

3941
$this->assertSame(array('Group 1', 'Group 2'), iterator_to_array($sequence));
4042
}
4143

42-
public function testCount()
44+
public function testLegacyCount()
4345
{
46+
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
47+
4448
$sequence = new GroupSequence(array('Group 1', 'Group 2'));
4549

4650
$this->assertCount(2, $sequence);
4751
}
4852

49-
public function testArrayAccess()
53+
public function testLegacyArrayAccess()
5054
{
55+
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
56+
5157
$sequence = new GroupSequence(array('Group 1', 'Group 2'));
5258

5359
$this->assertSame('Group 1', $sequence[0]);
@@ -67,15 +73,19 @@ public function testArrayAccess()
6773
/**
6874
* @expectedException \Symfony\Component\Validator\Exception\OutOfBoundsException
6975
*/
70-
public function testGetExpectsExistingKey()
76+
public function testLegacyGetExpectsExistingKey()
7177
{
78+
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
79+
7280
$sequence = new GroupSequence(array('Group 1', 'Group 2'));
7381

7482
$sequence[2];
7583
}
7684

77-
public function testUnsetIgnoresNonExistingKeys()
85+
public function testLegacyUnsetIgnoresNonExistingKeys()
7886
{
87+
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
88+
7989
$sequence = new GroupSequence(array('Group 1', 'Group 2'));
8090

8191
// should not fail

‎src/Symfony/Component/Validator/Tests/Mapping/MemberMetadataTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Tests/Mapping/MemberMetadataTest.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,16 @@ public function testSerialize()
7272

7373
public function testSerializeCollectionCascaded()
7474
{
75-
$this->metadata->addConstraint(new Valid(array('traverse' => true, 'deep' => false)));
75+
$this->metadata->addConstraint(new Valid(array('traverse' => true)));
7676

7777
$metadata = unserialize(serialize($this->metadata));
7878

7979
$this->assertEquals($this->metadata, $metadata);
8080
}
8181

82-
public function testSerializeCollectionCascadedDeeply()
82+
public function testLegacySerializeCollectionCascadedDeeply()
8383
{
84-
$this->metadata->addConstraint(new Valid(array('traverse' => true, 'deep' => true)));
84+
$this->metadata->addConstraint(new Valid(array('traverse' => true)));
8585

8686
$metadata = unserialize(serialize($this->metadata));
8787

‎src/Symfony/Component/Validator/Tests/Validator/Abstract2Dot5ApiTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Tests/Validator/Abstract2Dot5ApiTest.php
-59Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -506,65 +506,6 @@ public function testReferenceTraversalDisabledOnReferenceEnabledOnClass()
506506
$this->assertCount(0, $violations);
507507
}
508508

509-
public function testReferenceTraversalRecursionEnabledOnReferenceTraversalEnabledOnClass()
510-
{
511-
$entity = new Entity();
512-
$entity->reference = new \ArrayIterator(array(
513-
2 => new \ArrayIterator(array('key' => new Reference())),
514-
));
515-
516-
$callback = function ($value, ExecutionContextInterface $context) {
517-
$context->addViolation('Message');
518-
};
519-
520-
$traversableMetadata = new ClassMetadata('ArrayIterator');
521-
$traversableMetadata->addConstraint(new Traverse(true));
522-
523-
$this->metadataFactory->addMetadata($traversableMetadata);
524-
$this->referenceMetadata->addConstraint(new Callback(array(
525-
'callback' => $callback,
526-
'groups' => 'Group',
527-
)));
528-
$this->metadata->addPropertyConstraint('reference', new Valid(array(
529-
'deep' => true,
530-
)));
531-
532-
$violations = $this->validate($entity, new Valid(), 'Group');
533-
534-
/** @var ConstraintViolationInterface[] $violations */
535-
$this->assertCount(1, $violations);
536-
}
537-
538-
public function testReferenceTraversalRecursionDisabledOnReferenceTraversalEnabledOnClass()
539-
{
540-
$test = $this;
541-
$entity = new Entity();
542-
$entity->reference = new \ArrayIterator(array(
543-
2 => new \ArrayIterator(array('key' => new Reference())),
544-
));
545-
546-
$callback = function ($value, ExecutionContextInterface $context) use ($test) {
547-
$test->fail('Should not be called');
548-
};
549-
550-
$traversableMetadata = new ClassMetadata('ArrayIterator');
551-
$traversableMetadata->addConstraint(new Traverse(true));
552-
553-
$this->metadataFactory->addMetadata($traversableMetadata);
554-
$this->referenceMetadata->addConstraint(new Callback(array(
555-
'callback' => $callback,
556-
'groups' => 'Group',
557-
)));
558-
$this->metadata->addPropertyConstraint('reference', new Valid(array(
559-
'deep' => false,
560-
)));
561-
562-
$violations = $this->validate($entity, new Valid(), 'Group');
563-
564-
/** @var ConstraintViolationInterface[] $violations */
565-
$this->assertCount(0, $violations);
566-
}
567-
568509
public function testAddCustomizedViolation()
569510
{
570511
$entity = new Entity();

‎src/Symfony/Component/Validator/Tests/Validator/AbstractValidatorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Tests/Validator/AbstractValidatorTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ public function testEnableRecursiveTraversableTraversal()
766766
};
767767

768768
$this->metadata->addPropertyConstraint('reference', new Valid(array(
769-
'deep' => true,
769+
'traverse' => true,
770770
)));
771771
$this->referenceMetadata->addConstraint(new Callback(array(
772772
'callback' => $callback,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.