Skip to content

Commit 85067b0

Browse files
Merge branch '6.4' into 7.2
* 6.4: [Routing] Add test to validate that default value is allowed to not match requirement fix handling required options Fix @var phpdoc [Lock] [MongoDB] Enforce readPreference=primary and writeConcern=majority [FrameworkBundle] fix phpdoc in `MicroKernelTrait` Fixed validator translations for Albanian
2 parents bab0d37 + 8d5f378 commit 85067b0

17 files changed

+223
-60
lines changed

Constraints/CardScheme.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function __construct(array|string|null $schemes, ?string $message = null,
5555
{
5656
if (\is_array($schemes) && \is_string(key($schemes))) {
5757
$options = array_merge($schemes, $options);
58-
} else {
58+
} elseif (null !== $schemes) {
5959
$options['value'] = $schemes;
6060
}
6161

Constraints/Composite.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function __construct(mixed $options = null, ?array $groups = null, mixed
5555

5656
$this->initializeNestedConstraints();
5757

58-
/* @var Constraint[] $nestedConstraints */
58+
/** @var Constraint[] $nestedConstraints */
5959
$compositeOption = $this->getCompositeOption();
6060
$nestedConstraints = $this->$compositeOption;
6161

@@ -135,7 +135,7 @@ abstract protected function getCompositeOption(): string;
135135
*/
136136
public function getNestedConstraints(): array
137137
{
138-
/* @var Constraint[] $nestedConstraints */
138+
/** @var Constraint[] $nestedConstraints */
139139
return $this->{$this->getCompositeOption()};
140140
}
141141

Constraints/Expression.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function __construct(
6060

6161
if (\is_array($expression)) {
6262
$options = array_merge($expression, $options);
63-
} else {
63+
} elseif (null !== $expression) {
6464
$options['value'] = $expression;
6565
}
6666

Constraints/When.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ public function __construct(string|Expression|array $expression, array|Constrain
4545
$options = array_merge($expression, $options);
4646
} else {
4747
$options['expression'] = $expression;
48-
$options['constraints'] = $constraints;
48+
49+
if (null !== $constraints) {
50+
$options['constraints'] = $constraints;
51+
}
4952
}
5053

5154
if (isset($options['constraints']) && !\is_array($options['constraints'])) {

Resources/translations/validators.sq.xlf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@
449449
</trans-unit>
450450
<trans-unit id="113">
451451
<source>This URL is missing a top-level domain.</source>
452-
<target state="needs-review-translation">Kësaj URL i mungon një domain i nivelit të lartë.</target>
452+
<target>Kësaj URL-je i mungon një domain i nivelit të sipërm.</target>
453453
</trans-unit>
454454
<trans-unit id="114">
455455
<source>This value is too short. It should contain at least one word.|This value is too short. It should contain at least {{ min }} words.</source>
@@ -477,7 +477,7 @@
477477
</trans-unit>
478478
<trans-unit id="121">
479479
<source>This value is not a valid Twig template.</source>
480-
<target state="needs-review-translation">Kjo vlerë nuk është një shabllon Twig i vlefshëm.</target>
480+
<target>Kjo vlerë nuk është një shabllon Twig i vlefshëm.</target>
481481
</trans-unit>
482482
</body>
483483
</file>

Tests/Constraints/AllTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Validator\Constraints\All;
1616
use Symfony\Component\Validator\Constraints\Valid;
1717
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
18+
use Symfony\Component\Validator\Exception\MissingOptionsException;
1819

1920
/**
2021
* @author Bernhard Schussek <[email protected]>
@@ -36,4 +37,20 @@ public function testRejectValidConstraint()
3637
new Valid(),
3738
]);
3839
}
40+
41+
public function testMissingConstraints()
42+
{
43+
$this->expectException(MissingOptionsException::class);
44+
$this->expectExceptionMessage(\sprintf('The options "constraints" must be set for constraint "%s".', All::class));
45+
46+
new All(null);
47+
}
48+
49+
public function testMissingConstraintsDoctrineStyle()
50+
{
51+
$this->expectException(MissingOptionsException::class);
52+
$this->expectExceptionMessage(\sprintf('The options "constraints" must be set for constraint "%s".', All::class));
53+
54+
new All([]);
55+
}
3956
}

Tests/Constraints/AtLeastOneOfTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Validator\Constraints\AtLeastOneOf;
1616
use Symfony\Component\Validator\Constraints\Valid;
1717
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
18+
use Symfony\Component\Validator\Exception\MissingOptionsException;
1819

1920
/**
2021
* @author Przemysław Bogusz <[email protected]>
@@ -36,4 +37,20 @@ public function testRejectValidConstraint()
3637
new Valid(),
3738
]);
3839
}
40+
41+
public function testMissingConstraints()
42+
{
43+
$this->expectException(MissingOptionsException::class);
44+
$this->expectExceptionMessage(\sprintf('The options "constraints" must be set for constraint "%s".', AtLeastOneOf::class));
45+
46+
new AtLeastOneOf(null);
47+
}
48+
49+
public function testMissingConstraintsDoctrineStyle()
50+
{
51+
$this->expectException(MissingOptionsException::class);
52+
$this->expectExceptionMessage(\sprintf('The options "constraints" must be set for constraint "%s".', AtLeastOneOf::class));
53+
54+
new AtLeastOneOf([]);
55+
}
3956
}

Tests/Constraints/CardSchemeTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Validator\Constraints\CardScheme;
16+
use Symfony\Component\Validator\Exception\MissingOptionsException;
1617
use Symfony\Component\Validator\Mapping\ClassMetadata;
1718
use Symfony\Component\Validator\Mapping\Loader\AttributeLoader;
1819

@@ -37,6 +38,14 @@ public function testAttributes()
3738
self::assertSame(['my_group'], $cConstraint->groups);
3839
self::assertSame('some attached data', $cConstraint->payload);
3940
}
41+
42+
public function testMissingSchemes()
43+
{
44+
$this->expectException(MissingOptionsException::class);
45+
$this->expectExceptionMessage(\sprintf('The options "schemes" must be set for constraint "%s".', CardScheme::class));
46+
47+
new CardScheme(null);
48+
}
4049
}
4150

4251
class CardSchemeDummy

Tests/Constraints/CollectionTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Component\Validator\Constraints\Valid;
2020
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
2121
use Symfony\Component\Validator\Exception\InvalidOptionsException;
22+
use Symfony\Component\Validator\Exception\MissingOptionsException;
2223

2324
/**
2425
* @author Bernhard Schussek <[email protected]>
@@ -209,4 +210,12 @@ public function testEmptyConstraintListForFieldInOptions(?array $fieldConstraint
209210
$this->assertTrue($constraint->allowExtraFields);
210211
$this->assertSame('foo bar baz', $constraint->extraFieldsMessage);
211212
}
213+
214+
public function testMissingFields()
215+
{
216+
$this->expectException(MissingOptionsException::class);
217+
$this->expectExceptionMessage(\sprintf('The options "fields" must be set for constraint "%s".', Collection::class));
218+
219+
new Collection(null);
220+
}
212221
}

Tests/Constraints/CssColorTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,46 @@ public function testAttributes()
4040
self::assertSame(['my_group'], $cConstraint->groups);
4141
self::assertSame('some attached data', $cConstraint->payload);
4242
}
43+
44+
public function testMissingPattern()
45+
{
46+
$constraint = new CssColor(null);
47+
48+
$this->assertSame([
49+
CssColor::HEX_LONG,
50+
CssColor::HEX_LONG_WITH_ALPHA,
51+
CssColor::HEX_SHORT,
52+
CssColor::HEX_SHORT_WITH_ALPHA,
53+
CssColor::BASIC_NAMED_COLORS,
54+
CssColor::EXTENDED_NAMED_COLORS,
55+
CssColor::SYSTEM_COLORS,
56+
CssColor::KEYWORDS,
57+
CssColor::RGB,
58+
CssColor::RGBA,
59+
CssColor::HSL,
60+
CssColor::HSLA,
61+
], $constraint->formats);
62+
}
63+
64+
public function testMissingPatternDoctrineStyle()
65+
{
66+
$constraint = new CssColor([]);
67+
68+
$this->assertSame([
69+
CssColor::HEX_LONG,
70+
CssColor::HEX_LONG_WITH_ALPHA,
71+
CssColor::HEX_SHORT,
72+
CssColor::HEX_SHORT_WITH_ALPHA,
73+
CssColor::BASIC_NAMED_COLORS,
74+
CssColor::EXTENDED_NAMED_COLORS,
75+
CssColor::SYSTEM_COLORS,
76+
CssColor::KEYWORDS,
77+
CssColor::RGB,
78+
CssColor::RGBA,
79+
CssColor::HSL,
80+
CssColor::HSLA,
81+
], $constraint->formats);
82+
}
4383
}
4484

4585
class CssColorDummy

0 commit comments

Comments
 (0)