mirror of
https://github.com/justinrainbow/json-schema.git
synced 2025-03-18 05:09:41 +01:00
Initial conversion of selenium tests to PHPUnit
This commit is contained in:
parent
4436675413
commit
1c0a28dbbc
5
bootstrap.php
Normal file
5
bootstrap.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
require 'JsonSchema.php';
|
||||
require 'JsonSchemaUndefined.php';
|
||||
require 'tests/BaseTestCase.php';
|
20
phpunit.xml.dist
Normal file
20
phpunit.xml.dist
Normal file
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<phpunit backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
syntaxCheck="false"
|
||||
bootstrap="bootstrap.php"
|
||||
verbose="true"
|
||||
>
|
||||
<testsuites>
|
||||
<testsuite name="JSON Schema Test Suite">
|
||||
<directory suffix="Test.php">tests</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
</phpunit>
|
67
tests/AdditionalPropertiesTest.php
Normal file
67
tests/AdditionalPropertiesTest.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
class AdditionalPropertiesTest extends BaseTestCase
|
||||
{
|
||||
public function getInvalidTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'{
|
||||
"prop":"1",
|
||||
"additionalProp":"2"
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"prop":{"type":"string"}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}'
|
||||
),
|
||||
array(
|
||||
'{
|
||||
"prop":"1",
|
||||
"additionalProp":2
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"prop":{"type":"string"}
|
||||
},
|
||||
"additionalProperties": {"type":"string"}
|
||||
}'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getValidTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'{
|
||||
"prop":"1",
|
||||
"additionalProp":"2"
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"prop":{"type":"string"}
|
||||
}
|
||||
}'
|
||||
),
|
||||
array(
|
||||
'{
|
||||
"prop":"1",
|
||||
"additionalProp":"2"
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"prop":{"type":"string"}
|
||||
},
|
||||
"additionalProperties": {"type":"string"}
|
||||
}'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
55
tests/ArraysTest.php
Normal file
55
tests/ArraysTest.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
class ArraysTest extends BaseTestCase
|
||||
{
|
||||
public function getInvalidTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'{
|
||||
"array":[1,2,"a"]
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"array":{
|
||||
"type":"array",
|
||||
"items":{"type":"number"}
|
||||
}
|
||||
}
|
||||
}'
|
||||
),
|
||||
array(
|
||||
'{
|
||||
"array":[1,2,null]
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"array":{
|
||||
"type":"array",
|
||||
"items":{"type":["number","boolean"]}
|
||||
}
|
||||
}
|
||||
}'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getValidTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'{
|
||||
"array":[1,2,"a"]
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"array":{"type":"array"}
|
||||
}
|
||||
}'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
33
tests/BaseTestCase.php
Normal file
33
tests/BaseTestCase.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
abstract class BaseTestCase extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider getInvalidTests
|
||||
*/
|
||||
public function testInvalidCases($input, $schema, $errors = array())
|
||||
{
|
||||
$result = JsonSchema::validate(json_decode($input), json_decode($schema));
|
||||
if (array() !== $errors) {
|
||||
$this->assertEquals($errors, $result->errors);
|
||||
}
|
||||
$this->assertFalse($result->valid, var_export($result, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getValidTests
|
||||
*/
|
||||
public function testValidCases($input, $schema, $checkMode = null)
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
abstract public function getValidTests();
|
||||
|
||||
abstract public function getInvalidTests();
|
||||
}
|
78
tests/BasicTypesTest.php
Normal file
78
tests/BasicTypesTest.php
Normal file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
class BasicTypesTest extends BaseTestCase
|
||||
{
|
||||
public function getInvalidTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'{
|
||||
"string":null,
|
||||
"number":null,
|
||||
"integer":null,
|
||||
"boolean":null,
|
||||
"object":null,
|
||||
"array":null,
|
||||
"null":1
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"string":{"type":"string"},
|
||||
"number":{"type":"number"},
|
||||
"integer":{"type":"integer"},
|
||||
"boolean":{"type":"boolean"},
|
||||
"object":{"type":"object"},
|
||||
"array":{"type":"array"},
|
||||
"null":{"type":"null"}
|
||||
},
|
||||
"additionalProperties":false
|
||||
}'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getValidTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'{
|
||||
"string":"string test",
|
||||
"number":1,
|
||||
"integer":1,
|
||||
"boolean":true,
|
||||
"object":{},
|
||||
"array":[],
|
||||
"null":null,
|
||||
"any": "string",
|
||||
"any1": 2.6,
|
||||
"any2": 4,
|
||||
"any3": false,
|
||||
"any4": {},
|
||||
"any5": [],
|
||||
"any6": null
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"string":{"type":"string"},
|
||||
"number":{"type":"number"},
|
||||
"integer":{"type":"integer"},
|
||||
"boolean":{"type":"boolean"},
|
||||
"object":{"type":"object"},
|
||||
"array":{"type":"array"},
|
||||
"null":{"type":"null"},
|
||||
"any": {"type":"any"},
|
||||
"any1": {"type":"any"},
|
||||
"any2": {"type":"any"},
|
||||
"any3": {"type":"any"},
|
||||
"any4": {"type":"any"},
|
||||
"any5": {"type":"any"},
|
||||
"any6": {"type":"any"}
|
||||
},
|
||||
"additionalProperties":false
|
||||
}'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
72
tests/DisallowTest.php
Normal file
72
tests/DisallowTest.php
Normal file
@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
class DisallowTest extends BaseTestCase
|
||||
{
|
||||
public function getInvalidTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'{
|
||||
"value":" The xpto is weird"
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"value":{
|
||||
"type":"any",
|
||||
"disallow":{"type":"string","pattern":"xpto"}
|
||||
}
|
||||
}
|
||||
}'
|
||||
),
|
||||
array(
|
||||
'{
|
||||
"value":null
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"value":{
|
||||
"type":"any",
|
||||
"disallow":{"type":"null"}
|
||||
}
|
||||
}
|
||||
}'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getValidTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'{
|
||||
"value":" The xpto is weird"
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"value":{
|
||||
"type":"any",
|
||||
"disallow":{"type":"string","pattern":"^xpto"}
|
||||
}
|
||||
}
|
||||
}'
|
||||
),
|
||||
array(
|
||||
'{
|
||||
"value":1
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"value":{
|
||||
"type":"any",
|
||||
"disallow":{"type":"null"}
|
||||
}
|
||||
}
|
||||
}'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
40
tests/EnumTest.php
Normal file
40
tests/EnumTest.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
class EnumTest extends BaseTestCase
|
||||
{
|
||||
public function getInvalidTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'{
|
||||
"value":"Morango"
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"value":{"type":"string","enum":["Abacate","Manga","Pitanga"]}
|
||||
},
|
||||
"additionalProperties":false
|
||||
}'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getValidTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'{
|
||||
"value":"Abacate"
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"value":{"type":"string","enum":["Abacate","Manga","Pitanga"]}
|
||||
},
|
||||
"additionalProperties":false
|
||||
}'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
94
tests/ExtendsTest.php
Normal file
94
tests/ExtendsTest.php
Normal file
@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
class ExtendsTest extends BaseTestCase
|
||||
{
|
||||
public function getInvalidTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'{
|
||||
"name":"bruno",
|
||||
"age":50
|
||||
}',
|
||||
'{
|
||||
"id": "person",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"age" : {
|
||||
"type": "integer",
|
||||
"maximum":120
|
||||
}
|
||||
},
|
||||
"extends": {
|
||||
"id": "oldPerson",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"age" : {"minimum":70}
|
||||
}
|
||||
}
|
||||
}'
|
||||
),
|
||||
array(
|
||||
'{
|
||||
"name":"bruno",
|
||||
"age":180
|
||||
}',
|
||||
'{
|
||||
"id": "person",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"age" : {
|
||||
"type": "integer",
|
||||
"maximum":120
|
||||
}
|
||||
},
|
||||
"extends": {
|
||||
"id": "oldPerson",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"age" : {"minimum":70}
|
||||
}
|
||||
}
|
||||
}'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getValidTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'{
|
||||
"name":"bruno",
|
||||
"age":80
|
||||
}',
|
||||
'{
|
||||
"id": "person",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"age" : {
|
||||
"type": "integer",
|
||||
"maximum":120
|
||||
}
|
||||
},
|
||||
"extends": {
|
||||
"id": "oldPerson",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"age" : {"minimum":70}
|
||||
}
|
||||
}
|
||||
}'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
38
tests/MaxDecimalTest.php
Normal file
38
tests/MaxDecimalTest.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
class MaxDecimalTest extends BaseTestCase
|
||||
{
|
||||
public function getInvalidTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'{
|
||||
"value":5.6333
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"value":{"type":"number","maxDecimal":3}
|
||||
}
|
||||
}'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getValidTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'{
|
||||
"value":5.633
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"value":{"type":"number","maxDecimal":3}
|
||||
}
|
||||
}'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
60
tests/MinItemsMaxItemsTest.php
Normal file
60
tests/MinItemsMaxItemsTest.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
class MinItemsMaxItemsTest extends BaseTestCase
|
||||
{
|
||||
public function getInvalidTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'{
|
||||
"value":[2]
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"value":{"type":"array","minItems":2,"maxItems":4}
|
||||
}
|
||||
}'
|
||||
),
|
||||
array(
|
||||
'{
|
||||
"value":2,2,5,8,5]
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"value":{"type":"array","minItems":2,"maxItems":4}
|
||||
}
|
||||
}'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getValidTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'{
|
||||
"value":[2,2]
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"value":{"type":"array","minItems":2,"maxItems":4}
|
||||
}
|
||||
}'
|
||||
),
|
||||
array(
|
||||
'{
|
||||
"value":[2,2,5,8]
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"value":{"type":"array","minItems":2,"maxItems":4}
|
||||
}
|
||||
}'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
61
tests/MinLengthMaxLengthTest.php
Normal file
61
tests/MinLengthMaxLengthTest.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
class MinLengthMaxLengthTest extends BaseTestCase
|
||||
{
|
||||
public function getInvalidTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'{
|
||||
"value":"w"
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"value":{"type":"string","minLength":2,"maxLength":4}
|
||||
}
|
||||
}'
|
||||
),
|
||||
array(
|
||||
'{
|
||||
"value":"wo7us"
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"value":{"type":"string","minLength":2,"maxLength":4}
|
||||
}
|
||||
}'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getValidTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'{
|
||||
"value":"wo"
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"value":{"type":"string","minLength":2,"maxLength":4}
|
||||
}
|
||||
}'
|
||||
),
|
||||
array(
|
||||
'{
|
||||
"value":"wo7u"
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"value":{"type":"string","minLength":2,"maxLength":4}
|
||||
}
|
||||
}'
|
||||
),
|
||||
|
||||
);
|
||||
}
|
||||
}
|
60
tests/MinimumMaximumTest.php
Normal file
60
tests/MinimumMaximumTest.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
class MinimumMaximumTest extends BaseTestCase
|
||||
{
|
||||
public function getInvalidTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'{
|
||||
"value":2
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"value":{"type":"integer","minimum":4}
|
||||
}
|
||||
}'
|
||||
),
|
||||
array(
|
||||
'{
|
||||
"value":16
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"value":{"type":"integer","maximum":8}
|
||||
}
|
||||
}'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getValidTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'{
|
||||
"value":6
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"value":{"type":"integer","minimum":4}
|
||||
}
|
||||
}'
|
||||
),
|
||||
array(
|
||||
'{
|
||||
"value":6
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"value":{"type":"integer","maximum":8}
|
||||
}
|
||||
}'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
49
tests/NumberAndIntegerTypesTest.php
Normal file
49
tests/NumberAndIntegerTypesTest.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
class NumberAndIntegerTypesTest extends BaseTestCase
|
||||
{
|
||||
public function getInvalidTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'{
|
||||
"number": 1.4
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"number":{"type":"integer"}
|
||||
}
|
||||
}'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getValidTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'{
|
||||
"number": 1
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"number":{"type":"number"}
|
||||
}
|
||||
}'
|
||||
),
|
||||
array(
|
||||
'{
|
||||
"number": 1.4
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"number":{"type":"number"}
|
||||
}
|
||||
}'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
36
tests/OptionalPropertyTest.php
Normal file
36
tests/OptionalPropertyTest.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
class OptionalPropertyTest extends BaseTestCase
|
||||
{
|
||||
public function getInvalidTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'{}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"number":{"type":"string","optional":false}
|
||||
}
|
||||
}'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getValidTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'{
|
||||
"number": "1.4"
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"number":{"type":"string","optional":false}
|
||||
}
|
||||
}'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
52
tests/PatternTest.php
Normal file
52
tests/PatternTest.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
class PatternTest extends BaseTestCase
|
||||
{
|
||||
public function getInvalidTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'{
|
||||
"value":"Abacates"
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"value":{"type":"string","pattern":"^cat"}
|
||||
},
|
||||
"additionalProperties":false
|
||||
}'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getValidTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'{
|
||||
"value":"Abacates"
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"value":{"type":"string","pattern":"tes$"}
|
||||
},
|
||||
"additionalProperties":false
|
||||
}'
|
||||
),
|
||||
array(
|
||||
'{
|
||||
"value":"Abacates"
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"value":{"type":"string","pattern":"cat"}
|
||||
},
|
||||
"additionalProperties":false
|
||||
}'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
61
tests/PhpTypeCastModeTest.php
Normal file
61
tests/PhpTypeCastModeTest.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
class PhpTypeCastModeTest extends BaseTestCase
|
||||
{
|
||||
public function getInvalidTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'{
|
||||
"a":"c"
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"a":{"type":"number"}
|
||||
}
|
||||
}'
|
||||
),
|
||||
array(
|
||||
'{
|
||||
"a":"9"
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"a":{"type":"number"}
|
||||
}
|
||||
}'
|
||||
),
|
||||
array(
|
||||
'{
|
||||
"a":"9"
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"a":{"type":"integer","maximum":8}
|
||||
}
|
||||
}'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getValidTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'{
|
||||
"a":"9"
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"a":{"type":"integer","maximum":8.0}
|
||||
}
|
||||
}',
|
||||
JsonSchema::CHECK_MODE_TYPE_CAST
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
41
tests/RequireTest.php
Normal file
41
tests/RequireTest.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
class RequireTest extends BaseTestCase
|
||||
{
|
||||
public function getInvalidTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'{
|
||||
"state":"DF"
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"state":{"type":"string","optional":true,"requires":"city"},
|
||||
"city":{"type":"string","optional":true}
|
||||
}
|
||||
}'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getValidTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'{
|
||||
"state":"DF",
|
||||
"city":"Brasília"
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"state":{"type":"string","optional":true,"requires":"city"},
|
||||
"city":{"type":"string","optional":true}
|
||||
}
|
||||
}'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
56
tests/SelfDefinedSchemaTest.php
Normal file
56
tests/SelfDefinedSchemaTest.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
class SelfDefinedSchemaTest extends BaseTestCase
|
||||
{
|
||||
public function getInvalidTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'{
|
||||
"$schema": {
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"age" : {
|
||||
"type": "integer",
|
||||
"maximum": 25,
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"name" : "John Doe",
|
||||
"age" : 30,
|
||||
"type" : "object"
|
||||
}',
|
||||
''
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getValidTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'{
|
||||
"$schema": {
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"age" : {
|
||||
"type": "integer",
|
||||
"maximum": 125,
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"name" : "John Doe",
|
||||
"age" : 30,
|
||||
"type" : "object"
|
||||
}',
|
||||
''
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
104
tests/TupleTypingTest.php
Normal file
104
tests/TupleTypingTest.php
Normal file
@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
class TupleTypingTest extends BaseTestCase
|
||||
{
|
||||
public function getInvalidTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'{
|
||||
"tupleTyping":[2,"a"]
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"tupleTyping":{
|
||||
"type":"array",
|
||||
"items":[
|
||||
{"type":"string"},
|
||||
{"type":"number"}
|
||||
]
|
||||
}
|
||||
}
|
||||
}'
|
||||
),
|
||||
array(
|
||||
'{
|
||||
"tupleTyping":["2",2,3]
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"tupleTyping":{
|
||||
"type":"array",
|
||||
"items":[
|
||||
{"type":"string"},
|
||||
{"type":"number"}
|
||||
] ,
|
||||
"additionalProperties":false
|
||||
}
|
||||
}
|
||||
}'
|
||||
),
|
||||
array(
|
||||
'{
|
||||
"tupleTyping":["2",2,3]
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"tupleTyping":{
|
||||
"type":"array",
|
||||
"items":[
|
||||
{"type":"string"},
|
||||
{"type":"number"}
|
||||
] ,
|
||||
"additionalProperties":{"type":"string"}
|
||||
}
|
||||
}
|
||||
}'
|
||||
),
|
||||
array(
|
||||
'{
|
||||
"tupleTyping":["2"]
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"tupleTyping":{
|
||||
"type":"array",
|
||||
"items":[
|
||||
{"type":"string"},
|
||||
{"type":"number"}
|
||||
]
|
||||
}
|
||||
}
|
||||
}'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getValidTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'{
|
||||
"tupleTyping":["2"]
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"tupleTyping":{
|
||||
"type":"array",
|
||||
"items":[
|
||||
{"type":"string"},
|
||||
{"type":"number","optional":true},
|
||||
{"type":"number","optional":true}
|
||||
]
|
||||
}
|
||||
}
|
||||
}'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
42
tests/UnionTypesTest.php
Normal file
42
tests/UnionTypesTest.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
class UnionTypesTest extends BaseTestCase
|
||||
{
|
||||
public function getInvalidTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'{
|
||||
"stringOrNumber":4.8,
|
||||
"booleanOrNull":5
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"stringOrNumber":{"type":["string","number"]},
|
||||
"booleanOrNull":{"type":["boolean","null"]}
|
||||
}
|
||||
}'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getValidTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'{
|
||||
"stringOrNumber":4.8,
|
||||
"booleanOrNull":false
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"stringOrNumber":{"type":["string","number"]},
|
||||
"booleanOrNull":{"type":["boolean","null"]}
|
||||
}
|
||||
}'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
42
tests/UnionWithNullValueTest.php
Normal file
42
tests/UnionWithNullValueTest.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
class UnionWithNullValueTest extends BaseTestCase
|
||||
{
|
||||
public function getInvalidTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'{
|
||||
"stringOrNumber":null,
|
||||
"booleanOrNull":null
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"stringOrNumber":{"type":["string","number"]},
|
||||
"booleanOrNull":{"type":["boolean","null"]}
|
||||
}
|
||||
}'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getValidTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'{
|
||||
"stringOrNumber":12,
|
||||
"booleanOrNull":null
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"stringOrNumber":{"type":["string","number"]},
|
||||
"booleanOrNull":{"type":["boolean","null"]}
|
||||
}
|
||||
}'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
42
tests/WrongMessagesFailingTestCaseTest.php
Normal file
42
tests/WrongMessagesFailingTestCaseTest.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
class WrongMessagesFailingTestCaseTest extends BaseTestCase
|
||||
{
|
||||
public function getInvalidTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'{
|
||||
"stringOrNumber":4.8,
|
||||
"booleanOrNull":["A","B"]
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"stringOrNumber":{"type":["string","number"]},
|
||||
"booleanOrNull":{"type":["boolean","null"]}
|
||||
}
|
||||
}'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getValidTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'{
|
||||
"stringOrNumber":4.8,
|
||||
"booleanOrNull":true
|
||||
}',
|
||||
'{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"stringOrNumber":{"type":["string","number"]},
|
||||
"booleanOrNull":{"type":["boolean","null"]}
|
||||
}
|
||||
}'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user