Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Validator] remove deprecated features #22795

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Symfony/Component/Validator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
CHANGELOG
=========

4.0.0
-----

* Setting the `strict` option of the `Choice` constraint to anything but `true`
is not supported anymore.
* removed the `DateTimeValidator::PATTERN` constant
* removed the `AbstractConstraintValidatorTest` class

3.3.0
-----

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Validator/Constraints/Choice.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Choice extends Constraint
public $choices;
public $callback;
public $multiple = false;
public $strict = false;
public $strict = true;
public $min;
public $max;
public $message = 'The value you selected is not a valid choice.';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ public function validate($value, Constraint $constraint)
}

if (false === $constraint->strict) {
@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);
throw new \RuntimeException('The "strict" option of the Choice constraint should not be used.');
Copy link
Contributor

@ro0NL ro0NL May 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove the entire option right? given

... and will be removed in 4.0.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot completely remove the option as that would break code that was valid in 3.4 (as the base Constraint class would complain about an unknown option while setting the strict option to true is the forward compatible change to be made in 3.x).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should remove any use of the "strict" property in the class, isn't it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed, done

}

if ($constraint->multiple) {
foreach ($value as $_value) {
if (!in_array($_value, $choices, $constraint->strict)) {
if (!in_array($_value, $choices, true)) {
$this->context->buildViolation($constraint->multipleMessage)
->setParameter('{{ value }}', $this->formatValue($_value))
->setCode(Choice::NO_SUCH_CHOICE_ERROR)
Expand Down Expand Up @@ -96,7 +96,7 @@ public function validate($value, Constraint $constraint)

return;
}
} elseif (!in_array($value, $choices, $constraint->strict)) {
} elseif (!in_array($value, $choices, true)) {
$this->context->buildViolation($constraint->message)
->setParameter('{{ value }}', $this->formatValue($value))
->setCode(Choice::NO_SUCH_CHOICE_ERROR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@
*/
class DateTimeValidator extends DateValidator
{
/**
* @deprecated since version 3.1, to be removed in 4.0.
*/
const PATTERN = '/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/';

/**
* {@inheritdoc}
*/
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public function testExpectArrayIfMultipleIsTrue()
$constraint = new Choice(array(
'choices' => array('foo', 'bar'),
'multiple' => true,
'strict' => true,
));

$this->validator->validate('asdf', $constraint);
Expand All @@ -58,7 +57,6 @@ public function testNullIsValid()
new Choice(
array(
'choices' => array('foo', 'bar'),
'strict' => true,
)
)
);
Expand All @@ -71,20 +69,20 @@ public function testNullIsValid()
*/
public function testChoicesOrCallbackExpected()
{
$this->validator->validate('foobar', new Choice(array('strict' => true)));
$this->validator->validate('foobar', new Choice());
}

/**
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
*/
public function testValidCallbackExpected()
{
$this->validator->validate('foobar', new Choice(array('callback' => 'abcd', 'strict' => true)));
$this->validator->validate('foobar', new Choice(array('callback' => 'abcd')));
}

public function testValidChoiceArray()
{
$constraint = new Choice(array('choices' => array('foo', 'bar'), 'strict' => true));
$constraint = new Choice(array('choices' => array('foo', 'bar')));

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

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

public function testValidChoiceCallbackFunction()
{
$constraint = new Choice(array('callback' => __NAMESPACE__.'\choice_callback', 'strict' => true));
$constraint = new Choice(array('callback' => __NAMESPACE__.'\choice_callback'));

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

Expand All @@ -104,7 +102,6 @@ public function testValidChoiceCallbackClosure()
{
$constraint = new Choice(
array(
'strict' => true,
'callback' => function () {
return array('foo', 'bar');
},
Expand All @@ -118,7 +115,7 @@ public function testValidChoiceCallbackClosure()

public function testValidChoiceCallbackStaticMethod()
{
$constraint = new Choice(array('callback' => array(__CLASS__, 'staticCallback'), 'strict' => true));
$constraint = new Choice(array('callback' => array(__CLASS__, 'staticCallback')));

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

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

$constraint = new Choice(array('callback' => 'staticCallback', 'strict' => true));
$constraint = new Choice(array('callback' => 'staticCallback'));

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

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

$constraint = new Choice(array('callback' => 'objectMethodCallback', 'strict' => true));
$constraint = new Choice(array('callback' => 'objectMethodCallback'));

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

Expand All @@ -154,7 +151,6 @@ public function testMultipleChoices()
$constraint = new Choice(array(
'choices' => array('foo', 'bar', 'baz'),
'multiple' => true,
'strict' => true,
));

$this->validator->validate(array('baz', 'bar'), $constraint);
Expand All @@ -167,7 +163,6 @@ public function testInvalidChoice()
$constraint = new Choice(array(
'choices' => array('foo', 'bar'),
'message' => 'myMessage',
'strict' => true,
));

$this->validator->validate('baz', $constraint);
Expand All @@ -185,7 +180,6 @@ public function testInvalidChoiceEmptyChoices()
// the DB or the model
'choices' => array(),
'message' => 'myMessage',
'strict' => true,
));

$this->validator->validate('baz', $constraint);
Expand All @@ -202,7 +196,6 @@ public function testInvalidChoiceMultiple()
'choices' => array('foo', 'bar'),
'multipleMessage' => 'myMessage',
'multiple' => true,
'strict' => true,
));

$this->validator->validate(array('foo', 'baz'), $constraint);
Expand All @@ -221,7 +214,6 @@ public function testTooFewChoices()
'multiple' => true,
'min' => 2,
'minMessage' => 'myMessage',
'strict' => true,
));

$value = array('foo');
Expand All @@ -245,7 +237,6 @@ public function testTooManyChoices()
'multiple' => true,
'max' => 2,
'maxMessage' => 'myMessage',
'strict' => true,
));

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

/**
* @group legacy
*/
public function testNonStrict()
{
$constraint = new Choice(array(
'choices' => array(1, 2),
'strict' => false,
));

$this->validator->validate('2', $constraint);
$this->validator->validate(2, $constraint);

$this->assertNoViolation();
}

public function testStrictAllowsExactValue()
{
$constraint = new Choice(array(
'choices' => array(1, 2),
'strict' => true,
));

$this->validator->validate(2, $constraint);
Expand All @@ -294,7 +268,6 @@ public function testStrictDisallowsDifferentType()
{
$constraint = new Choice(array(
'choices' => array(1, 2),
'strict' => true,
'message' => 'myMessage',
));

Expand All @@ -306,28 +279,11 @@ public function testStrictDisallowsDifferentType()
->assertRaised();
}

/**
* @group legacy
*/
public function testNonStrictWithMultipleChoices()
{
$constraint = new Choice(array(
'choices' => array(1, 2, 3),
'multiple' => true,
'strict' => false,
));

$this->validator->validate(array('2', 3), $constraint);

$this->assertNoViolation();
}

public function testStrictWithMultipleChoices()
{
$constraint = new Choice(array(
'choices' => array(1, 2, 3),
'multiple' => true,
'strict' => true,
'multipleMessage' => 'myMessage',
));

Expand Down