160 Commits

Author SHA1 Message Date
Erayd
842c562f13
Swap values in tests (in violation of spec)
This commit deliberately tests in a way that violates the spec. Versions
of this library prior to 6.0.0 allow properties adjacent to $ref to
override properties with the same name from the $ref'ed schema. This is
explicitly in violation of the spec, but cannot be changed in 5.x.x, as
it results in a significant behavioral change that may break end users'
application logic.

This issue is resolved in 6.0.0, and siblings of $ref are correctly
ignored from 6.0.0 onwards.
2018-02-14 14:53:01 +13:00
David Porter
5550f3c359
Merge pull request #494 from erayd/apply-ref-default
[BUGFIX] Apply defaults in $ref'ed property / item definitions
2018-02-14 14:45:10 +13:00
David Porter
1a4e3394ab
Merge pull request #477 from localheinz/fix/unused-import
Enhancement: Implicitly enable no_unused_imports fixer
2018-02-14 14:42:17 +13:00
David Porter
0998cc8b9f
Merge pull request #485 from localheinz/fix/case
Fix: Case mismatch
2018-02-14 14:38:12 +13:00
David Porter
7845aa634c
Merge pull request #486 from localheinz/fix/argument
Fix: Remove unused argument from method call
2018-02-14 14:37:08 +13:00
David Porter
3597e445cd
Merge pull request #487 from localheinz/fix/assertion
Fix: Use more appropriate assertions
2018-02-14 14:36:09 +13:00
David Porter
bbff8be278
Merge pull request #488 from localheinz/fix/unused-method
Fix: Remove unused private method
2018-02-14 14:32:08 +13:00
David Porter
e08ea52506
Merge pull request #489 from localheinz/fix/unused-parameter
Fix: Remove unused parameter
2018-02-14 14:31:34 +13:00
David Porter
ca697a0b91
Merge pull request #466 from gabriel-caruso/phpunit
Use PHPUnit\Framework\TestCase instead of PHPUnit_Framework_TestCase
2018-02-14 14:29:46 +13:00
Erayd
7ccb0e67ea [BUGFIX] Don't resolve a schema id against itself (#452) (#453)
* Don't resolve a schema id against itself

