8000 deprecate the "allowEmptyString" option · symfony/symfony@6df1211 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6df1211

Browse files
committed
deprecate the "allowEmptyString" option
1 parent 7950851 commit 6df1211

File tree

9 files changed

+49
-3
lines changed

9 files changed

+49
-3
lines changed

UPGRADE-5.2.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
UPGRADE FROM 5.1 to 5.2
2+
=======================
3+
4+
Validator
5+
---------
6+
7+
* Deprecated the `allowEmptyString` option of the `Length` constraint.

UPGRADE-6.0.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ Security
115115
* Removed `DefaultLogoutSuccessHandler` in favor of `DefaultLogoutListener`.
116116
* Added a `logout(Request $request, Response $response, TokenInterface $token)` method to the `RememberMeServicesInterface`.
117117

118+
Validator
119+
---------
120+
121+
* Removed the `allowEmptyString` option from the `Length` constraint.
122+
118123
Yaml
119124
----
120125

src/Symfony/Bridge/Doctrine/Tests/Fixtures/DoctrineLoaderEntity.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ class DoctrineLoaderEntity extends DoctrineLoaderParentEntity
3636

3737
/**
3838
* @ORM\Column(length=20)
39-
* @Assert\Length(min=5, allowEmptyString=true)
39+
* @Assert\Length(min=5)
4040
*/
4141
public $mergedMaxLength;
4242

4343
/**
4444
* @ORM\Column(length=20)
45-
* @Assert\Length(min=1, max=10, allowEmptyString=true)
45+
* @Assert\Length(min=1, max=10)
4646
*/
4747
public $alreadyMappedMaxLength;
4848

src/Symfony/Bridge/Doctrine/Tests/Resources/validator/BaseUser.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
<option name="min">2</option>
1414
<option name="max">120</option>
1515
<option name="groups">Registration</option>
16-
<option name="allowEmptyString">true</option>
1716
</constraint>
1817
</property>
1918
</class>

src/Symfony/Component/Validator/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
5.2.0
5+
-----
6+
7+
* deprecated the `allowEmptyString` option of the `Length` constraint
8+
49
5.1.0
510
-----
611

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,9 @@ public function __construct($options = null)
6464
if (null !== $this->normalizer && !\is_callable($this->normalizer)) {
6565
throw new InvalidArgumentException(sprintf('The "normalizer" option must be a valid callable ("%s" given).', get_debug_type($this->normalizer)));
6666
}
67+
68+
if (isset($options['allowEmptyString'])) {
69+
trigger_deprecation('symfony/validator', '5.2', sprintf('The "allowEmptyString" option of the "%s" constraint is deprecated.', self::class));
70+
}
6771
}
6872
}

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@
1212
namespace Symfony\Component\Validator\Tests\Constraints;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1516
use Symfony\Component\Validator\Constraints\Length;
1617

1718
/**
1819
* @author Renan Taranto <renantaranto@gmail.com>
1920
*/
2021
class LengthTest extends TestCase
2122
{
23+
use ExpectDeprecationTrait;
24+
2225
public function testNormalizerCanBeSet()
2326
{
2427
$length = new Length(['min' => 0, 'max' => 10, 'normalizer' => 'trim']);
@@ -39,4 +42,23 @@ public function testInvalidNormalizerObjectThrowsException()
3942
$this->expectExceptionMessage('The "normalizer" option must be a valid callable ("stdClass" given).');
4043
new Length(['min' => 0, 'max' => 10, 'normalizer' => new \stdClass()]);
4144
}
45+
46+
/**
47+
* @group legacy
48+
* @dataProvider allowEmptyStringOptionData
49+
*/
50+
public function testDoNotAllowEmptyStringWithoutMinLength(bool $value)
51+
{
52+
$this->expectDeprecation('Since symfony/validator 5.2: The "allowEmptyString" option of the "Symfony\Component\Validator\Constraints\Length" constraint is deprecated.');
53+
54+
new Length(['allowEmptyString' => $value, 'max' => 5]);
55+
}
56+
57+
public function allowEmptyStringOptionData()
58+
{
59+
return [
60+
[true],
61+
[false],
62+
];
63+
}
4264
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ public function testNullIsValid()
2929
$this->assertNoViolation();
3030
}
3131

32+
/**
33+
* @group legacy
34+
*/
3235
public function testAllowEmptyString()
3336
{
3437
$this->validator->validate('', new Length(['value' => 6, 'allowEmptyString' => true]));

src/Symfony/Component/Validator/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
],
1818
"require": {
1919
"php": ">=7.2.5",
20+
"symfony/deprecation-contracts": "^2.1",
2021
"symfony/polyfill-ctype": "~1.8",
2122
"symfony/polyfill-mbstring": "~1.0",
2223
"symfony/polyfill-php80": "^1.15",

0 commit comments

Comments
 (0)
0