Skip to content

Backports for 5.2.9 #591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ $config
'phpdoc_order' => true,
'phpdoc_summary' => false,
'pre_increment' => false,
'increment_style' => false,
'simplified_null_return' => false,
'trailing_comma_in_multiline_array' => false,
'yoda_style' => false,
'phpdoc_types_order' => array('null_adjustment' => 'none', 'sort_algorithm' => 'none'),
))
->setFinder($finder)
;
Expand Down
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@ matrix:
- php: 5.3
dist: precise
- php: 5.4
dist: trusty
- php: 5.5
dist: trusty
- php: 5.6
- php: 7.0
env: WITH_COVERAGE=true WITH_PHPCSFIXER=true
env: WITH_COVERAGE=true
- php: 7.0
env: WITH_PHPCSFIXER=true
- php: 7.1
- php: 7.2
- php: 7.3
- php: 'nightly'
- php: hhvm
dist: trusty
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"php": ">=5.3.3"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "~2.2.20",
"friendsofphp/php-cs-fixer": "~2.2.20||~2.15.1",
"json-schema/JSON-Schema-Test-Suite": "1.2.0",
"phpunit/phpunit": "^4.8.35"
},
Expand Down
6 changes: 6 additions & 0 deletions src/JsonSchema/Constraints/UndefinedConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ protected function validateCommonProperties(&$value, $schema = null, JsonPointer
'required'
);
}
} else {
// If the value is both undefined and not required, skip remaining checks
// in this method which assume an actual, defined instance when validating.
if ($value instanceof self) {
return;
}
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/JsonSchema/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ class Validator extends BaseConstraint
* Both the php object and the schema are supposed to be a result of a json_decode call.
* The validation works as defined by the schema proposal in http://json-schema.org.
*
* Note that the first argument is passwd by reference, so you must pass in a variable.
*
* {@inheritdoc}
* Note that the first argument is passed by reference, so you must pass in a variable.
*/
public function validate(&$value, $schema = null, $checkMode = null)
{
Expand Down
90 changes: 90 additions & 0 deletions tests/Constraints/ArraysTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,51 @@ public function getInvalidTests()
}
}
}'
),
array( // Test array items.enum where type string fail validation if value(s) is/are not in items.enum
'{"data": ["a", "b"]}',
'{
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"type": "string",
"enum": ["b", "c"]
}
}
}
}'
),
array( // Test array items.enum where type integer fail validation if value(s) is/are not in items.enum
'{"data": [1, 2]}',
'{
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"type": "integer",
"enum": [2, 3]
}
}
}
}'
),
array( // Test array items.enum where type number fail validation if value(s) is/are not in items.enum
'{"data": [1.25, 2.25]}',
'{
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"type": "number",
"enum": [1.25, 2]
}
}
}
}'
)
);
}
Expand Down Expand Up @@ -168,6 +213,51 @@ public function getValidTests()
}
}
}'
),
array( // Test array items.enum where type string passes validation if value(s) is/are in items.enum
'{"data": ["c", "c", "b"]}',
'{
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"type": "string",
"enum": ["b", "c"]
}
}
}
}'
),
array( // Test array items.enum where type integer passes validation if value(s) is/are in items.enum
'{"data": [1, 1, 2]}',
'{
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"type": "integer",
"enum": [1, 2]
}
}
}
}'
),
array( // Test array items.enum where type number passes validation if value(s) is/are in items.enum
'{"data": [1.25, 1.25, 2.25]}',
'{
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"type": "number",
"enum": [1.25, 2.25]
}
}
}
}'
)
);
}
Expand Down
27 changes: 27 additions & 0 deletions tests/Constraints/NotTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ public function getInvalidTests()
}
}
}'
),
array( // check that a missing, required property is correctly validated
'{"y": "foo"}',
'{
"type": "object",
"required": ["x"],
"properties": {
"x": {
"not": {
"type": "null"
}
}
}
}'
)
);
}
Expand Down Expand Up @@ -69,6 +83,19 @@ public function getValidTests()
}
}
}'
),
array( // check that a missing, non-required property isn't validated
'{"y": "foo"}',
'{
"type": "object",
"properties": {
"x": {
"not": {
"type": "null"
}
}
}
}'
)
);
}
Expand Down