* Add test for double-resolve bugfix
2017-10-04 22:57:36 +02:00
Erayd
b80053b620 Backports for 5.2.2 (Part 3) (#450)
* Update php-csfixer rules to address problem in 2.7 & new multiline rule (#449)

* Update php-csfixer rules to address problem in 2.7 & new multiline rule

 * yoda_style in 2.7 is dangerous and may result in logic errors. In
 some cases, it also results in invalid syntax.

 * multiline comments prefixed with // now seem to be misaligned, and
 this cannot be disabled, so have changed the relevant comment.

* PHP-5.3 is not available on trusty, so explicitly specify precise for 5.3

* Add proper recursive handling for $ref resolution base (#448)

Fixes #447

Note that this patch does not check whether a given container is
actually a schema when recursing into it. In most cases this will
not matter, however it does mean that in some edge cases it will
attempt to resolve a `$ref` in a context where ref is actually not
part of the spec. Limiting resolution to schema-context containers
is outside the scope of this patch, but can be added later.
2017-10-03 02:49:49 +02:00
Erayd
2a4203948b Backports for 5.2.2 (#431)
* Remove PHPDocumentor & change travis platform for hhvm tests (#429)

* Remove dev-time dependency on phpdocumentor due to resolution headaches

* Switch distro for hhvm testing to trusty (precise now unsupported)

* Bugfix for #424 - add '?' for query string (#425)

Note that this bugfix will cause empty query strings to be dropped (e.g.
http://example.com?#blue becomes http://example.com#blue). This is
because the '?' character is deliberately not captured as part of the
query string, and the testsuite expects to be able to pass an empty
query string and *not* have the '?' added for that case.
2017-06-05 15:17:19 -05:00
Erayd
429be236f2 Backports for 5.2.1 (#413)
* Split $objectDefinition into $schema and $properties (#411)

Object validation attempts to use a single variable to store both the
object definition, and its properties. This causes validation to be
incomplete where "properties" is not set, but "additionalProperties" is.

This commit fixes both bugs in issue #353.

* Issue-414: Allow The Option of T or space for Date time. (#415)

* Testcase for minProperties with properties defined (#416)

+ Fix Test

* Tweak phpdocumentor dependency to avoid install conflicts (#421)

* [BUGFIX] Cast empty schema arrays to object (#409)

* Cast root to object

* Use function_exists to allow polyfill compatibility

* Move array->object conversion to SchemaConstraint & SchemaStorage

Fixes issue #408

* fix bug when applying defaults for array items when the schema is for (#405)

all items and add support for minItems when applying defaults

* [BUGFIX] Split "uri" format into "uri" & "uri-reference", fix meta-schema bug (#419)

* Split "uri" format into "uri" and "uri-reference"

* Correct format for id & $ref in draft-03/04 meta-schemas

See https://github.com/json-schema-org/JSON-Schema-Test-Suite/issues/177#issuecomment-293051367
2017-05-16 16:06:09 -05:00
Erayd
e3c9bccdc3 Backports for 5.2.0 (#368)
* Add URI translation for retrieval & add local copies of spec schema

* Add use line for InvalidArgumentException & adjust scope (#372)

Fixes issue #371

* add quiet option (#382)

* add quiet option

* use verbose instead of quiet

* add quiet option

* always output dump-schema

* always output dump-schema-url

* fix typo and ws

* [BUGFIX] Add provided schema under a dummy / internal URI (fixes #376) (#378)

* Add provided schema under a dummy / internal URI (fixes #376)

In order to resolve internal $ref references within a user-provided
schema, SchemaStorage needs to know about the schema. As user-supplied
schemas do not have an associated URI, use a dummy / internal one instead.

* Remove dangling use

* Change URI to class constant on SchemaStorage

* Add option to disable validation of "format" constraint (#383)

* Add more unit tests (#366)

* Add test coverage for coercion API

* Complete test coverage for SchemaStorage

* Add test coverage for ObjectIterator

* Add exception test for JsonPointer

* MabeEnum\Enum appears to use singletons - add testing const

* Don't check this line for coverage

mbstring is on all test platforms, so this line will never be reached.

* Add test for TypeConstraint::validateTypeNameWording()

* Add test for exception on TypeConstraint::validateType()

* PHPunit doesn't like an explanation with its @codeCoverageIgnore...

* Add various tests for UriRetriever

* Add tests for FileGetContents

* Add tests for JsonSchema\Uri\Retrievers\Curl

* Add missing bad-syntax test file

* Restrict ignore to the exception line only

* Fix exception scope

* Allow the schema to be an associative array (#389)

* Allow the schema to be an associative array

Implements #388.

* Use json_decode(json_encode()) for array -> object cast

* Skip exception check on PHP versions < 5.5.0

* Skip test on HHVM, as it's happy to encode resources

* Enable FILTER_FLAG_EMAIL_UNICODE for email format if present (#398)

* Don't throw exceptions until after checking anyOf / oneOf (#394)

Fixes #393

* Fix infinite recursion on some schemas when setting defaults (#359) (#365)

* Don't try to fetch files that don't exist

Throws an exception when the ref can't be resolved to a useful file URI,
rather than waiting for something further down the line to fail after
the fact.

* Refactor defaults code to use LooseTypeCheck where appropriate

* Test for not treating non-containers like arrays

* Update comments

* Rename variable for clarity

* Add CHECK_MODE_ONLY_REQUIRED_DEFAULTS

If CHECK_MODE_ONLY_REQUIRED_DEFAULTS is set, then only apply defaults
if they are marked as required.

* Workaround for $this scope issue on PHP-5.3

* Fix infinite recursion via $ref when applying defaults

* Add missing second test for array case

* Add test for setting a default value for null

* Also fix infinite recursion via $ref for array defaults

* Move nested closure into separate method

* $parentSchema will always be set when $name is, so don't check it

* Handle nulls properly - fixes issue #377

* Add option to also validate the schema (#357)

* Remove stale files from #357 (obviated by #362) (#400)

* Stop #386 sneaking in alongside another PR backport
2017-03-22 18:43:35 -04:00
Erayd
282a63e17b Fix relative-path case where first segment contains a colon (#360) 2017-02-23 17:04:45 -06:00
Erayd
337855de25 Fix non-conforming URL validation (#358)
Json schema spec says URLs are validated as per RFC-3986, but PHP's
FILTER_VALIDATE_URL can't cope with relative path references, which are
explicitly allowed. See https://tools.ietf.org/html/rfc3986#section-4.2
for further information.
2017-02-23 13:00:20 -06:00
Erayd
48817e5f95 Add option to apply default values from the schema (#349)
* Add option to apply default values from the schema

* Clone default objects instead of passing by reference

Objects should always be assigned via clone, to prevent modifications
to the input object from also modifying the underlying schema.

* Run php-cs-fixer

* Remove two duplicate test cases
2017-02-21 21:28:16 -06:00
Rob
42c1043e1c Make code-style more consistent (#355)
* update branch-alias

* add php-cs-fixer configuration

* add php-cs-fixer to travis

* apply code-style rules
2017-02-21 13:11:59 -06:00
Erayd
7eb38e2b20 Option to throw exceptions when an error is encountered (#354)
* Add option to throw an exception on validation errors

* Update README

 * Changes API references to use the new Validator::validate() entry point
 * Adds section describing available config options
2017-02-15 19:56:09 -06:00
Erayd
9b6ebfeece Refactor to simplify the public API and make adding features easier (#351)
This commit makes the following changes:
 * Split the Constraint class to make Validator independent from it
 * Add Validator::validate() as the main entry point
 * Turn Validator::coerce() and Validator::check() into aliases
 * Add Factory::setConfig(), getConfig(), addConfig() & removeConfig()
 * Make type-coercion a checkMode option, don't pass $coerce everywhere
 * Add some extra tests
2017-02-15 10:21:39 -06:00
Francesco Lo Franco
325a0f8c59 Fix regex for Rfc3339 validation (#347) 2017-01-16 09:17:02 -06:00
Max Loeb
d39c56a46b Better coercion (#336)
* Better coercion

* add phpdocs
2016-12-22 10:43:46 -06:00
Iurii Antykhovych
9da41b076f improve validation performance of long string, number and integer arrays (#331)
* improve validation performance of long string and numeric arrays

* update 'Running the thests' section in README.md
2016-12-08 11:29:26 -06:00
jbaron-gingco
24aa1a916a [BUGFIX] Add unicode support in patternProperties and in format constraints (#338) 2016-12-02 11:42:45 -06:00
jbaron-gingco
10d1f6977f [BUGFIX] Use unicode matching for patterns, since JSON allows all unicode. (#330) 2016-11-09 10:32:33 -06:00
Max Loeb
43158d3844 handle negative integers (#325) 2016-10-24 14:51:15 -05:00
Max Loeb
d44cac08da handle coercion of multiple types (#322) 2016-10-24 12:24:56 -04:00
Robert Schönthal
31b29546f4 performance improvements (#310) 2016-10-10 07:37:37 -05:00
David Porter
c3e11beff3 fix(NumberConstraint): force positive value on first arg (#316)
Resolves #315 - `multipleOf` is inconsistent, fails for negative numbers
2016-10-10 05:20:45 -05:00
Max Loeb
d701d8f2ba Add support for $ref on properties (#317)
* add support for  on properties

* use classic array syntax
2016-10-10 04:18:54 +01:00
Max Loeb
a918d3b5d9 Add support for type coercion (#308)
* add support for type coercion

* add tests

* move coerce tests out of base

* use flags for mode

* update readme

* fix tests

* remove ws

* use binary literals, explicit cast

* back to hex
2016-10-09 20:36:01 +01:00
Patrick Safarov
1296583112 New way of handling references (#277) 2016-08-15 11:39:11 -05:00
Chris Wilkinson
ef13b9b94c Cache the results of RefResolver::resolve() (#290)
* Cache the results of RefResolver::resolve()

* Add test
2016-08-11 07:35:14 -05:00
David Porter
58b6e07fc0 Merge pull request #276 from steffkes/path-json-pointer
use JsonPointer for path handling
2016-08-11 07:34:30 -05:00
Florian
53a8486e62 Change error reporting for invalid types with multiple valid types
Currently, if a property has multiple valid types, an error message
when a value doesn't conform to the schema, would mention only the
last valid type, without mentioning the other valid types.

This commit changes, how the TypeConstraint works internally. It
does a little bit of refactoring (removing also the "Refacter this"
ToDo) and now mentions any valid types on a failure.

Fixes #293
2016-08-02 18:19:59 +02:00
steffkes
8c32e3e54d use JsonPointer for path handling 2016-08-02 15:02:29 +02:00
David Porter
ddabcf8025 Merge pull request #286 from boekkooi-fresh/array-as-object
Support json_decode assoc
2016-08-01 19:40:51 -05:00
David Porter
c269bdaa37 Merge pull request #278 from abacaphiliac/exception-interface
Exception interface
2016-07-25 18:45:42 -05:00
David Porter
6b56652c51 Merge pull request #287 from sinbonders/master
Updating to use more correct hostname regex. This fixes #129
2016-07-25 18:44:29 -05:00
Remi Collet
14c9472c2b Fix #291 failed tests with lestest PHP
Since 5.6.24, 7.0.9, 7.1.0beta1, negative timestamps are valid.
2016-07-21 18:37:10 +02:00
Ben Saunders
321f6af994 Updating to use more correct hostname regex. This fixes #129 2016-07-07 16:19:47 -07:00
Warnar Boekkooi
dd5717a760 Tweaked tests for assoc array tests 2016-07-04 11:47:19 +02:00
Warnar Boekkooi
d750e17d8f Added Tests for array assoc json decode 2016-07-04 11:47:19 +02:00
Tim Younger
1a5f3396ef add tests to validate existing exception hierarchy, in preparation for adjustment. add \RuntimeException wrapper. update all extensions of \RuntimeException to extend the wrapper. spl-exception wrappers now implement a common exception interface for this package. this allows consumers to handle all custom exception types thrown by catching the common interface rather than by catching each specific extension or their spl parents. 2016-06-28 13:10:14 -07:00
David Porter
8490e828c1 Merge pull request #234 from ehimen/fix-zero-secfrac
Fix: allow explicit 0 secfracs in datetime format
2016-06-28 15:00:59 -05:00
steffkes
7f9d9038ec move MinMaxPropertiesTest to proper location 2016-06-22 21:12:09 +02:00
Andy Cook
ffc856dbbe Fix: allow explicit 0 secfracs in datetime format 2016-06-09 13:18:46 +01:00
Mirosław Filip
346b3218dd 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
2016-05-09 23:42:42 +02:00
Sławomir Chrobak
84decc9a66 Skips min/max properties validation for non objects 2016-04-29 17:04:39 +02:00
bighappyface
0e7add4652 feat(UriRetriever): application/json support 2016-04-28 08:29:49 -05:00