File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed
src/Symfony/Component/Validator Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ CHANGELOG
12
12
* Add the ` WordCount ` constraint
13
13
* Add the ` Week ` constraint
14
14
* Add ` CompoundConstraintTestCase ` to ease testing Compound Constraints
15
+ * Add context variable to ` WhenValidator `
15
16
16
17
7.1
17
18
---
Original file line number Diff line number Diff line change @@ -85,6 +85,30 @@ public function testConstraintsAreExecutedWithObject()
85
85
]));
86
86
}
87
87
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
+
88
112
public function testConstraintsAreExecutedWithValue ()
89
113
{
90
114
$ constraints = [
You can’t perform that action at this time.
0 commit comments