Skip to content

Commit b3e4d83

Browse files
Merge branch '6.4' into 7.0
* 6.4: [Console][PhpUnitBridge][VarDumper] Fix `NO_COLOR` empty value handling [Translation] Fix CSV escape char in `CsvFileLoader` on PHP >= 7.4 [DoctrineBridge] fix messenger bus dispatch inside an active transaction [HttpFoundation] Add tests for uncovered sections treat uninitialized properties referenced by property paths as null properly set up constraint options [ErrorHandler][VarDumper] Remove PHP 8.4 deprecations [Profiler] Add word wrap in tables in dialog to see all the text [Core] Fix & Enhance security arabic translation.
2 parents 8eb1c27 + bcf939a commit b3e4d83

13 files changed

+209
-14
lines changed

Constraints/AbstractComparisonValidator.php

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Validator\Constraints;
1313

1414
use Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException;
15+
use Symfony\Component\PropertyAccess\Exception\UninitializedPropertyException;
1516
use Symfony\Component\PropertyAccess\PropertyAccess;
1617
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
1718
use Symfony\Component\Validator\Constraint;
@@ -53,6 +54,8 @@ public function validate(mixed $value, Constraint $constraint): void
5354
$comparedValue = $this->getPropertyAccessor()->getValue($object, $path);
5455
} catch (NoSuchPropertyException $e) {
5556
throw new ConstraintDefinitionException(sprintf('Invalid property path "%s" provided to "%s" constraint: ', $path, get_debug_type($constraint)).$e->getMessage(), 0, $e);
57+
} catch (UninitializedPropertyException) {
58+
$comparedValue = null;
5659
}
5760
} else {
5861
$comparedValue = $constraint->value;

Constraints/BicValidator.php

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Intl\Countries;
1515
use Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException;
16+
use Symfony\Component\PropertyAccess\Exception\UninitializedPropertyException;
1617
use Symfony\Component\PropertyAccess\PropertyAccess;
1718
use Symfony\Component\PropertyAccess\PropertyAccessor;
1819
use Symfony\Component\Validator\Constraint;
@@ -127,6 +128,8 @@ public function validate(mixed $value, Constraint $constraint): void
127128
$iban = $this->getPropertyAccessor()->getValue($object, $path);
128129
} catch (NoSuchPropertyException $e) {
129130
throw new ConstraintDefinitionException(sprintf('Invalid property path "%s" provided to "%s" constraint: ', $path, get_debug_type($constraint)).$e->getMessage(), 0, $e);
131+
} catch (UninitializedPropertyException) {
132+
$iban = null;
130133
}
131134
}
132135
if (!$iban) {

Constraints/RangeValidator.php

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Validator\Constraints;
1313

1414
use Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException;
15+
use Symfony\Component\PropertyAccess\Exception\UninitializedPropertyException;
1516
use Symfony\Component\PropertyAccess\PropertyAccess;
1617
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
1718
use Symfony\Component\Validator\Constraint;
@@ -159,6 +160,8 @@ private function getLimit(?string $propertyPath, mixed $default, Constraint $con
159160
return $this->getPropertyAccessor()->getValue($object, $propertyPath);
160161
} catch (NoSuchPropertyException $e) {
161162
throw new ConstraintDefinitionException(sprintf('Invalid property path "%s" provided to "%s" constraint: ', $propertyPath, get_debug_type($constraint)).$e->getMessage(), 0, $e);
163+
} catch (UninitializedPropertyException) {
164+
return null;
162165
}
163166
}
164167

Tests/Constraints/AbstractComparisonValidatorTestCase.php

+26
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Validator\Constraints\AbstractComparison;
1717
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
1818
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
19+
use Symfony\Component\Validator\Tests\Constraints\Fixtures\TypedDummy;
1920

2021
class ComparisonTest_Class
2122
{
@@ -265,6 +266,31 @@ public function testCompareWithNullValueAtPropertyAt($dirtyValue, $dirtyValueAsS
265266
}
266267
}
267268

