Skip to content

Commit bbd656b

Browse files
committed
[Validator] remove deprecated features
1 parent d3449e6 commit bbd656b

File tree

6 files changed

+19
-81
lines changed

6 files changed

+19
-81
lines changed

src/Symfony/Component/Validator/CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
CHANGELOG
22
=========
33

4+
4.0.0
5+
-----
6+
7+
* Setting the `strict` option of the `Choice` constraint to anything but `true`
8+
is not supported anymore.
9+
* removed the `DateTimeValidator::PATTERN` constant
10+
* removed the `AbstractConstraintValidatorTest` class
11+
412
3.3.0
513
-----
614

src/Symfony/Component/Validator/Constraints/Choice.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Choice extends Constraint
3434
public $choices;
3535
public $callback;
3636
public $multiple = false;
37-
public $strict = false;
37+
public $strict = true;
3838
public $min;
3939
public $max;
4040
public $message = 'The value you selected is not a valid choice.';

src/Symfony/Component/Validator/Constraints/ChoiceValidator.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ public function validate($value, Constraint $constraint)
5959
}
6060

6161
if (false === $constraint->strict) {
62-
@trigger_error('Setting the strict option of the Choice constraint to false is deprecated since version 3.2 and will be removed in 4.0.', E_USER_DEPRECATED);
62+
throw new \RuntimeException('The "strict" option of the Choice constraint should not be used.');
6363
}
6464

6565
if ($constraint->multiple) {
6666
foreach ($value as $_value) {
67-
if (!in_array($_value, $choices, $constraint->strict)) {
67+
if (!in_array($_value, $choices, true)) {
6868
$this->context->buildViolation($constraint->multipleMessage)
6969
->setParameter('{{ value }}', $this->formatValue($_value))
7070
->setCode(Choice::NO_SUCH_CHOICE_ERROR)
@@ -96,7 +96,7 @@ public function validate($value, Constraint $constraint)
9696

9797
return;
9898
}
99-
} elseif (!in_array($value, $choices, $constraint->strict)) {
99+
} elseif (!in_array($value, $choices, true)) {
100100
$this->context->buildViolation($constraint->message)
101101
->setParameter('{{ value }}', $this->formatValue($value))
102102
->setCode(Choice::NO_SUCH_CHOICE_ERROR)

src/Symfony/Component/Validator/Constraints/DateTimeValidator.php

-5
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@
2020
*/
2121
class DateTimeValidator extends DateValidator
2222
{
23-
/**
24-
* @deprecated since version 3.1, to be removed in 4.0.
25-
*/
26-
const PATTERN = '/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/';
27-
2823
/**
2924
* {@inheritdoc}
3025
*/

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

-21
This file was deleted.

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

+7-51
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public function testExpectArrayIfMultipleIsTrue()
4545
$constraint = new Choice(array(
4646
'choices' => array('foo', 'bar'),
4747
'multiple' => true,
48-
'strict' => true,
4948
));
5049

5150
$this->validator->validate('asdf', $constraint);
@@ -58,7 +57,6 @@ public function testNullIsValid()
5857
new Choice(
5958
array(
6059
'choices' => array('foo', 'bar'),
61-
'strict' => true,
6260
)
6361
)
6462
);
@@ -71,20 +69,20 @@ public function testNullIsValid()
7169
*/
7270
public function testChoicesOrCallbackExpected()
7371
{
74-
$this->validator->validate('foobar', new Choice(array('strict' => true)));
72+
$this->validator->validate('foobar', new Choice());
7573
}
7674

7775
/**
7876
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
7977
*/
8078
public function testValidCallbackExpected()
8179
{
82-
$this->validator->validate('foobar', new Choice(array('callback' => 'abcd', 'strict' => true)));
80+
$this->validator->validate('foobar', new Choice(array('callback' => 'abcd')));
8381
}
8482

8583
public function testValidChoiceArray()
8684
{
87-
$constraint = new Choice(array('choices' => array('foo', 'bar'), 'strict' => true));
85+
$constraint = new Choice(array('choices' => array('foo', 'bar')));
8886

8987
$this->validator->validate('bar', $constraint);
9088

@@ -93,7 +91,7 @@ public function testValidChoiceArray()
9391

9492
public function testValidChoiceCallbackFunction()
9593
{
96-
$constraint = new Choice(array('callback' => __NAMESPACE__.'\choice_callback', 'strict' => true));
94+
$constraint = new Choice(array('callback' => __NAMESPACE__.'\choice_callback'));
9795

9896
$this->validator->validate('bar', $constraint);
9997

@@ -104,7 +102,6 @@ public function testValidChoiceCallbackClosure()
104102
{
105103
$constraint = new Choice(
106104
array(
107-
'strict' => true,
108105
'callback' => function () {
109106
return array('foo', 'bar');
110107
},
@@ -118,7 +115,7 @@ public function testValidChoiceCallbackClosure()
118115

119116
public function testValidChoiceCallbackStaticMethod()
120117
{
121-
$constraint = new Choice(array('callback' => array(__CLASS__, 'staticCallback'), 'strict' => true));
118+
$constraint = new Choice(array('callback' => array(__CLASS__, 'staticCallback')));
122119

123120
$this->validator->validate('bar', $constraint);
124121

@@ -130,7 +127,7 @@ public function testValidChoiceCallbackContextMethod()
130127
// search $this for "staticCallback"
131128
$this->setObject($this);
132129

133-
$constraint = new Choice(array('callback' => 'staticCallback', 'strict' => true));
130+
$constraint = new Choice(array('callback' => 'staticCallback'));
134131

135132
$this->validator->validate('bar', $constraint);
136133

@@ -142,7 +139,7 @@ public function testValidChoiceCallbackContextObjectMethod()
142139
// search $this for "objectMethodCallback"
143140
$this->setObject($this);
144141

145-
$constraint = new Choice(array('callback' => 'objectMethodCallback', 'strict' => true));
142+
$constraint = new Choice(array('callback' => 'objectMethodCallback'));
146143

147144
$this->validator->validate('bar', $constraint);
148145

@@ -154,7 +151,6 @@ public function testMultipleChoices()
154151
$constraint = new Choice(array(
155152
'choices' => array('foo', 'bar', 'baz'),
156153
'multiple' => true,
157-
'strict' => true,
158154
));
159155

160156
$this->validator->validate(array('baz', 'bar'), $constraint);
@@ -167,7 +163,6 @@ public function testInvalidChoice()
167163
$constraint = new Choice(array(
168164
'choices' => array('foo', 'bar'),
169165
'message' => 'myMessage',
170-
'strict' => true,
171166
));
172167

173168
$this->validator->validate('baz', $constraint);
@@ -185,7 +180,6 @@ public function testInvalidChoiceEmptyChoices()
185180
// the DB or the model
186181
'choices' => array(),
187182
'message' => 'myMessage',
188-
'strict' => true,
189183
));
190184

191185
$this->validator->validate('baz', $constraint);
@@ -202,7 +196,6 @@ public function testInvalidChoiceMultiple()
202196
'choices' => array('foo', 'bar'),
203197
'multipleMessage' => 'myMessage',
204198
'multiple' => true,
205-
'strict' => true,
206199
));
207200

208201
$this->validator->validate(array('foo', 'baz'), $constraint);
@@ -221,7 +214,6 @@ public function testTooFewChoices()
221214
'multiple' => true,
222215
'min' => 2,
223216
'minMessage' => 'myMessage',
224-
'strict' => true,
225217
));
226218

227219
$value = array('foo');
@@ -245,7 +237,6 @@ public function testTooManyChoices()
245237
'multiple' => true,
246238
'max' => 2,
247239
'maxMessage' => 'myMessage',
248-
'strict' => true,
249240
));
250241

251242
$value = array('foo', 'bar', 'moo');
@@ -262,27 +253,10 @@ public function testTooManyChoices()
262253
->assertRaised();
263254
}
264255

