reorganize tests

This commit is contained in:
Igor Wiedler 2011-09-30 19:09:42 +02:00
parent 8fccda0bee
commit cb88336e56
22 changed files with 101 additions and 57 deletions

View File

@ -1,5 +1,7 @@
<?php
namespace JsonSchema\Tests;
class AdditionalPropertiesTest extends BaseTestCase
{
public function getInvalidTests()
@ -68,7 +70,7 @@ class AdditionalPropertiesTest extends BaseTestCase
)
);
}
public function getValidTests()
{
return array(

View File

@ -1,5 +1,7 @@
<?php
namespace JsonSchema\Tests;
class ArraysTest extends BaseTestCase
{
public function getInvalidTests()
@ -35,7 +37,7 @@ class ArraysTest extends BaseTestCase
)
);
}
public function getValidTests()
{
return array(

View File

@ -1,6 +1,8 @@
<?php
abstract class BaseTestCase extends PHPUnit_Framework_TestCase
namespace JsonSchema\Tests;
abstract class BaseTestCase extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider getInvalidTests
@ -10,32 +12,32 @@ 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));
if (array() !== $errors) {
$this->assertEquals($errors, $result->errors, var_export($result, true));
}
$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();
}

View File

@ -1,12 +1,14 @@
<?php
namespace JsonSchema\Tests;
class BasicTypesTest extends BaseTestCase
{
public function getInvalidTests()
{
return array(
array(
'{
'{
"string":null,
"number":null,
"integer":null,
@ -15,7 +17,7 @@ class BasicTypesTest extends BaseTestCase
"array":null,
"null":1
}',
'{
'{
"type":"object",
"properties":{
"string":{"type":"string"},
@ -31,12 +33,12 @@ class BasicTypesTest extends BaseTestCase
)
);
}
public function getValidTests()
{
return array(
array(
'{
'{
"string":"string test",
"number":1,
"integer":1,
@ -52,7 +54,7 @@ class BasicTypesTest extends BaseTestCase
"any5": [],
"any6": null
}',
'{
'{
"type":"object",
"properties":{
"string":{"type":"string"},

View File

@ -1,5 +1,7 @@
<?php
namespace JsonSchema\Tests;
class DisallowTest extends BaseTestCase
{
public function getInvalidTests()
@ -35,7 +37,7 @@ class DisallowTest extends BaseTestCase
)
);
}
public function getValidTests()
{
return array(

View File

@ -1,5 +1,7 @@
<?php
namespace JsonSchema\Tests;
class EnumTest extends BaseTestCase
{
public function getInvalidTests()
@ -19,7 +21,7 @@ class EnumTest extends BaseTestCase
)
);
}
public function getValidTests()
{
return array(

View File

@ -1,5 +1,7 @@
<?php
namespace JsonSchema\Tests;
class ExtendsTest extends BaseTestCase
{
public function getInvalidTests()
@ -15,18 +17,18 @@ class ExtendsTest extends BaseTestCase
"type": "object",
"properties": {
"name": {
"type": "string"
"type": "string"
},
"age" : {
"type": "integer",
"maximum":120
}
}
},
"extends": {
"id": "oldPerson",
"type": "object",
"properties": {
"age" : {"minimum":70}
"age" : {"minimum":70}
}
}
}'
@ -41,25 +43,25 @@ class ExtendsTest extends BaseTestCase
"type": "object",
"properties": {
"name": {
"type": "string"
"type": "string"
},
"age" : {
"type": "integer",
"maximum":120
}
}
},
"extends": {
"id": "oldPerson",
"type": "object",
"properties": {
"age" : {"minimum":70}
"age" : {"minimum":70}
}
}
}'
)
);
}
public function getValidTests()
{
return array(
@ -73,18 +75,18 @@ class ExtendsTest extends BaseTestCase
"type": "object",
"properties": {
"name": {
"type": "string"
"type": "string"
},
"age" : {
"type": "integer",
"maximum":120
}
}
},
"extends": {
"id": "oldPerson",
"type": "object",
"properties": {
"age" : {"minimum":70}
"age" : {"minimum":70}
}
}
}'

View File

@ -1,5 +1,7 @@
<?php
namespace JsonSchema\Tests;
class MaxDecimalTest extends BaseTestCase
{
public function getInvalidTests()
@ -18,7 +20,7 @@ class MaxDecimalTest extends BaseTestCase
)
);
}
public function getValidTests()
{
return array(

View File

@ -1,5 +1,7 @@
<?php
namespace JsonSchema\Tests;
class MinItemsMaxItemsTest extends BaseTestCase
{
public function getInvalidTests()
@ -29,7 +31,7 @@ class MinItemsMaxItemsTest extends BaseTestCase
)
);
}
public function getValidTests()
{
return array(
@ -46,7 +48,7 @@ class MinItemsMaxItemsTest extends BaseTestCase
),
array(
'{
"value":[2,2,5,8]
"value":[2,2,5,8]
}',
'{
"type":"object",

View File

@ -1,5 +1,7 @@
<?php
namespace JsonSchema\Tests;
class MinLengthMaxLengthTest extends BaseTestCase
{
public function getInvalidTests()
@ -7,7 +9,7 @@ class MinLengthMaxLengthTest extends BaseTestCase
return array(
array(
'{
"value":"w"
"value":"w"
}',
'{
"type":"object",
@ -29,7 +31,7 @@ class MinLengthMaxLengthTest extends BaseTestCase
)
);
}
public function getValidTests()
{
return array(
@ -55,7 +57,7 @@ class MinLengthMaxLengthTest extends BaseTestCase
}
}'
),
);
}
}

