Skip to content

Commit 3131495

Browse files
author
Bruce Chase
committed
ArraysTest for array items with enum validation
Tests number, integer and string array items types that have enums of acceptable values
1 parent f981a46 commit 3131495

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

tests/Constraints/ArraysTest.php

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,51 @@ public function getInvalidTests()
7171
}
7272
}
7373
}'
74+
),
75+
array( // Test array items.enum where type string fail validation if value(s) is/are not in items.enum
76+
'{"data": ["a", "b"]}',
77+
'{
78+
"type": "object",
79+
"properties": {
80+
"data": {
81+
"type": "array",
82+
"items": {
83+
"type": "string",
84+
"enum": ["b", "c"]
85+
}
86+
}
87+
}
88+
}'
89+
),
90+
array( // Test array items.enum where type integer fail validation if value(s) is/are not in items.enum
91+
'{"data": [1, 2]}',
92+
'{
93+
"type": "object",
94+
"properties": {
95+
"data": {
96+
"type": "array",
97+
"items": {
98+
"type": "integer",
99+
"enum": [2, 3]
100+
}
101+
}
102+
}
103+
}'
104+
),
105+
array( // Test array items.enum where type number fail validation if value(s) is/are not in items.enum
106+
'{"data": [1.25, 2.25]}',
107+
'{
108+
"type": "object",
109+
"properties": {
110+
"data": {
111+
"type": "array",
112+
"items": {
113+
"type": "number",
114+
"enum": [1.25, 2]
115+
}
116+
}
117+
}
118+
}'
74119
)
75120
);
76121
}
@@ -168,6 +213,51 @@ public function getValidTests()
168213
}
169214
}
170215
}'
216+
),
217+
array( // Test array items.enum where type string passes validation if value(s) is/are in items.enum
218+
'{"data": ["c", "c", "b"]}',
219+
'{
220+
"type": "object",
221+
"properties": {
222+
"data": {
223+
"type": "array",
224+
"items": {
225+
"type": "string",
226+
"enum": ["b", "c"]
227+
}
228+
}
229+
}
230+
}'
231+
),
232+
array( // Test array items.enum where type integer passes validation if value(s) is/are in items.enum
233+
'{"data": [1, 1, 2]}',
234+
'{
235+
"type": "object",
236+
"properties": {
237+
"data": {
238+
"type": "array",
239+
"items": {
240+
"type": "integer",
241+
"enum": [1, 2]
242+
}
243+
}
244+
}
245+
}'
246+
),
247+
array( // Test array items.enum where type number passes validation if value(s) is/are in items.enum
248+
'{"data": [1.25, 1.25, 2.25]}',
249+
'{
250+
"type": "object",
251+
"properties": {
252+
"data": {
253+
"type": "array",
254+
"items": {
255+
"type": "number",
256+
"enum": [1.25, 2.25]
257+
}
258+
}
259+
}
260+
}'
171261
)
172262
);
173263
}

0 commit comments

Comments
 (0)