Skip to content

Commit bf4207c

Browse files
committed
[Validator] Add $groups and $payload to Compound constructor
1 parent b7fe7ef commit bf4207c

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ abstract class Compound extends Composite
2424
/** @var Constraint[] */
2525
public array $constraints = [];
2626

27-
public function __construct(mixed $options = null)
27+
public function __construct(mixed $options = null, ?array $groups = null, mixed $payload = null)
2828
{
2929
if (isset($options[$this->getCompositeOption()])) {
3030
throw new ConstraintDefinitionException(\sprintf('You can\'t redefine the "%s" option. Use the "%s::getConstraints()" method instead.', $this->getCompositeOption(), __CLASS__));
3131
}
3232

3333
$this->constraints = $this->getConstraints($this->normalizeOptions($options));
3434

35-
parent::__construct($options);
35+
parent::__construct($options, $groups, $payload);
3636
}
3737

3838
final protected function getCompositeOption(): string

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,24 @@ public function testItCannotRedefineConstraintsOption()
2626
new EmptyCompound(['constraints' => [new NotBlank()]]);
2727
}
2828

29+
public function testGroupsAndPayload()
30+
{
31+
$payload = new \stdClass();
32+
$compound = new EmptyCompound(groups: ['my-group', 'my-other-group'], payload: $payload);
33+
34+
$this->assertSame(['my-group', 'my-other-group'], $compound->groups);
35+
$this->assertSame($payload, $compound->payload);
36+
}
37+
38+
public function testGroupsAndPayloadInOptionsArray()
39+
{
40+
$payload = new \stdClass();
41+
$compound = new EmptyCompound(['groups' => ['my-group', 'my-other-group'], 'payload' => $payload]);
42+
43+
$this->assertSame(['my-group', 'my-other-group'], $compound->groups);
44+
$this->assertSame($payload, $compound->payload);
45+
}
46+
2947
public function testCanDependOnNormalizedOptions()
3048
{
3149
$constraint = new ForwardingOptionCompound($min = 3);

0 commit comments

Comments
 (0)