Skip to content

Commit 8d40237

Browse files
committed
deprecate the "allowEmptyString" option
1 parent a73523b commit 8d40237

File tree

6 files changed

+46
-0
lines changed

6 files changed

+46
-0
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
@@ -113,6 +113,11 @@ Security
113113
* Removed `LogoutSuccessHandlerInterface` and `LogoutHandlerInterface`, register a listener on the `LogoutEvent` event instead.
114114
* Removed `DefaultLogoutSuccessHandler` in favor of `DefaultLogoutListener`.
115115

116+
Validator
117+
---------
118+
119+
* Removed the `allowEmptyString` option from the `Length` constraint.
120+
116121
Yaml
117122
----
118123

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]));

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy