Skip to content

Commit af6547d

Browse files
Merge branch '7.2' into 7.3
* 7.2: [DoctrineBridge] Prevent idle connection listener from running on subrequests [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 e8bd700 + 85067b0 commit af6547d

17 files changed

+225
-59
lines changed

Constraints/CardScheme.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ public function __construct(array|string|null $schemes, ?string $message = null,
6666
$options = [];
6767
}
6868

69-
$options['value'] = $schemes;
69+
if (null !== $schemes) {
70+
$options['value'] = $schemes;
71+
}
7072
}
7173

7274
parent::__construct($options, $groups, $payload);

Constraints/Composite.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function __construct(mixed $options = null, ?array $groups = null, mixed
5858
$this->initializeNestedConstraints();
5959

6060
foreach ((array) $this->getCompositeOption() as $option) {
61-
/* @var Constraint[] $nestedConstraints */
61+
/** @var Constraint[] $nestedConstraints */
6262
$nestedConstraints = $this->$option;
6363

6464
if (!\is_array($nestedConstraints)) {

Constraints/Expression.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ public function __construct(
7171
$options = [];
7272
}
7373

74-
$options['value'] = $expression;
74+
if (null !== $expression) {
75+
$options['value'] = $expression;
76+
}
7577
}
7678

7779
parent::__construct($options, $groups, $payload);

Constraints/When.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ public function __construct(string|Expression|array|\Closure $expression, array|
5757
}
5858

5959
$options['expression'] = $expression;
60-
$options['constraints'] = $constraints;
60+
if (null !== $constraints) {
61+
$options['constraints'] = $constraints;
62+
}
6163
$options['otherwise'] = $otherwise;
6264
}
6365

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]>
@@ -207,4 +208,12 @@ public function testEmptyConstraintListForFieldInOptions(?array $fieldConstraint
207208
$this->assertTrue($constraint->allowExtraFields);
208209
$this->assertSame('foo bar baz', $constraint->extraFieldsMessage);
209210
}
211+
212+
public function testMissingFields()
213+
{
214+
$this->expectException(MissingOptionsException::class);
215+
$this->expectExceptionMessage(\sprintf('The options "fields" must be set for constraint "%s".', Collection::class));
216+
217+
new Collection(null);
218+
}
210219
}

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)