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
This commit is contained in:
Mirosław Filip 2016-05-09 22:38:52 +02:00
parent a2be633611
commit 346b3218dd
44 changed files with 36 additions and 11 deletions

View File

@ -28,11 +28,11 @@
"type": "package",
"package": {
"name": "json-schema/JSON-Schema-Test-Suite",
"version": "1.1.2",
"version": "1.2.0",
"source": {
"url": "https://github.com/json-schema/JSON-Schema-Test-Suite",
"type": "git",
"reference": "1.1.2"
"reference": "1.2.0"
}
}
}],
@ -40,7 +40,7 @@
"php": ">=5.3.3"
},
"require-dev": {
"json-schema/JSON-Schema-Test-Suite": "1.1.2",
"json-schema/JSON-Schema-Test-Suite": "1.2.0",
"phpunit/phpunit": "^4.8.22",
"phpdocumentor/phpdocumentor": "~2"
},
@ -48,7 +48,7 @@
"psr-4": { "JsonSchema\\": "src/JsonSchema/" }
},
"autoload-dev": {
"psr-4": { "JsonSchema\\Tests\\": "tests/JsonSchema/Tests/" }
"psr-4": { "JsonSchema\\Tests\\": "tests/" }
},
"bin": ["bin/validate-json"],
"extra": {

View File

@ -79,7 +79,7 @@ abstract class BaseTestCase extends \PHPUnit_Framework_TestCase
*/
private function resolveSchema($schema)
{
$relativeTestsRoot = realpath(__DIR__ . '/../../../../vendor/json-schema/JSON-Schema-Test-Suite/remotes');
$relativeTestsRoot = realpath(__DIR__ . '/../../vendor/json-schema/JSON-Schema-Test-Suite/remotes');
$jsonSchemaDraft03 = $this->getJsonSchemaDraft03();
$jsonSchemaDraft04 = $this->getJsonSchemaDraft04();

View File

@ -10,7 +10,7 @@ use JsonSchema\Tests\Constraints\BaseTestCase;
abstract class BaseDraftTestCase extends BaseTestCase
{
/** @var string */
protected $relativeTestsRoot = '/../../../../vendor/json-schema/JSON-Schema-Test-Suite/tests';
protected $relativeTestsRoot = '/../../vendor/json-schema/JSON-Schema-Test-Suite/tests';
private function setUpTests($isValid)
{
@ -20,13 +20,18 @@ abstract class BaseDraftTestCase extends BaseTestCase
foreach ($filePaths as $path) {
foreach (glob($path . '/*.json') as $file) {
if (!in_array(basename($file), $skippedTests)) {
$filename = basename($file);
if (!in_array($filename, $skippedTests)) {
$suites = json_decode(file_get_contents($file));
foreach ($suites as $suite) {
$suiteDescription = $suite->description;
foreach ($suite->tests as $test) {
$testCaseDescription = $test->description;
if ($isValid === $test->valid) {
$tests[] = array(json_encode($test->data), json_encode($suite->schema));
}
$tests[
$this->createDataSetPath($filename, $suiteDescription, $testCaseDescription)
] = array(json_encode($test->data), json_encode($suite->schema));
}
}
}
}
@ -61,4 +66,19 @@ abstract class BaseDraftTestCase extends BaseTestCase
* @return string[]
*/
protected abstract function getSkippedTests();
/**
* Generates a readable path to Json Schema Test Suite data set under test
*
* @param string $filename
* @param string $suiteDesc
* @param string $testCaseDesc
*
* @return string
*/
private function createDataSetPath($filename, $suiteDesc, $testCaseDesc)
{
$separator = ' / ';
return $filename . $separator . $suiteDesc . $separator . $testCaseDesc;
}
}

View File

@ -31,7 +31,9 @@ class Draft3Test extends BaseDraftTestCase
protected function getSkippedTests()
{
return array(
// Optional
'bignum.json',
'format.json',
'jsregex.json',
'zeroTerminatedFloats.json'
);

View File

@ -33,7 +33,10 @@ class Draft4Test extends BaseDraftTestCase
return array(
// Optional
'bignum.json',
'zeroTerminatedFloats.json'
'format.json',
'zeroTerminatedFloats.json',
// Required
'not.json' // only one test case failing
);
}
}

View File

@ -21,7 +21,7 @@ class FileGetContentsTest extends \PHPUnit_Framework_TestCase
public function testFetchFile()
{
$res = new FileGetContents();
$result = $res->retrieve(__DIR__.'/../Fixture/child.json');
$result = $res->retrieve(__DIR__ . '/../Fixture/child.json');
$this->assertNotEmpty($result);
}
}