Skip to content

Commit 9e8b2f0

Browse files
committed
[Validator] fixed broken tests
1 parent a1616ef commit 9e8b2f0

17 files changed

+190
-42
lines changed

src/Symfony/Component/Validator/Tests/Constraints/MaxLengthValidatorTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,30 @@ class MaxLengthValidatorTest extends \PHPUnit_Framework_TestCase
2121

2222
protected function setUp()
2323
{
24+
set_error_handler(array($this, "deprecationErrorHandler"));
25+
2426
$this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false);
2527
$this->validator = new MaxLengthValidator();
2628
$this->validator->initialize($this->context);
2729
}
2830

2931
protected function tearDown()
3032
{
33+
restore_error_handler();
34+
3135
$this->context = null;
3236
$this->validator = null;
3337
}
3438

39+
public function deprecationErrorHandler($errorNumber, $message, $file, $line, $context)
40+
{
41+
if ($errorNumber & E_USER_DEPRECATED) {
42+
return true;
43+
}
44+
45+
return \PHPUnit_Util_ErrorHandler::handleError($errorNumber, $message, $file, $line);
46+
}
47+
3548
public function testNullIsValid()
3649
{
3750
$this->context->expects($this->never())

src/Symfony/Component/Validator/Tests/Constraints/MaxValidatorTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,30 @@ class MaxValidatorTest extends \PHPUnit_Framework_TestCase
2121

2222
protected function setUp()
2323
{
24+
set_error_handler(array($this, "deprecationErrorHandler"));
25+
2426
$this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false);
2527
$this->validator = new MaxValidator();
2628
$this->validator->initialize($this->context);
2729
}
2830

2931
protected function tearDown()
3032
{
33+
restore_error_handler();
34+
3135
$this->context = null;
3236
$this->validator = null;
3337
}
3438

39+
public function deprecationErrorHandler($errorNumber, $message, $file, $line, $context)
40+
{
41+
if ($errorNumber & E_USER_DEPRECATED) {
42+
return true;
43+
}
44+
45+
return \PHPUnit_Util_ErrorHandler::handleError($errorNumber, $message, $file, $line);
46+
}
47+
3548
public function testNullIsValid()
3649
{
3750
$this->context->expects($this->never())

src/Symfony/Component/Validator/Tests/Constraints/MinLengthValidatorTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,30 @@ class MinLengthValidatorTest extends \PHPUnit_Framework_TestCase
2121

2222
protected function setUp()
2323
{
24+
set_error_handler(array($this, "deprecationErrorHandler"));
25+
2426
$this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false);
2527
$this->validator = new MinLengthValidator();
2628
$this->validator->initialize($this->context);
2729
}
2830

2931
protected function tearDown()
3032
{
33+
restore_error_handler();
34+
3135
$this->context = null;
3236
$this->validator = null;
3337
}
3438

39+
public function deprecationErrorHandler($errorNumber, $message, $file, $line, $context)
40+
{
41+
if ($errorNumber & E_USER_DEPRECATED) {
42+
return true;
43+
}
44+
45+
return \PHPUnit_Util_ErrorHandler::handleError($errorNumber, $message, $file, $line);
46+
}
47+
3548
public function testNullIsValid()
3649
{
3750
$this->context->expects($this->never())

src/Symfony/Component/Validator/Tests/Constraints/MinValidatorTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,27 @@ class MinValidatorTest extends \PHPUnit_Framework_TestCase
2121

2222
protected function setUp()
2323
{
24+
set_error_handler(array($this, "deprecationErrorHandler"));
25+
2426
$this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false);
2527
$this->validator = new MinValidator();
2628
$this->validator->initialize($this->context);
2729
}
2830

31+
protected function tearDown()
32+
{
33+
restore_error_handler();
34+
}
35+
36+
public function deprecationErrorHandler($errorNumber, $message, $file, $line, $context)
37+
{
38+
if ($errorNumber & E_USER_DEPRECATED) {
39+
return true;
40+
}
41+
42+
return \PHPUnit_Util_ErrorHandler::handleError($errorNumber, $message, $file, $line);
43+
}
44+
2945
public function testNullIsValid()
3046
{
3147
$this->context->expects($this->never())

src/Symfony/Component/Validator/Tests/ExecutionContextTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ protected function tearDown()
6464
$this->context = null;
6565
}
6666

