json-schema/tests/Constraints/OfPropertiesTest.php
Mirosław Filip 346b3218dd Bump json-schema/JSON-Schema-Test-Suite to 1.2.0. Add data set
description for failing tests. Flatten directory structure

Use "test.json / suite description / test case description" notation in data provider to allow a readable test output

Skip Draft3Test / Draft4Test tests which are not passing

Add some comment to skipped tests
2016-05-09 23:42:42 +02:00

211 lines
6.0 KiB
PHP

<?php
/*
* This file is part of the JsonSchema package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace JsonSchema\Tests\Constraints;
use JsonSchema\Validator;
/**
* Class OfPropertiesTest
*/
class OfPropertiesTest extends BaseTestCase
{
public function getValidTests()
{
return array(
array(
'{"prop1": "abc"}',
'{
"type": "object",
"properties": {
"prop1": {"type": "string"},
"prop2": {
"oneOf": [
{"type": "number"},
{"type": "string"}
]
}
},
"required": ["prop1"]
}'
),
array(
'{"prop1": "abc", "prop2": 23}',
'{
"type": "object",
"properties": {
"prop1": {"type": "string"},
"prop2": {
"oneOf": [
{"type": "number"},
{"type": "string"}
]
}
},
"required": ["prop1"]
}'
),
);
}
public function getInvalidTests()
{
return array(
array(
'{"prop1": "abc", "prop2": []}',
'{
"type": "object",
"properties": {
"prop1": {"type": "string"},
"prop2": {
"oneOf": [
{"type": "number"},
{"type": "string"}
]
}
},
"required": ["prop1"]
}',
Validator::CHECK_MODE_NORMAL,
array(
array(
"property" => "prop2",
"message" => "Array value found, but a string is required",
"constraint" => "type",
),
array(
"property" => "prop2",
"message" => "Array value found, but a number is required",
"constraint" => "type",
),
array(
"property" => "prop2",
"message" => "Failed to match exactly one schema",
"constraint" => "oneOf",
),
),
),
array(
'{"prop1": [1,2]}',
'{
"type": "object",
"properties": {
"prop1": {
"oneOf": [
{
"type": "string",
"pattern": "^[a-z]*$"
},
{
"type": "string",
"pattern": "^[A-Z]*$"
}
]
}
}
}'
),
array(
'{"prop1": [1,2]}',
'{
"type": "object",
"properties": {
"prop1": {
"anyOf": [
{
"type": "string",
"pattern": "^[A-Z]*$"
}
]
}
}
}'
),
array(
'{"prop1": [1,2]}',
'{
"type": "object",
"properties": {
"prop1": {
"anyOf": [
{
"type": "number"
},
{
"type": "string",
"pattern": "^[A-Z]*$"
}
]
}
}
}'
),
array(
'{"prop1": [1,2]}',
'{
"type": "object",
"properties": {
"prop1": {
"anyOf": [
{
"type": "string"
},
{
"type": "string",
"pattern": "^[A-Z]*$"
}
]
}
}
}'
),
array(
'{"prop1": [1,2]}',
'{
"type": "object",
"properties": {
"prop1": {
"anyOf": [
{
"type": "string",
"pattern": "^[a-z]*$"
},
{
"type": "string",
"pattern": "^[A-Z]*$"
}
]
}
}
}'
),
array(
'{"prop1": [1,2]}',
'{
"type": "object",
"properties": {
"prop1": {
"anyOf": [
{
"type": "number"
},
{
"type": "string"
},
{
"type": "string"
}
]
}
}
}'
)
);
}
}