Skip to content

Commit 8a01101

Browse files
committed
Fix FormTypeClass constraint constructor for Symfony 8.1 compatibility
Constraint::__construct() no longer processes options arrays to set properties. Use an explicit named message parameter instead, and update the test to match.
1 parent 77965cf commit 8a01101

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

src/Validator/Constraints/FormTypeClass.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ class FormTypeClass extends Constraint
2424
{
2525
public string $message;
2626

27-
public function __construct($options = null)
28-
{
27+
public function __construct(
28+
?string $message = null,
29+
?array $groups = null,
30+
mixed $payload = null,
31+
) {
2932
$conditionsStr = vsprintf(
3033
'It should extend %s, implement %s or tagged %s',
3134
[
@@ -34,8 +37,8 @@ public function __construct($options = null)
3437
'silverback_api_components.form_type',
3538
]
3639
);
37-
$this->message = 'The string "{{ string }}" does not refer to a class configured correctly as a form type. ' . $conditionsStr;
40+
$this->message = $message ?? 'The string "{{ string }}" does not refer to a class configured correctly as a form type. ' . $conditionsStr;
3841

39-
parent::__construct($options);
42+
parent::__construct([], $groups, $payload);
4043
}
4144
}

tests/Validator/Constraints/FormTypeClassValidatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public function test_constraint_violation_for_string_that_is_not_a_class(): void
141141

142142
public function test_form_type_class_options_passed_to_parent(): void
143143
{
144-
$constraint = new FormTypeClass(['message' => 'different message option']);
144+
$constraint = new FormTypeClass(message: 'different message option');
145145
$this->assertEquals('different message option', $constraint->message);
146146
}
147147
}

0 commit comments

Comments
 (0)