67+
public function deprecationErrorHandler($errorNumber, $message, $file, $line, $context)
68+
{
69+
if ($errorNumber & E_USER_DEPRECATED) {
70+
return true;
71+
}
72+
73+
return \PHPUnit_Util_ErrorHandler::handleError($errorNumber, $message, $file, $line);
74+
}
75+
6776
public function testInit()
6877
{
6978
$this->assertCount(0, $this->context->getViolations());
@@ -76,30 +85,36 @@ public function testInit()
7685
->will($this->returnValue('GRAPHWALKER'));
7786

7887
// BC
88+
set_error_handler(array($this, "deprecationErrorHandler"));
7989
$this->assertNull($this->context->getCurrentClass());
8090
$this->assertNull($this->context->getCurrentProperty());
8191
$this->assertSame('GRAPHWALKER', $this->context->getGraphWalker());
8292
$this->assertSame($this->metadataFactory, $this->context->getMetadataFactory());
93+
restore_error_handler();
8394
}
8495

8596
public function testInitWithClassMetadata()
8697
{
8798
// BC
99+
set_error_handler(array($this, "deprecationErrorHandler"));
88100
$this->metadata = new ClassMetadata(__NAMESPACE__ . '\ExecutionContextTest_TestClass');
89101
$this->context = new ExecutionContext($this->globalContext, $this->translator, self::TRANS_DOMAIN, $this->metadata, 'currentValue', 'Group', 'foo.bar');
90102

91103
$this->assertSame(__NAMESPACE__ . '\ExecutionContextTest_TestClass', $this->context->getCurrentClass());
92104
$this->assertNull($this->context->getCurrentProperty());
105+
restore_error_handler();
93106
}
94107

95108
public function testInitWithPropertyMetadata()
96109
{
97110
// BC
111+
set_error_handler(array($this, "deprecationErrorHandler"));
98112
$this->metadata = new PropertyMetadata(__NAMESPACE__ . '\ExecutionContextTest_TestClass', 'myProperty');
99113
$this->context = new ExecutionContext($this->globalContext, $this->translator, self::TRANS_DOMAIN, $this->metadata, 'currentValue', 'Group', 'foo.bar');
100114

101115
$this->assertSame(__NAMESPACE__ . '\ExecutionContextTest_TestClass', $this->context->getCurrentClass());
102116
$this->assertSame('myProperty', $this->context->getCurrentProperty());
117+
restore_error_handler();
103118
}
104119

105120
public function testClone()
@@ -199,7 +214,9 @@ public function testAddViolationAtPath()
199214
->will($this->returnValue('Translated error'));
200215

201216
// override preconfigured property path
217+
set_error_handler(array($this, "deprecationErrorHandler"));
202218
$this->context->addViolationAtPath('bar.baz', 'Error', array('foo' => 'bar'), 'invalid');
219+
restore_error_handler();
203220

