Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit3d1d2d2

Browse files
committed
Deprecate use ofLocale validation constraint without setting "canonicalize" option totrue
1 parent89d1b65 commit3d1d2d2

File tree

3 files changed

+100
-11
lines changed

3 files changed

+100
-11
lines changed

‎src/Symfony/Component/Validator/CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
* Deprecated the`checkDNS` and`dnsMessage` options of the`Url` constraint. They will be removed in 5.0.
88
* added a`values` option to the`Expression` constraint
9+
* Deprecated use of`Locale` constraint without setting`true` at "canonicalize" option, which will be the default value in 5.0
910

1011
4.0.0
1112
-----

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,13 @@ class Locale extends Constraint
2929

3030
public$message ='This value is not a valid locale.';
3131
public$canonicalize =false;
32+
33+
publicfunction__construct($options =null)
34+
{
35+
if (!($options['canonicalize'] ??false)) {
36+
@trigger_error('The "canonicalize" option with value `false` is deprecated since Symfony 4.1 and will be removed in 5.0. Set it to `true` instead.',E_USER_DEPRECATED);
37+
}
38+
39+
parent::__construct($options);
40+
}
3241
}

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

Lines changed: 90 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,47 +22,123 @@ protected function createValidator()
2222
returnnewLocaleValidator();
2323
}
2424

25-
publicfunctiontestNullIsValid()
25+
/**
26+
* @group legacy
27+
* @expectedDeprecation The "canonicalize" option with value `false` is deprecated since Symfony 4.1 and will be removed in 5.0. Set it to `true` instead.
28+
*
29+
* @dataProvider getValidLocales
30+
*/
31+
publicfunctiontestLegacyNullIsValid()
2632
{
2733
$this->validator->validate(null,newLocale());
2834

2935
$this->assertNoViolation();
3036
}
3137

32-
publicfunctiontestEmptyStringIsValid()
38+
publicfunctiontestNullIsValid()
39+
{
40+
$this->validator->validate(null,newLocale(array('canonicalize' =>true)));
41+
42+
$this->assertNoViolation();
43+
}
44+
45+
/**
46+
* @group legacy
47+
* @expectedDeprecation The "canonicalize" option with value `false` is deprecated since Symfony 4.1 and will be removed in 5.0. Set it to `true` instead.
48+
*
49+
* @dataProvider getValidLocales
50+
*/
51+
publicfunctiontestLegacyEmptyStringIsValid()
3352
{
3453
$this->validator->validate('',newLocale());
3554

3655
$this->assertNoViolation();
3756
}
3857

58+
publicfunctiontestEmptyStringIsValid()
59+
{
60+
$this->validator->validate('',newLocale(array('canonicalize' =>true)));
61+
62+
$this->assertNoViolation();
63+
}
64+
3965
/**
66+
* @group legacy
67+
* @expectedDeprecation The "canonicalize" option with value `false` is deprecated since Symfony 4.1 and will be removed in 5.0. Set it to `true` instead.
4068
* @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
4169
*/
42-
publicfunctiontestExpectsStringCompatibleType()
70+
publicfunctiontestLegacyExpectsStringCompatibleType()
4371
{
4472
$this->validator->validate(new \stdClass(),newLocale());
4573
}
4674

4775
/**
76+
* @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
77+
*/
78+
publicfunctiontestExpectsStringCompatibleType()
79+
{
80+
$this->validator->validate(new \stdClass(),newLocale(array('canonicalize' =>true)));
81+
}
82+
83+
/**
84+
* @group legacy
85+
* @expectedDeprecation The "canonicalize" option with value `false` is deprecated since Symfony 4.1 and will be removed in 5.0. Set it to `true` instead.
86+
*
4887
* @dataProvider getValidLocales
4988
*/
50-
publicfunctiontestValidLocales($locale)
89+
publicfunctiontestLegacyValidLocales(string$locale)
5190
{
5291
$this->validator->validate($locale,newLocale());
5392

5493
$this->assertNoViolation();
5594
}
5695

96+
/**
97+
* @dataProvider getValidLocales
98+
*/
99+
publicfunctiontestValidLocales(string$locale,array$options)
100+
{
101+
$this->validator->validate($locale,newLocale($options));
102+
103+
$this->assertNoViolation();
104+
}
105+
57106
publicfunctiongetValidLocales()
58107
{
59108
returnarray(
60-
array('en'),
61-
array('en_US'),
62-
array('pt'),
63-
array('pt_PT'),
64-
array('zh_Hans'),
65-
array('fil_PH'),
109+
array('en',array('canonicalize' =>true)),
110+
array('en_US',array('canonicalize' =>true)),
111+
array('pt',array('canonicalize' =>true)),
112+
array('pt_PT',array('canonicalize' =>true)),
113+
array('zh_Hans',array('canonicalize' =>true)),
114+
array('fil_PH',array('canonicalize' =>true)),
115+
);
116+
}
117+
118+
/**
119+
* @group legacy
120+
* @expectedDeprecation The "canonicalize" option with value `false` is deprecated since Symfony 4.1 and will be removed in 5.0. Set it to `true` instead.
121+
* @dataProvider getLegacyInvalidLocales
122+
*/
123+
publicfunctiontestLegacyInvalidLocales(string$locale)
124+
{
125+
$constraint =newLocale(array(
126+
'message' =>'myMessage',
127+
));
128+
129+
$this->validator->validate($locale,$constraint);
130+
131+
$this->buildViolation('myMessage')
132+
->setParameter('{{ value }}','"'.$locale.'"')
133+
->setCode(Locale::NO_SUCH_LOCALE_ERROR)
134+
->assertRaised();
135+
}
136+
137+
publicfunctiongetLegacyInvalidLocales()
138+
{
139+
returnarray(
140+
array('EN'),
141+
array('foobar'),
66142
);
67143
}
68144

@@ -73,6 +149,7 @@ public function testInvalidLocales($locale)
73149
{
74150
$constraint =newLocale(array(
75151
'message' =>'myMessage',
152+
'canonicalize' =>true,
76153
));
77154

78155
$this->validator->validate($locale,$constraint);
@@ -86,12 +163,14 @@ public function testInvalidLocales($locale)
86163
publicfunctiongetInvalidLocales()
87164
{
88165
returnarray(
89-
array('EN'),
166+
array('baz'),
90167
array('foobar'),
91168
);
92169
}
93170

94171
/**
172+
* @group legacy
173+
* @expectedDeprecation The "canonicalize" option with value `false` is deprecated since Symfony 4.1 and will be removed in 5.0. Set it to `true` instead.
95174
* @dataProvider getUncanonicalizedLocales
96175
*/
97176
publicfunctiontestInvalidLocalesWithoutCanonicalization(string$locale)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp