Skip to content

Commit 5cc0bae

Browse files
committed
feat(when constraint): pass context and root
1 parent b4951b3 commit 5cc0bae

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/Symfony/Component/Validator/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ CHANGELOG
1212
* Add the `WordCount` constraint
1313
* Add the `Week` constraint
1414
* Add `CompoundConstraintTestCase` to ease testing Compound Constraints
15+
* Add context variable to `WhenValidator`
1516

1617
7.1
1718
---

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,30 @@ public function testConstraintsAreExecutedWithObject()
8585
]));
8686
}
8787

88+
public function testConstraintsAreExecutedWithNestedObject()
89+
{
90+
$parent = new \stdClass();
91+
$parent->child = new \stdClass();
92+
$parent->ok = true;
93+
94+
$number = new \stdClass();
95+
$number->value = 1;
96+
97+
$this->setObject($parent);
98+
$this->setPropertyPath('child.value');
99+
100+
$constraints = [
101+
new PositiveOrZero(),
102+
];
103+
104+
$this->expectValidateValue(0, $number->value, $constraints);
105+
106+
$this->validator->validate($number->value, new When([
107+
'expression' => 'context.root.ok === true',
108+
'constraints' => $constraints,
109+
]));
110+
}
111+
88112
public function testConstraintsAreExecutedWithValue()
89113
{
90114
$constraints = [

0 commit comments

Comments
 (0)