9
9
10
10
namespace JsonSchema \Tests \Constraints ;
11
11
12
+ use JsonSchema \Constraints \Constraint ;
13
+
12
14
class MinMaxPropertiesTest extends BaseTestCase
13
15
{
14
16
protected $ validateSchema = true ;
@@ -19,50 +21,71 @@ class MinMaxPropertiesTest extends BaseTestCase
19
21
public function getValidTests (): array
20
22
{
21
23
return [
22
- [
23
- '{
24
+ ' Empty object with minProperties: 0 ' => [
25
+ 'input ' => ' {
24
26
"value": {}
25
27
} ' ,
26
- '{
28
+ 'schema ' => ' {
27
29
"type": "object",
28
30
"properties": {
29
31
"value": {"type": "object", "minProperties": 0}
30
32
}
31
33
} '
32
34
],
33
- [
34
- '{
35
+ ' Empty object with maxProperties: 1 ' => [
36
+ 'input ' => ' {
35
37
"value": {}
36
38
} ' ,
37
- '{
39
+ 'schema ' => ' {
38
40
"type": "object",
39
41
"properties": {
40
42
"value": {"type": "object", "maxProperties": 1}
41
43
}
42
44
} '
43
45
],
44
- [
45
- '{
46
+ ' Empty object with minProperties: 0 and maxProperties: 1 ' => [
47
+ 'input ' => ' {
46
48
"value": {}
47
49
} ' ,
48
- '{
50
+ 'schema ' => ' {
49
51
"type": "object",
50
52
"properties": {
51
53
"value": {"type": "object", "minProperties": 0,"maxProperties": 1}
52
54
}
53
55
} '
54
56
],
55
- [
56
- '{
57
+ ' Object with two properties with minProperties: 1 and maxProperties: 2 ' => [
58
+ 'input ' => ' {
57
59
"value": {"foo": 1, "bar": 2}
58
60
} ' ,
59
- '{
61
+ 'schema ' => ' {
60
62
"type": "object",
61
63
"properties": {
62
64
"value": {"type": "object", "minProperties": 1,"maxProperties": 2}
63
65
}
64
66
} '
65
67
],
68
+ 'Empty array with minProperties: 1 and maxProperties: 2 ' => [
69
+ 'input ' => '{
70
+ "value": []
71
+ } ' ,
72
+ 'schema ' => '{
73
+ "properties": {
74
+ "value": {"minProperties": 1,"maxProperties": 2}
75
+ }
76
+ } ' ,
77
+ 'checkMode ' => Constraint::CHECK_MODE_NORMAL ,
78
+ ],
79
+ 'Array with two items with maxProperties: 1 ' => [
80
+ 'input ' => '{
81
+ "value": [1, 2]
82
+ } ' ,
83
+ 'schema ' => '{
84
+ "properties": {
85
+ "value": {"maxProperties": 1}
86
+ }
87
+ } '
88
+ ],
66
89
];
67
90
}
68
91
@@ -72,20 +95,20 @@ public function getValidTests(): array
72
95
public function getInvalidTests (): array
73
96
{
74
97
return [
75
- [
76
- '{
98
+ ' Empty object with minProperties: 1 ' => [
99
+ 'input ' => ' {
77
100
"value": {}
78
101
} ' ,
79
- '{
102
+ 'schema ' => ' {
80
103
"type": "object",
81
104
"properties": {
82
105
"value": {"type": "object", "minProperties": 1}
83
106
}
84
107
} '
85
108
],
86
- [
87
- '{} ' ,
88
- '{
109
+ ' Empty object with minProperties ' => [
110
+ 'input ' => ' {} ' ,
111
+ 'schema ' => ' {
89
112
"type": "object",
90
113
"properties": {
91
114
"propertyOne": {
@@ -98,41 +121,31 @@ public function getInvalidTests(): array
98
121
"minProperties": 1
99
122
} '
100
123
],
101
- [
102
- '{
124
+ ' Object with two properties with maxProperties: 1 ' => [
125
+ 'input ' => ' {
103
126
"value": {
104
127
"propertyOne": "valueOne",
105
128
"propertyTwo": "valueTwo"
106
129
}
107
130
} ' ,
108
- '{
131
+ 'schema ' => ' {
109
132
"type": "object",
110
133
"properties": {
111
134
"value": {"type": "object", "maxProperties": 1}
112
135
}
113
136
} '
114
137
],
115
- [
116
- '{
138
+ ' Object with two properties with minProperties: 1 and maxProperties: 2 ' => [
139
+ 'input ' => ' {
117
140
"value": {"foo": 1, "bar": 2, "baz": 3}
118
141
} ' ,
119
- '{
142
+ 'schema ' => ' {
120
143
"type": "object",
121
144
"properties": {
122
145
"value": {"type": "object", "minProperties": 1,"maxProperties": 2}
123
146
}
124
147
} '
125
148
],
126
- [
127
- '{
128
- "value": []
129
- } ' ,
130
- '{
131
- "properties": {
132
- "value": {"minProperties": 1,"maxProperties": 2}
133
- }
134
- } '
135
- ],
136
149
];
137
150
}
138
151
}
0 commit comments