Skip to content

Commit 2478de5

Browse files
bug symfony#61084 [Validator] fix BC layer for Expression constraint from options array (xabbuh)
This PR was merged into the 7.4 branch. Discussion ---------- [Validator] fix BC layer for Expression constraint from options array | Q | A | ------------- | --- | Branch? | 7.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | | License | MIT see e.g. https://github.com/symfony/symfony/actions/runs/16165806927/job/45627315188#step:8:7084 Commits ------- c722388 fix BC layer for Expression constraint from options array
2 parents 51ec885 + c722388 commit 2478de5

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/Symfony/Component/Validator/Constraints/Expression.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public function __construct(
6464
trigger_deprecation('symfony/validator', '7.3', 'Passing an array of options to configure the "%s" constraint is deprecated, use named arguments instead.', static::class);
6565

6666
$options = array_merge($expression, $options ?? []);
67+
$expression = null;
6768
} else {
6869
if (\is_array($options)) {
6970
trigger_deprecation('symfony/validator', '7.3', 'Passing an array of options to configure the "%s" constraint is deprecated, use named arguments instead.', static::class);

src/Symfony/Component/Validator/Tests/Constraints/ExpressionTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ public function testAttributes()
4141
self::assertSame('some attached data', $cConstraint->payload);
4242
self::assertFalse($cConstraint->negate);
4343
}
44+
45+
/**
46+
* @group legacy
47+
*/
48+
public function testInitializeWithOptionsArray()
49+
{
50+
$constraint = new Expression([
51+
'expression' => '!this.getParent().get("field2").getData()',
52+
]);
53+
54+
$this->assertSame('!this.getParent().get("field2").getData()', $constraint->expression);
55+
}
4456
}
4557

4658
class ExpressionDummy

0 commit comments

Comments
 (0)