269+
/**
270+
* @dataProvider provideComparisonsToNullValueAtPropertyPath
271+
*/
272+
public function testCompareWithUninitializedPropertyAtPropertyPath($dirtyValue, $dirtyValueAsString, $isValid)
273+
{
274+
$this->setObject(new TypedDummy());
275+
276+
$this->validator->validate($dirtyValue, $this->createConstraint([
277+
'message' => 'Constraint Message',
278+
'propertyPath' => 'value',
279+
]));
280+
281+
if ($isValid) {
282+
$this->assertNoViolation();
283+
} else {
284+
$this->buildViolation('Constraint Message')
285+
->setParameter('{{ value }}', $dirtyValueAsString)
286+
->setParameter('{{ compared_value }}', 'null')
287+
->setParameter('{{ compared_value_type }}', 'null')
288+
->setParameter('{{ compared_value_path }}', 'value')
289+
->setCode($this->getErrorCode())
290+
->assertRaised();
291+
}
292+
}
293+
268294
public static function provideAllInvalidComparisons(): array
269295
{
270296
// The provider runs before setUp(), so we need to manually fix

Tests/Constraints/BicValidatorTest.php

+10
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\Validator\Mapping\ClassMetadata;
1919
use Symfony\Component\Validator\Mapping\Loader\AttributeLoader;
2020
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
21+
use Symfony\Component\Validator\Tests\Constraints\Fixtures\BicTypedDummy;
2122

2223
class BicValidatorTest extends ConstraintValidatorTestCase
2324
{
@@ -89,6 +90,15 @@ public function testInvalidComparisonToPropertyPathFromAttribute()
8990
->assertRaised();
9091
}
9192

93+
public function testPropertyPathReferencingUninitializedProperty()
94+
{
95+
$this->setObject(new BicTypedDummy());
96+
97+
$this->validator->validate('UNCRIT2B912', new Bic(['ibanPropertyPath' => 'iban']));
98+
99+
$this->assertNoViolation();
100+
}
101+
92102
public function testValidComparisonToValue()
93103
{
94104
$constraint = new Bic(['iban' => 'FR14 2004 1010 0505 0001 3M02 606']);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Validator\Tests\Constraints\Fixtures;
13+
14+
class BicTypedDummy
15+
{
16+
public string $iban;
17+
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Validator\Tests\Constraints\Fixtures;
13+
14+
class MinMaxTyped
15+
{
16+
public int $min;
17+
public int $max;
18+
}
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Validator\Tests\Constraints\Fixtures;
13+
14+
class TypedDummy
15+
{
16+
public mixed $value;
17+
}

Tests/Constraints/GreaterThanOrEqualValidatorWithPositiveOrZeroConstraintTest.php

+26-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class GreaterThanOrEqualValidatorWithPositiveOrZeroConstraintTest extends Greate
2323
{
2424
protected static function createConstraint(?array $options = null): Constraint
2525
{
26-
return new PositiveOrZero();
26+
return new PositiveOrZero($options);
2727
}
2828

2929
public static function provideValidComparisons(): array
@@ -86,6 +86,11 @@ public function testInvalidValuePath()
8686
$this->markTestSkipped('PropertyPath option is not used in PositiveOrZero constraint');
8787
}
8888

89+
public static function provideAllValidComparisons(): array
90+
{
91+
self::markTestSkipped('The "value" option cannot be used in the PositiveOrZero constraint');
92+
}
93+
8994
/**
9095
* @dataProvider provideValidComparisonsToPropertyPath
9196
*/
@@ -94,6 +99,11 @@ public function testValidComparisonToPropertyPath($comparedValue)
9499
$this->markTestSkipped('PropertyPath option is not used in PositiveOrZero constraint');
95100
}
96101

102+
public function testNoViolationOnNullObjectWithPropertyPath()
103+
{
104+
$this->markTestSkipped('PropertyPath option is not used in PositiveOrZero constraint');
105+
}
106+
97107
/**
98108
* @dataProvider throwsOnInvalidStringDatesProvider
99109
*/
@@ -106,4 +116,19 @@ public function testInvalidComparisonToPropertyPathAddsPathAsParameter()
106116
{
107117
$this->markTestSkipped('PropertyPath option is not used in PositiveOrZero constraint');
108118
}
119+
120+
public static function throwsOnInvalidStringDatesProvider(): array
121+
{
122+
self::markTestSkipped('The "value" option cannot be used in the PositiveOrZero constraint');
123+
}
124+
125+
public static function provideAllInvalidComparisons(): array
126+
{
127+
self::markTestSkipped('The "value" option cannot be used in the Negative constraint');
128+
}
129+
130+
public static function provideComparisonsToNullValueAtPropertyPath(): array
131+
{
132+
self::markTestSkipped('PropertyPath option is not used in PositiveOrZero constraint');
133+
}
109134
}

Tests/Constraints/GreaterThanValidatorWithPositiveConstraintTest.php

+21-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class GreaterThanValidatorWithPositiveConstraintTest extends GreaterThanValidato
2323
{
2424
protected static function createConstraint(?array $options = null): Constraint
2525
{
26-
return new Positive();
26+
return new Positive($options);
2727
}
2828

2929
public static function provideValidComparisons(): array
@@ -89,6 +89,11 @@ public function testInvalidValuePath()
8989
$this->markTestSkipped('PropertyPath option is not used in Positive constraint');
9090
}
9191

92+
public static function provideAllValidComparisons(): array
93+
{
94+
self::markTestSkipped('The "value" option cannot be used in the Positive constraint');
95+
}
96+
9297
/**
9398
* @dataProvider provideValidComparisonsToPropertyPath
9499
*/
@@ -109,4 +114,19 @@ public function testInvalidComparisonToPropertyPathAddsPathAsParameter()
109114
{
110115
$this->markTestSkipped('PropertyPath option is not used in Positive constraint');
111116
}
117+
118+
public static function throwsOnInvalidStringDatesProvider(): array
119+
{
120+
self::markTestSkipped('The "value" option cannot be used in the Positive constraint');
121+
}
122+
123+
public static function provideAllInvalidComparisons(): array
124+
{
125+
self::markTestSkipped('The "value" option cannot be used in the Positive constraint');
126+
}
127+
128+
public static function provideComparisonsToNullValueAtPropertyPath(): array
129+
{
130+
self::markTestSkipped('PropertyPath option is not used in PositiveOrZero constraint');
131+
}
112132
}

