Skip to content

Commit

Permalink
Merge pull request #19 from shouze/upgrade-json-schema-dependency
Browse files Browse the repository at this point in the history
Upgrade justinrainbow/json-schema >=3.0.0 <6.0.0
  • Loading branch information
shouze authored Aug 29, 2017
2 parents 67639f9 + 3221937 commit 6ede6f8
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 17 deletions.
22 changes: 19 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
language: php
dist: trusty

php:
- 5.5
- 5.6
- 7.0
- 7.1
- nightly

env:
matrix:
- COMPOSER_PREFER="--prefer-stable"
- COMPOSER_PREFER="--prefer-lowest"

matrix:
allow_failures:
- php: nightly
fast_finish: true

before_script:
- echo 'always_populate_raw_post_data = -1' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
- phpenv config-rm xdebug.ini
- composer install --prefer-dist --optimize-autoloader
- |
if [ ! $(php -m | grep -ci xdebug) -eq 0 ] ; then
phpenv config-rm xdebug.ini
fi
- composer global require hirak/prestissimo
- composer update $COMPOSER_PREFER
- php -S 127.0.0.1:4224 -t "$TRAVIS_BUILD_DIR/testapp" &> /dev/null &

script:
Expand Down
12 changes: 9 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,22 @@
"symfony/http-foundation": "^2.8|^3.0",
"symfony/debug": "^2.8|^3.0",
"jakeasmith/http_build_url": "^1.0",
"justinrainbow/json-schema": "^2.0"
"justinrainbow/json-schema": ">=3.0 <6.0"
},
"config": {
"optimize-autoloader": true,
"preferred-install": {
"*": "dist"
}
},
"require-dev": {
"atoum/atoum": "^2.6",
"atoum/atoum": "^3.1",
"fzaninotto/faker": "^1.5",
"league/tactician-bundle": "^0.4.1",
"symfony/serializer": "^3.0",
"symfony/validator": "^3.0",
"symfony/framework-bundle": "^3.0",
"rezzza/rest-api-behat-extension": "^5.0",
"rezzza/rest-api-behat-extension": "^6.0",
"php-http/curl-client": "^1.5",
"guzzlehttp/psr7": "^1.3"
},
Expand Down
11 changes: 6 additions & 5 deletions src/JsonSchemaTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
namespace Rezzza\SymfonyRestApiJson;

use JsonSchema\Validator;
use JsonSchema\RefResolver;
use JsonSchema\SchemaStorage;
use JsonSchema\Uri;

/**
* Used as factory because JsonSchema\Validator and JsonSchema\RefResolver are not stateless
* Used as factory because JsonSchema\Validator and JsonSchema\SchemaStorage are not stateless
*/
class JsonSchemaTools
{
Expand All @@ -16,10 +16,11 @@ public function createValidator()
return new Validator;
}

public function createRefResolver()
public function createSchemaStorage()
{
return new RefResolver(
new Uri\UriRetriever(), new Uri\UriResolver()
return new SchemaStorage(
new Uri\UriRetriever(),
new Uri\UriResolver()
);
}
}
7 changes: 4 additions & 3 deletions src/PayloadValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ public function validate($payload, $jsonSchemaFilename)
}

$delegateValidator = $this->jsonSchemaTools->createValidator();
$refResolver = $this->jsonSchemaTools->createRefResolver();
$refResolver = $this->jsonSchemaTools->createSchemaStorage();

$data = json_decode($payload);
$delegateValidator->check(
json_decode($payload),
$refResolver->resolve('file://' . realpath($jsonSchemaFilename))
$data,
$refResolver->resolveRef('file://' . realpath($jsonSchemaFilename))
);

if (!$delegateValidator->isValid()) {
Expand Down
6 changes: 3 additions & 3 deletions tests/Units/PayloadValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function test_validation_should_be_delegated_to_internal_validator()
$validator = $this->mockJsonSchemaValidator(),
$this->calling($validator)->check = null,
$refResolver = $this->mockJsonSchemaRefResolver(),
$this->calling($refResolver)->resolve = 'resolvedJsonSchema',
$this->calling($refResolver)->resolveRef = 'resolvedJsonSchema',
$jsonSchemaTools = $this->mockJsonSchemaTools($validator, $refResolver),
$this->newTestedInstance($jsonSchemaTools)
)
Expand Down Expand Up @@ -75,15 +75,15 @@ private function mockJsonSchemaRefResolver()
{
$this->mockGenerator->orphanize('__construct');

return new \mock\JsonSchema\RefResolver;
return new \mock\JsonSchema\JsonStorage();
}

private function mockJsonSchemaTools($validator = null, $refResolver = null)
{
$this->mockGenerator->orphanize('__construct');
$mock = new \mock\Rezzza\SymfonyRestApiJson\JsonSchemaTools;
$this->calling($mock)->createValidator = $validator;
$this->calling($mock)->createRefResolver = $refResolver;
$this->calling($mock)->createSchemaStorage = $refResolver;

return $mock;
}
Expand Down

0 comments on commit 6ede6f8

Please sign in to comment.