mirror of
https://github.com/justinrainbow/json-schema.git
synced 2025-03-20 22:29:44 +01:00
Starting to add error message testing to PHPUnit tests
This commit is contained in:
parent
1c0a28dbbc
commit
115585c154
@ -317,7 +317,7 @@ class JsonSchema {
|
||||
return array(
|
||||
array(
|
||||
'property'=>$path,
|
||||
'message'=>gettype($value)." value found, but a ".$type." is required "
|
||||
'message'=>gettype($value)." value found, but a ".$type." is required"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -18,6 +18,20 @@ class AdditionalPropertiesTest extends BaseTestCase
|
||||
"additionalProperties": false
|
||||
}'
|
||||
),
|
||||
array(
|
||||
'{
|
||||
"prop":"1",
|
||||
"additionalProp":"2"
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"prop":{"type":"string"}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}',
|
||||
JsonSchema::CHECK_MODE_TYPE_CAST
|
||||
),
|
||||
array(
|
||||
'{
|
||||
"prop":"1",
|
||||
@ -30,6 +44,20 @@ class AdditionalPropertiesTest extends BaseTestCase
|
||||
},
|
||||
"additionalProperties": {"type":"string"}
|
||||
}'
|
||||
),
|
||||
array(
|
||||
'{
|
||||
"prop":"1",
|
||||
"additionalProp":2
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"prop":{"type":"string"}
|
||||
},
|
||||
"additionalProperties": {"type":"string"}
|
||||
}',
|
||||
JsonSchema::CHECK_MODE_TYPE_CAST
|
||||
)
|
||||
);
|
||||
}
|
||||
@ -49,6 +77,19 @@ class AdditionalPropertiesTest extends BaseTestCase
|
||||
}
|
||||
}'
|
||||
),
|
||||
array(
|
||||
'{
|
||||
"prop":"1",
|
||||
"additionalProp":"2"
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"prop":{"type":"string"}
|
||||
}
|
||||
}',
|
||||
JsonSchema::CHECK_MODE_TYPE_CAST
|
||||
),
|
||||
array(
|
||||
'{
|
||||
"prop":"1",
|
||||
|
@ -5,11 +5,17 @@ abstract class BaseTestCase extends PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* @dataProvider getInvalidTests
|
||||
*/
|
||||
public function testInvalidCases($input, $schema, $errors = array())
|
||||
public function testInvalidCases($input, $schema, $checkMode = null, $errors = array())
|
||||
{
|
||||
if (null === $checkMode) {
|
||||
$checkMode = JsonSchema::CHECK_MODE_NORMAL;
|
||||
}
|
||||
|
||||
JsonSchema::$checkMode = $checkMode;
|
||||
|
||||
$result = JsonSchema::validate(json_decode($input), json_decode($schema));
|
||||
if (array() !== $errors) {
|
||||
$this->assertEquals($errors, $result->errors);
|
||||
$this->assertEquals($errors, $result->errors, var_export($result, true));
|
||||
}
|
||||
$this->assertFalse($result->valid, var_export($result, true));
|
||||
}
|
||||
@ -22,7 +28,9 @@ abstract class BaseTestCase extends PHPUnit_Framework_TestCase
|
||||
if (null === $checkMode) {
|
||||
$checkMode = JsonSchema::CHECK_MODE_NORMAL;
|
||||
}
|
||||
|
||||
JsonSchema::$checkMode = $checkMode;
|
||||
|
||||
$result = JsonSchema::validate(json_decode($input), json_decode($schema));
|
||||
$this->assertTrue($result->valid, var_export($result, true));
|
||||
}
|
||||
|
@ -14,18 +14,14 @@ class PhpTypeCastModeTest extends BaseTestCase
|
||||
"properties":{
|
||||
"a":{"type":"number"}
|
||||
}
|
||||
}'
|
||||
),
|
||||
array(
|
||||
'{
|
||||
"a":"9"
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"a":{"type":"number"}
|
||||
}
|
||||
}'
|
||||
null,
|
||||
array(
|
||||
array(
|
||||
'property' => 'a',
|
||||
'message' => 'string value found, but a number is required'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
'{
|
||||
@ -55,7 +51,19 @@ class PhpTypeCastModeTest extends BaseTestCase
|
||||
}
|
||||
}',
|
||||
JsonSchema::CHECK_MODE_TYPE_CAST
|
||||
)
|
||||
),
|
||||
array(
|
||||
'{
|
||||
"a":"9"
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"a":{"type":"number"}
|
||||
}
|
||||
}',
|
||||
JsonSchema::CHECK_MODE_TYPE_CAST
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user