Tests/Constraints/LessThanOrEqualValidatorWithNegativeOrZeroConstraintTest.php

+22-7
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class LessThanOrEqualValidatorWithNegativeOrZeroConstraintTest extends LessThanO
2323
{
2424
protected static function createConstraint(?array $options = null): Constraint
2525
{
26-
return new NegativeOrZero();
26+
return new NegativeOrZero($options);
2727
}
2828

2929
public static function provideValidComparisons(): array
@@ -89,6 +89,11 @@ public function testInvalidValuePath()
8989
$this->markTestSkipped('PropertyPath option is not used in NegativeOrZero constraint');
9090
}
9191

92+
public static function provideAllValidComparisons(): array
93+
{
94+
self::markTestSkipped('The "value" option cannot be used in the NegativeOrZero constraint');
95+
}
96+
9297
/**
9398
* @dataProvider provideValidComparisonsToPropertyPath
9499
*/
@@ -97,12 +102,9 @@ public function testValidComparisonToPropertyPath($comparedValue)
97102
$this->markTestSkipped('PropertyPath option is not used in NegativeOrZero constraint');
98103
}
99104

100-
/**
101-
* @dataProvider throwsOnInvalidStringDatesProvider
102-
*/
103-
public function testThrowsOnInvalidStringDates(AbstractComparison $constraint, $expectedMessage, $value)
105+
public function testInvalidComparisonToPropertyPathAddsPathAsParameter()
104106
{
105-
$this->markTestSkipped('The compared value cannot be an invalid string date because it is hardcoded to 0.');
107+
$this->markTestSkipped('PropertyPath option is not used in NegativeOrZero constraint');
106108
}
107109