265-
/**
266-
* @group legacy
267-
*/
268-
public function testNonStrict()
269-
{
270-
$constraint = new Choice(array(
271-
'choices' => array(1, 2),
272-
'strict' => false,
273-
));
274-
275-
$this->validator->validate('2', $constraint);
276-
$this->validator->validate(2, $constraint);
277-
278-
$this->assertNoViolation();
279-
}
280-
281256
public function testStrictAllowsExactValue()
282257
{
283258
$constraint = new Choice(array(
284259
'choices' => array(1, 2),
285-
'strict' => true,
286260
));
287261

288262
$this->validator->validate(2, $constraint);
@@ -294,7 +268,6 @@ public function testStrictDisallowsDifferentType()
294268
{
295269
$constraint = new Choice(array(
296270
'choices' => array(1, 2),
297-
'strict' => true,
298271
'message' => 'myMessage',
299272
));
300273

@@ -306,28 +279,11 @@ public function testStrictDisallowsDifferentType()
306279
->assertRaised();
307280
}
308281

309-
/**
310-
* @group legacy
311-
*/
312-
public function testNonStrictWithMultipleChoices()
313-
{
314-
$constraint = new Choice(array(
315-
'choices' => array(1, 2, 3),
316-
'multiple' => true,
317-
'strict' => false,
318-
));
319-
320-
$this->validator->validate(array('2', 3), $constraint);
321-
322-
$this->assertNoViolation();
323-
}
324-
325282
public function testStrictWithMultipleChoices()
326283
{
327284
$constraint = new Choice(array(
328285
'choices' => array(1, 2, 3),
329286
'multiple' => true,
330-
'strict' => true,
331287
'multipleMessage' => 'myMessage',
332288
));
333289

0 commit comments

Comments
 (0)