204221
$this->assertEquals(new ConstraintViolationList(array(
205222
new ConstraintViolation(
@@ -220,7 +237,9 @@ public function testAddViolationAtPathUsesPreconfiguredValueIfNotPassed()
220237
->with('Error', array())
221238
->will($this->returnValue('Translated error'));
222239

240+
set_error_handler(array($this, "deprecationErrorHandler"));
223241
$this->context->addViolationAtPath('bar.baz', 'Error');
242+
restore_error_handler();
224243

225244
$this->assertEquals(new ConstraintViolationList(array(
226245
new ConstraintViolation(
@@ -246,8 +265,10 @@ public function testAddViolationAtPathUsesPassedNullValue()
246265
->will($this->returnValue('Translated choice error'));
247266

248267
// passed null value should override preconfigured value "invalid"
268+
set_error_handler(array($this, "deprecationErrorHandler"));
249269
$this->context->addViolationAtPath('bar.baz', 'Error', array('foo' => 'bar'), null);
250270
$this->context->addViolationAtPath('bar.baz', 'Choice error', array('foo' => 'bar'), null, 3);
271+
restore_error_handler();
251272

252273
$this->assertEquals(new ConstraintViolationList(array(
253274
new ConstraintViolation(
@@ -278,7 +299,9 @@ public function testAddViolationAt()
278299
->will($this->returnValue('Translated error'));
279300

280301
// override preconfigured property path
302+
set_error_handler(array($this, "deprecationErrorHandler"));
281303
$this->context->addViolationAt('bam.baz', 'Error', array('foo' => 'bar'), 'invalid');
304+
restore_error_handler();
282305

283306
$this->assertEquals(new ConstraintViolationList(array(
284307
new ConstraintViolation(
@@ -299,7 +322,9 @@ public function testAddViolationAtUsesPreconfiguredValueIfNotPassed()
299322
->with('Error', array())
300323
->will($this->returnValue('Translated error'));
301324

325+
set_error_handler(array($this, "deprecationErrorHandler"));
302326
$this->context->addViolationAt('bam.baz', 'Error');
327+
restore_error_handler();
303328

304329
$this->assertEquals(new ConstraintViolationList(array(
305330
new ConstraintViolation(
@@ -325,8 +350,10 @@ public function testAddViolationAtUsesPassedNullValue()
325350
->will($this->returnValue('Translated choice error'));
326351

327352
// passed null value should override preconfigured value "invalid"
353+
set_error_handler(array($this, "deprecationErrorHandler"));
328354
$this->context->addViolationAt('bam.baz', 'Error', array('foo' => 'bar'), null);
329355
$this->context->addViolationAt('bam.baz', 'Choice error', array('foo' => 'bar'), null, 2);
356+
restore_error_handler();
330357

331358
$this->assertEquals(new ConstraintViolationList(array(
332359
new ConstraintViolation(

src/Symfony/Component/Validator/Tests/Fixtures/Entity.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ class Entity extends EntityParent implements EntityInterface
2121
{
2222
/**
2323
* @Assert\NotNull
24-
* @Assert\Min(3)
25-
* @Assert\All({@Assert\NotNull, @Assert\Min(3)}),
26-
* @Assert\All(constraints={@Assert\NotNull, @Assert\Min(3)})
24+
* @Assert\Range(min=3)
25+
* @Assert\All({@Assert\NotNull, @Assert\Range(min=3)}),
26+
* @Assert\All(constraints={@Assert\NotNull, @Assert\Range(min=3)})
2727
* @Assert\Collection(fields={
28-
* "foo" = {@Assert\NotNull, @Assert\Min(3)},
29-
* "bar" = @Assert\Min(5)
28+
* "foo" = {@Assert\NotNull, @Assert\Range(min=3)},
29+
* "bar" = @Assert\Range(min=5)
3030
* })
3131
* @Assert\Choice(choices={"A", "B"}, message="Must be one of %choices%")
3232
*/

src/Symfony/Component/Validator/Tests/GraphWalkerTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class GraphWalkerTest extends \PHPUnit_Framework_TestCase
5353

5454
protected function setUp()
5555
{
56+
set_error_handler(array($this, "deprecationErrorHandler"));
57+
5658
$this->metadataFactory = new FakeMetadataFactory();
5759
$this->visitor = new ValidationVisitor('Root', $this->metadataFactory, new ConstraintValidatorFactory(), new DefaultTranslator());
5860
$this->walker = $this->visitor->getGraphWalker();
@@ -62,12 +64,23 @@ protected function setUp()
6264

6365
protected function tearDown()
6466
{
67+
restore_error_handler();
68+
6569
$this->metadataFactory = null;
6670
$this->visitor = null;
6771
$this->walker = null;
6872
$this->metadata = null;
6973
}
7074

75+
public function deprecationErrorHandler($errorNumber, $message, $file, $line, $context)
76+
{
77+
if ($errorNumber & E_USER_DEPRECATED) {
78+
return true;
79+
}
80+
81+
return \PHPUnit_Util_ErrorHandler::handleError($errorNumber, $message, $file, $line);
82+
}
83+
7184
public function testWalkObjectPassesCorrectClassAndProperty()
7285
{
7386
$this->metadata->addConstraint(new ConstraintA());

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ public function testInvalidPropertyName()
2525
new GetterMetadata(self::CLASSNAME, 'foobar');
2626
}
2727

28-
public function testGetValueFromPublicGetter()
28+
public function testGetPropertyValueFromPublicGetter()
2929
{
3030
// private getters don't work yet because ReflectionMethod::setAccessible()
3131
// does not exists yet in a stable PHP release
3232

3333
$entity = new Entity('foobar');
3434
$metadata = new GetterMetadata(self::CLASSNAME, 'internal');
3535

36-
$this->assertEquals('foobar from getter', $metadata->getValue($entity));
36+
$this->assertEquals('foobar from getter', $metadata->getPropertyValue($entity));
3737
}
3838
}

src/Symfony/Component/Validator/Tests/Mapping/Loader/AnnotationLoaderTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use Symfony\Component\Validator\Constraints\All;
1616
use Symfony\Component\Validator\Constraints\Collection;
1717
use Symfony\Component\Validator\Constraints\NotNull;
18-
use Symfony\Component\Validator\Constraints\Min;
18+
use Symfony\Component\Validator\Constraints\Range;
1919
use Symfony\Component\Validator\Constraints\Choice;
2020
use Symfony\Component\Validator\Mapping\ClassMetadata;
2121
use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader;
@@ -58,12 +58,12 @@ public function testLoadClassMetadata()
5858
$expected->setGroupSequence(array('Foo', 'Entity'));
5959
$expected->addConstraint(new ConstraintA());
6060
$expected->addPropertyConstraint('firstName', new NotNull());
61-
$expected->addPropertyConstraint('firstName', new Min(3));
62-
$expected->addPropertyConstraint('firstName', new All(array(new NotNull(), new Min(3))));
63-
$expected->addPropertyConstraint('firstName', new All(array('constraints' => array(new NotNull(), new Min(3)))));
61+
$expected->addPropertyConstraint('firstName', new Range(array('min' => 3)));
62+
$expected->addPropertyConstraint('firstName', new All(array(new NotNull(), new Range(array('min' => 3)))));
63+
$expected->addPropertyConstraint('firstName', new All(array('constraints' => array(new NotNull(), new Range(array('min' => 3))))));
6464
$expected->addPropertyConstraint('firstName', new Collection(array('fields' => array(
65-
'foo' => array(new NotNull(), new Min(3)),
66-
'bar' => new Min(5),
65+
'foo' => array(new NotNull(), new Range(array('min' => 3))),
66+
'bar' => new Range(array('min' => 5)),
6767
))));
6868
$expected->addPropertyConstraint('firstName', new Choice(array(
6969
'message' => 'Must be one of %choices%',
@@ -122,12 +122,12 @@ public function testLoadClassMetadataAndMerge()
122122
$expected->setGroupSequence(array('Foo', 'Entity'));
123123
$expected->addConstraint(new ConstraintA());
124124
$expected->addPropertyConstraint('firstName', new NotNull());
125-
$expected->addPropertyConstraint('firstName', new Min(3));
126-
$expected->addPropertyConstraint('firstName', new All(array(new NotNull(), new Min(3))));
127-
$expected->addPropertyConstraint('firstName', new All(array('constraints' => array(new NotNull(), new Min(3)))));
125+
$expected->addPropertyConstraint('firstName', new Range(array('min' => 3)));
126+
$expected->addPropertyConstraint('firstName', new All(array(new NotNull(), new Range(array('min' => 3)))));
127+
$expected->addPropertyConstraint('firstName', new All(array('constraints' => array(new NotNull(), new Range(array('min' => 3))))));
128128
$expected->addPropertyConstraint('firstName', new Collection(array('fields' => array(
129-
'foo' => array(new NotNull(), new Min(3)),
130-
'bar' => new Min(5),
129+
'foo' => array(new NotNull(), new Range(array('min' => 3))),
130+
'bar' => new Range(array('min' => 5)),
131131
))));
132132
$expected->addPropertyConstraint('firstName', new Choice(array(
133133
'message' => 'Must be one of %choices%',

src/Symfony/Component/Validator/Tests/Mapping/Loader/XmlFileLoaderTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Symfony\Component\Validator\Constraints\All;
1515
use Symfony\Component\Validator\Constraints\Collection;
1616
use Symfony\Component\Validator\Constraints\NotNull;
17-
use Symfony\Component\Validator\Constraints\Min;
17+
use Symfony\Component\Validator\Constraints\Range;
1818
use Symfony\Component\Validator\Constraints\Choice;
1919
use Symfony\Component\Validator\Mapping\ClassMetadata;
2020
use Symfony\Component\Validator\Mapping\Loader\XmlFileLoader;
@@ -51,13 +51,13 @@ public function testLoadClassMetadata()
5151
$expected->addConstraint(new ConstraintA());
5252
$expected->addConstraint(new ConstraintB());
5353
$expected->addPropertyConstraint('firstName', new NotNull());
54-
$expected->addPropertyConstraint('firstName', new Min(3));
54+
$expected->addPropertyConstraint('firstName', new Range(array('min' => 3)));
5555
$expected->addPropertyConstraint('firstName', new Choice(array('A', 'B')));
56-
$expected->addPropertyConstraint('firstName', new All(array(new NotNull(), new Min(3))));
57-
$expected->addPropertyConstraint('firstName', new All(array('constraints' => array(new NotNull(), new Min(3)))));
56+
$expected->addPropertyConstraint('firstName', new All(array(new NotNull(), new Range(array('min' => 3)))));
57+
$expected->addPropertyConstraint('firstName', new All(array('constraints' => array(new NotNull(), new Range(array('min' => 3))))));
5858
$expected->addPropertyConstraint('firstName', new Collection(array('fields' => array(
59-
'foo' => array(new NotNull(), new Min(3)),
60-
'bar' => array(new Min(5)),
59+
'foo' => array(new NotNull(), new Range(array('min' => 3))),
60+
'bar' => array(new Range(array('min' => 5))),
6161
))));
6262
$expected->addPropertyConstraint('firstName', new Choice(array(
6363
'message' => 'Must be one of %choices%',

0 commit comments

Comments
 (0)