Skip to content

Commit 04fed36

Browse files
committed
Merge pull request #98 from alexmmm/fix-constraint-errors-getter
Fix constraint errors getter
2 parents 99fa58a + 0c39a5b commit 04fed36

File tree

3 files changed

+117
-2
lines changed

3 files changed

+117
-2
lines changed

src/JsonSchema/Constraints/Constraint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function addErrors(array $errors)
8282
*/
8383
public function getErrors()
8484
{
85-
return array_unique($this->errors, SORT_REGULAR);
85+
return $this->errors;
8686
}
8787

8888
/**

src/JsonSchema/Validator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ public function check($value, $schema = null, $path = null, $i = null)
4040
$validator = new Schema($this->checkMode, $this->uriRetriever);
4141
$validator->check($value, $schema);
4242

43-
$this->addErrors($validator->getErrors());
43+
$this->addErrors(array_unique($validator->getErrors(), SORT_REGULAR));
4444
}
4545
}

tests/JsonSchema/Tests/Constraints/OfPropertiesTest.php

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,121 @@ public function getInvalidTests()
8888
),
8989
),
9090
),
91+
array(
92+
'{"prop1": [1,2]}',
93+
'{
94+
"type": "object",
95+
"properties": {
96+
"prop1": {
97+
"oneOf": [
98+
{
99+
"type": "string",
100+
"pattern": "^[a-z]*$"
101+
},
102+
{
103+
"type": "string",
104+
"pattern": "^[A-Z]*$"
105+
}
106+
]
107+
}
108+
}
109+
}'
110+
),
111+
array(
112+
'{"prop1": [1,2]}',
113+
'{
114+
"type": "object",
115+
"properties": {
116+
"prop1": {
117+
"anyOf": [
118+
{
119+
"type": "string",
120+
"pattern": "^[A-Z]*$"
121+
}
122+
]
123+
}
124+
}
125+
}'
126+
),
127+
array(
128+
'{"prop1": [1,2]}',
129+
'{
130+
"type": "object",
131+
"properties": {
132+
"prop1": {
133+
"anyOf": [
134+
{
135+
"type": "number"
136+
},
137+
{
138+
"type": "string",
139+
"pattern": "^[A-Z]*$"
140+
}
141+
]
142+
}
143+
}
144+
}'
145+
),
146+
array(
147+
'{"prop1": [1,2]}',
148+
'{
149+
"type": "object",
150+
"properties": {
151+
"prop1": {
152+
"anyOf": [
153+
{
154+
"type": "string"
155+
},
156+
{
157+
"type": "string",
158+
"pattern": "^[A-Z]*$"
159+
}
160+
]
161+
}
162+
}
163+
}'
164+
),
165+
array(
166+
'{"prop1": [1,2]}',
167+
'{
168+
"type": "object",
169+
"properties": {
170+
"prop1": {
171+
"anyOf": [
172+
{
173+
"type": "string",
174+
"pattern": "^[a-z]*$"
175+
},
176+
{
177+
"type": "string",
178+
"pattern": "^[A-Z]*$"
179+
}
180+
]
181+
}
182+
}
183+
}'
184+
),
185+
array(
186+
'{"prop1": [1,2]}',
187+
'{
188+
"type": "object",
189+
"properties": {
190+
"prop1": {
191+
"anyOf": [
192+
{
193+
"type": "number"
194+
},
195+
{
196+
"type": "string"
197+
},
198+
{
199+
"type": "string"
200+
}
201+
]
202+
}
203+
}
204+
}'
205+
)
91206
);
92207
}
93208
}

0 commit comments

Comments
 (0)