diff --git a/.travis.yml b/.travis.yml index 487aed4..89b4d38 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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: diff --git a/composer.json b/composer.json index 30d1bef..13a6bb9 100644 --- a/composer.json +++ b/composer.json @@ -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" }, diff --git a/src/JsonSchemaTools.php b/src/JsonSchemaTools.php index d73c79d..2782e0c 100644 --- a/src/JsonSchemaTools.php +++ b/src/JsonSchemaTools.php @@ -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 { @@ -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() ); } } diff --git a/src/PayloadValidator.php b/src/PayloadValidator.php index e8a897e..2b34755 100644 --- a/src/PayloadValidator.php +++ b/src/PayloadValidator.php @@ -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()) { diff --git a/tests/Units/PayloadValidator.php b/tests/Units/PayloadValidator.php index 1030a35..22346ec 100644 --- a/tests/Units/PayloadValidator.php +++ b/tests/Units/PayloadValidator.php @@ -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) ) @@ -75,7 +75,7 @@ private function mockJsonSchemaRefResolver() { $this->mockGenerator->orphanize('__construct'); - return new \mock\JsonSchema\RefResolver; + return new \mock\JsonSchema\JsonStorage(); } private function mockJsonSchemaTools($validator = null, $refResolver = null) @@ -83,7 +83,7 @@ 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; }