108110
/**
@@ -113,8 +115,21 @@ public function testCompareWithNullValueAtPropertyAt($dirtyValue, $dirtyValueAsS
113115
$this->markTestSkipped('PropertyPath option is not used in NegativeOrZero constraint');
114116
}
115117

116-
public function testInvalidComparisonToPropertyPathAddsPathAsParameter()
118+
/**
119+
* @dataProvider provideComparisonsToNullValueAtPropertyPath
120+
*/
121+
public function testCompareWithUninitializedPropertyAtPropertyPath($dirtyValue, $dirtyValueAsString, $isValid)
117122
{
118123
$this->markTestSkipped('PropertyPath option is not used in NegativeOrZero constraint');
119124
}
125+
126+
public static function throwsOnInvalidStringDatesProvider(): array
127+
{
128+
self::markTestSkipped('The "value" option cannot be used in the NegativeOrZero constraint');
129+
}
130+
131+
public static function provideAllInvalidComparisons(): array
132+
{
133+
self::markTestSkipped('The "value" option cannot be used in the NegativeOrZero constraint');
134+
}
120135
}

Tests/Constraints/LessThanValidatorWithNegativeConstraintTest.php

+20-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class LessThanValidatorWithNegativeConstraintTest extends LessThanValidatorTest
2323
{
2424
protected static function createConstraint(?array $options = null): Constraint
2525
{
26-
return new Negative();
26+
return new Negative($options);
2727
}
2828

2929
public static function provideValidComparisons(): array
@@ -89,6 +89,11 @@ public function testInvalidValuePath()
8989
$this->markTestSkipped('PropertyPath option is not used in Negative constraint');
9090
}
9191

92+
public static function provideAllValidComparisons(): array
93+
{
94+
self::markTestSkipped('The "value" option cannot be used in the Negative constraint');
95+
}
96+
9297
/**
9398
* @dataProvider provideValidComparisonsToPropertyPath
9499
*/
@@ -97,18 +102,23 @@ public function testValidComparisonToPropertyPath($comparedValue)
97102
$this->markTestSkipped('PropertyPath option is not used in Negative constraint');
98103
}
99104

105+
public static function throwsOnInvalidStringDatesProvider(): array
106+
{
107+
self::markTestSkipped('The "value" option cannot be used in the Negative constraint');
108+
}
109+
100110
/**
101-
* @dataProvider throwsOnInvalidStringDatesProvider
111+
* @dataProvider provideComparisonsToNullValueAtPropertyPath
102112
*/
103-
public function testThrowsOnInvalidStringDates(AbstractComparison $constraint, $expectedMessage, $value)
113+
public function testCompareWithNullValueAtPropertyAt($dirtyValue, $dirtyValueAsString, $isValid)
104114
{
105-
$this->markTestSkipped('The compared value cannot be an invalid string date because it is hardcoded to 0.');
115+
$this->markTestSkipped('PropertyPath option is not used in Negative constraint');
106116
}
107117

108118
/**
109119
* @dataProvider provideComparisonsToNullValueAtPropertyPath
110120
*/
111-
public function testCompareWithNullValueAtPropertyAt($dirtyValue, $dirtyValueAsString, $isValid)
121+
public function testCompareWithUninitializedPropertyAtPropertyPath($dirtyValue, $dirtyValueAsString, $isValid)
112122
{
113123
$this->markTestSkipped('PropertyPath option is not used in Negative constraint');
114124
}
@@ -117,4 +127,9 @@ public function testInvalidComparisonToPropertyPathAddsPathAsParameter()
117127
{
118128
$this->markTestSkipped('PropertyPath option is not used in Negative constraint');
119129
}
130+
131+
public static function provideAllInvalidComparisons(): array
132+
{
133+
self::markTestSkipped('The "value" option cannot be used in the Negative constraint');
134+
}
120135
}

0 commit comments

Comments
 (0)