|
16 | 16 | use Symfony\Component\Validator\Constraints\AbstractComparison;
|
17 | 17 | use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
|
18 | 18 | use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
|
| 19 | +use Symfony\Component\Validator\Tests\Constraints\Fixtures\TypedDummy; |
19 | 20 |
|
20 | 21 | class ComparisonTest_Class
|
21 | 22 | {
|
@@ -274,6 +275,33 @@ public function testCompareWithNullValueAtPropertyAt($dirtyValue, $dirtyValueAsS
|
274 | 275 | }
|
275 | 276 | }
|
276 | 277 |
|
| 278 | + /** |
| 279 | + * @requires PHP 7.4 |
| 280 | + * |
| 281 | + * @dataProvider provideComparisonsToNullValueAtPropertyPath |
| 282 | + */ |
| 283 | + public function testCompareWithUninitializedPropertyAtPropertyPath($dirtyValue, $dirtyValueAsString, $isValid) |
| 284 | + { |
| 285 | + $this->setObject(new TypedDummy()); |
| 286 | + |
| 287 | + $this->validator->validate($dirtyValue, $this->createConstraint([ |
| 288 | + 'message' => 'Constraint Message', |
| 289 | + 'propertyPath' => 'value', |
| 290 | + ])); |
| 291 | + |
| 292 | + if ($isValid) { |
| 293 | + $this->assertNoViolation(); |
| 294 | + } else { |
| 295 | + $this->buildViolation('Constraint Message') |
| 296 | + ->setParameter('{{ value }}', $dirtyValueAsString) |
| 297 | + ->setParameter('{{ compared_value }}', 'null') |
| 298 | + ->setParameter('{{ compared_value_type }}', 'null') |
| 299 | + ->setParameter('{{ compared_value_path }}', 'value') |
| 300 | + ->setCode($this->getErrorCode()) |
| 301 | + ->assertRaised(); |
| 302 | + } |
| 303 | + } |
| 304 | + |
277 | 305 | public static function provideAllInvalidComparisons(): array
|
278 | 306 | {
|
279 | 307 | // The provider runs before setUp(), so we need to manually fix
|
|
0 commit comments