File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed
tests/JsonSchema/Tests/Constraints Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change 9
9
10
10
namespace JsonSchema \Tests \Constraints ;
11
11
12
+ use JsonSchema \Constraints \UndefinedConstraint ;
13
+
12
14
class RequiredPropertyTest extends BaseTestCase
13
15
{
16
+
17
+ public function testErrorPropertyIsPopulatedForRequiredIfMissingInInput ()
18
+ {
19
+ $ validator = new UndefinedConstraint ();
20
+ $ document = json_decode ('{
21
+ "bar": 42
22
+ } ' );
23
+ $ schema = json_decode ('{
24
+ "type": "object",
25
+ "properties": {
26
+ "foo": {"type": "number"},
27
+ "bar": {"type": "number"}
28
+ },
29
+ "required": ["foo"]
30
+ } ' );
31
+
32
+ $ validator ->check ($ document , $ schema );
33
+ $ error = $ validator ->getErrors ();
34
+ $ this ->assertEquals ('foo ' , $ error [0 ]['property ' ]);
35
+ }
36
+
37
+ public function testErrorPropertyIsPopulatedForRequiredIfEmptyValueInInput ()
38
+ {
39
+ $ validator = new UndefinedConstraint ();
40
+ $ document = json_decode ('{
41
+ "bar": 42,
42
+ "foo": null
43
+ } ' );
44
+ $ schema = json_decode ('{
45
+ "type": "object",
46
+ "properties": {
47
+ "foo": {"type": "number"},
48
+ "bar": {"type": "number"}
49
+ },
50
+ "required": ["foo"]
51
+ } ' );
52
+
53
+ $ validator ->check ($ document , $ schema );
54
+ $ error = $ validator ->getErrors ();
55
+ $ this ->assertEquals ('foo ' , $ error [0 ]['property ' ]);
56
+ }
57
+
14
58
public function getInvalidTests ()
15
59
{
16
60
return array (
You can’t perform that action at this time.
0 commit comments