@@ -13,153 +13,149 @@ class UniqueItemsTest extends BaseTestCase
1313{
1414 protected $ validateSchema = true ;
1515
16- public function getInvalidTests (): array
17- {
18- return [
19- 'Non unique integers ' => [
20- 'input ' => '[1,2,2] ' ,
21- 'schema ' => '{
22- "type":"array",
23- "uniqueItems": true
24- } '
25- ],
26- 'Non unique objects ' => [
27- 'input ' => '[{"a":"b"},{"a":"c"},{"a":"b"}] ' ,
28- 'schema ' => '{
29- "type":"array",
30- "uniqueItems": true
31- } '
32- ],
33- 'Non unique objects - three levels deep ' => [
34- 'input ' => '[{"foo": {"bar" : {"baz" : true}}}, {"foo": {"bar" : {"baz" : true}}}] ' ,
35- 'schema ' => '{
36- "type": "array",
37- "uniqueItems": true
38- } '
39- ],
40- 'Non unique mathematical values for the number one ' => [
41- 'input ' => '[1.0, 1.00, 1] ' ,
42- 'schema ' => '{
43- "type": "array",
44- "uniqueItems": true
45- } '
46- ],
47- 'Non unique arrays ' => [
48- 'input ' => '[["foo"], ["foo"]] ' ,
49- 'schema ' => '{
50- "type": "array",
51- "uniqueItems": true
52- } '
53- ],
54- 'Non unique mix of different types ' => [
55- 'input ' => '[{}, [1], true, null, {}, 1] ' ,
56- 'schema ' => '{
57- "type": "array",
58- "uniqueItems": true
59- } '
60- ],
61- 'objects are non-unique despite key order ' => [
62- 'input ' => '[{"a": 1, "b": 2}, {"b": 2, "a": 1}] ' ,
63- 'schema ' => '{"uniqueItems": true} ' ,
64- ]
16+ public function getInvalidTests (): \Generator
17+ {
18+ yield 'Non unique integers ' => [
19+ 'input ' => '[1,2,2] ' ,
20+ 'schema ' => '{
21+ "type":"array",
22+ "uniqueItems": true
23+ } '
24+ ];
25+ yield 'Non unique objects ' => [
26+ 'input ' => '[{"a":"b"},{"a":"c"},{"a":"b"}] ' ,
27+ 'schema ' => '{
28+ "type":"array",
29+ "uniqueItems": true
30+ } '
31+ ];
32+ yield 'Non unique objects - three levels deep ' => [
33+ 'input ' => '[{"foo": {"bar" : {"baz" : true}}}, {"foo": {"bar" : {"baz" : true}}}] ' ,
34+ 'schema ' => '{
35+ "type": "array",
36+ "uniqueItems": true
37+ } '
38+ ];
39+ yield 'Non unique mathematical values for the number one ' => [
40+ 'input ' => '[1.0, 1.00, 1] ' ,
41+ 'schema ' => '{
42+ "type": "array",
43+ "uniqueItems": true
44+ } '
45+ ];
46+ yield 'Non unique arrays ' => [
47+ 'input ' => '[["foo"], ["foo"]] ' ,
48+ 'schema ' => '{
49+ "type": "array",
50+ "uniqueItems": true
51+ } '
52+ ];
53+ yield 'Non unique mix of different types ' => [
54+ 'input ' => '[{}, [1], true, null, {}, 1] ' ,
55+ 'schema ' => '{
56+ "type": "array",
57+ "uniqueItems": true
58+ } '
59+ ];
60+ yield 'objects are non-unique despite key order ' => [
61+ 'input ' => '[{"a": 1, "b": 2}, {"b": 2, "a": 1}] ' ,
62+ 'schema ' => '{"uniqueItems": true} ' ,
6563 ];
6664 }
6765
68- public function getValidTests (): array
66+ public function getValidTests (): \ Generator
6967 {
70- return [
71- 'unique integers ' => [
72- 'input ' => '[1,2,3] ' ,
73- 'schema ' => '{
74- "type":"array",
75- "uniqueItems": true
76- } '
77- ],
78- 'unique objects ' =>[
79- 'input ' => '[{"foo": 12}, {"bar": false}] ' ,
80- 'schema ' => '{
81- "type": "array",
82- "uniqueItems": true
83- } '
84- ],
85- 'Integer one and boolean true ' => [
86- 'input ' => '[1, true] ' ,
87- 'schema ' => '{
88- "type": "array",
89- "uniqueItems": true
90- } '
91- ],
92- 'Integer zero and boolean false ' => [
93- 'input ' => '[0, false] ' ,
94- 'schema ' => '{
95- "type": "array",
96- "uniqueItems": true
97- } '
98- ],
99- 'Objects with different value three levels deep ' => [
100- 'input ' => '[{"foo": {"bar" : {"baz" : true}}}, {"foo": {"bar" : {"baz" : false}}}] ' ,
101- 'schema ' => '{
102- "type": "array",
103- "uniqueItems": true
104- } '
105- ],
106- 'Array of strings ' => [
107- 'input ' => '[["foo"], ["bar"]] ' ,
108- 'schema ' => '{
109- "type": "array",
110- "uniqueItems": true
111- } '
112- ],
113- 'Object, Array, boolean, null and integer ' => [
114- 'input ' => '[{}, [1], true, null, 1] ' ,
115- 'schema ' => '{
116- "type": "array",
117- "uniqueItems": true
118- } '
119- ],
120- // below equals the invalid tests, but with uniqueItems set to false
121- 'Non unique integers ' => [
122- 'input ' => '[1,2,2] ' ,
123- 'schema ' => '{
124- "type":"array",
125- "uniqueItems": false
126- } '
127- ],
128- 'Non unique objects ' => [
129- 'input ' => '[{"a":"b"},{"a":"c"},{"a":"b"}] ' ,
130- 'schema ' => '{
131- "type":"array",
132- "uniqueItems": false
133- } '
134- ],
135- 'Non unique objects - three levels deep ' => [
136- 'input ' => '[{"foo": {"bar" : {"baz" : true}}}, {"foo": {"bar" : {"baz" : true}}}] ' ,
137- 'schema ' => '{
138- "type": "array",
139- "uniqueItems": false
140- } '
141- ],
142- 'Non unique mathematical values for the number one ' => [
143- 'input ' => '[1.0, 1.00, 1] ' ,
144- 'schema ' => '{
145- "type": "array",
146- "uniqueItems": false
147- } '
148- ],
149- 'Non unique arrays ' => [
150- 'input ' => '[["foo"], ["foo"]] ' ,
151- 'schema ' => '{
152- "type": "array",
153- "uniqueItems": false
154- } '
155- ],
156- 'Non unique mix of different types ' => [
157- 'input ' => '[{}, [1], true, null, {}, 1] ' ,
158- 'schema ' => '{
159- "type": "array",
160- "uniqueItems": false
161- } '
162- ]
68+ yield 'unique integers ' => [
69+ 'input ' => '[1,2,3] ' ,
70+ 'schema ' => '{
71+ "type":"array",
72+ "uniqueItems": true
73+ } '
74+ ];
75+ yield 'unique objects ' =>[
76+ 'input ' => '[{"foo": 12}, {"bar": false}] ' ,
77+ 'schema ' => '{
78+ "type": "array",
79+ "uniqueItems": true
80+ } '
81+ ];
82+ yield 'Integer one and boolean true ' => [
83+ 'input ' => '[1, true] ' ,
84+ 'schema ' => '{
85+ "type": "array",
86+ "uniqueItems": true
87+ } '
88+ ];
89+ yield 'Integer zero and boolean false ' => [
90+ 'input ' => '[0, false] ' ,
91+ 'schema ' => '{
92+ "type": "array",
93+ "uniqueItems": true
94+ } '
95+ ];
96+ yield 'Objects with different value three levels deep ' => [
97+ 'input ' => '[{"foo": {"bar" : {"baz" : true}}}, {"foo": {"bar" : {"baz" : false}}}] ' ,
98+ 'schema ' => '{
99+ "type": "array",
100+ "uniqueItems": true
101+ } '
102+ ];
103+ yield 'Array of strings ' => [
104+ 'input ' => '[["foo"], ["bar"]] ' ,
105+ 'schema ' => '{
106+ "type": "array",
107+ "uniqueItems": true
108+ } '
109+ ];
110+ yield 'Object, Array, boolean, null and integer ' => [
111+ 'input ' => '[{}, [1], true, null, 1] ' ,
112+ 'schema ' => '{
113+ "type": "array",
114+ "uniqueItems": true
115+ } '
116+ ];
117+ // below equals the invalid tests, but with uniqueItems set to false
118+ yield 'Non unique integers ' => [
119+ 'input ' => '[1,2,2] ' ,
120+ 'schema ' => '{
121+ "type":"array",
122+ "uniqueItems": false
123+ } '
124+ ];
125+ yield 'Non unique objects ' => [
126+ 'input ' => '[{"a":"b"},{"a":"c"},{"a":"b"}] ' ,
127+ 'schema ' => '{
128+ "type":"array",
129+ "uniqueItems": false
130+ } '
131+ ];
132+ yield 'Non unique objects - three levels deep ' => [
133+ 'input ' => '[{"foo": {"bar" : {"baz" : true}}}, {"foo": {"bar" : {"baz" : true}}}] ' ,
134+ 'schema ' => '{
135+ "type": "array",
136+ "uniqueItems": false
137+ } '
138+ ];
139+ yield 'Non unique mathematical values for the number one ' => [
140+ 'input ' => '[1.0, 1.00, 1] ' ,
141+ 'schema ' => '{
142+ "type": "array",
143+ "uniqueItems": false
144+ } '
145+ ];
146+ yield 'Non unique arrays ' => [
147+ 'input ' => '[["foo"], ["foo"]] ' ,
148+ 'schema ' => '{
149+ "type": "array",
150+ "uniqueItems": false
151+ } '
152+ ];
153+ yield 'Non unique mix of different types ' => [
154+ 'input ' => '[{}, [1], true, null, {}, 1] ' ,
155+ 'schema ' => '{
156+ "type": "array",
157+ "uniqueItems": false
158+ } '
163159 ];
164160 }
165161}
0 commit comments