View File

@ -1,5 +1,7 @@
<?php
namespace JsonSchema\Tests;
class MinimumMaximumTest extends BaseTestCase
{
public function getInvalidTests()
@ -29,7 +31,7 @@ class MinimumMaximumTest extends BaseTestCase
)
);
}
public function getValidTests()
{
return array(

View File

@ -1,5 +1,7 @@
<?php
namespace JsonSchema\Tests;
class NumberAndIntegerTypesTest extends BaseTestCase
{
public function getInvalidTests()
@ -18,7 +20,7 @@ class NumberAndIntegerTypesTest extends BaseTestCase
)
);
}
public function getValidTests()
{
return array(

View File

@ -1,5 +1,7 @@
<?php
namespace JsonSchema\Tests;
class OptionalPropertyTest extends BaseTestCase
{
public function getInvalidTests()
@ -16,7 +18,7 @@ class OptionalPropertyTest extends BaseTestCase
)
);
}
public function getValidTests()
{
return array(

View File

@ -1,5 +1,7 @@
<?php
namespace JsonSchema\Tests;
class PatternTest extends BaseTestCase
{
public function getInvalidTests()
@ -19,7 +21,7 @@ class PatternTest extends BaseTestCase
)
);
}
public function getValidTests()
{
return array(

View File

@ -1,5 +1,7 @@
<?php
namespace JsonSchema\Tests;
class RequireTest extends BaseTestCase
{
public function getInvalidTests()
@ -19,7 +21,7 @@ class RequireTest extends BaseTestCase
)
);
}
public function getValidTests()
{
return array(

View File

@ -1,5 +1,7 @@
<?php
namespace JsonSchema\Tests;
class SelfDefinedSchemaTest extends BaseTestCase
{
public function getInvalidTests()
@ -10,14 +12,14 @@ class SelfDefinedSchemaTest extends BaseTestCase
"$schema": {
"properties": {
"name": {
"type": "string"
"type": "string"
},
"age" : {
"type": "integer",
"maximum": 25,
"optional": true
}
}
"optional": true
}
}
},
"name" : "John Doe",
"age" : 30,
@ -27,7 +29,7 @@ class SelfDefinedSchemaTest extends BaseTestCase
)
);
}
public function getValidTests()
{
return array(
@ -36,14 +38,14 @@ class SelfDefinedSchemaTest extends BaseTestCase
"$schema": {
"properties": {
"name": {
"type": "string"
"type": "string"
},
"age" : {
"type": "integer",
"maximum": 125,
"optional": true
}
}
"optional": true
}
}
},
"name" : "John Doe",
"age" : 30,

View File

@ -1,5 +1,7 @@
<?php
namespace JsonSchema\Tests;
class TupleTypingTest extends BaseTestCase
{
public function getInvalidTests()
@ -17,7 +19,7 @@ class TupleTypingTest extends BaseTestCase
"items":[
{"type":"string"},
{"type":"number"}
]
]
}
}
}'
@ -70,14 +72,14 @@ class TupleTypingTest extends BaseTestCase
"items":[
{"type":"string"},
{"type":"number"}
]
]
}
}
}'
)
);
}
public function getValidTests()
{
return array(
@ -94,7 +96,7 @@ class TupleTypingTest extends BaseTestCase
{"type":"string"},
{"type":"number","optional":true},
{"type":"number","optional":true}
]
]
}
}
}'

View File

@ -1,5 +1,7 @@
<?php
namespace JsonSchema\Tests;
class UnionTypesTest extends BaseTestCase
{
public function getInvalidTests()
@ -20,7 +22,7 @@ class UnionTypesTest extends BaseTestCase
)
);
}
public function getValidTests()
{
return array(

View File

@ -1,5 +1,7 @@
<?php
namespace JsonSchema\Tests;
class UnionWithNullValueTest extends BaseTestCase
{
public function getInvalidTests()
@ -20,7 +22,7 @@ class UnionWithNullValueTest extends BaseTestCase
)
);
}
public function getValidTests()
{
return array(

View File

@ -1,5 +1,7 @@
<?php
namespace JsonSchema\Tests;
class WrongMessagesFailingTestCaseTest extends BaseTestCase
{
public function getInvalidTests()
@ -20,7 +22,7 @@ class WrongMessagesFailingTestCaseTest extends BaseTestCase
)
);
}
public function getValidTests()
{
return array(

View File

@ -1,4 +1,8 @@
<?php
require dirname(__FILE__) . '/../bootstrap.php';
require 'BaseTestCase.php';
require_once __DIR__.'/../vendor/symfony/Component/ClassLoader/UniversalClassLoader.php';
$loader = new Symfony\Component\ClassLoader\UniversalClassLoader();
$loader->registerNamespace('JsonSchema', __DIR__.'/../src');
$loader->registerNamespace('JsonSchema\Tests', __DIR__);
$loader->register();