diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 134bd93c..df516fb8 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -6,14 +6,14 @@ /* Based on ^2.1 of php-cs-fixer */ $config - ->setRules(array( + ->setRules([ // default '@PSR2' => true, '@Symfony' => true, // additionally - 'array_syntax' => array('syntax' => 'long'), + 'array_syntax' => ['syntax' => 'short'], 'binary_operator_spaces' => false, - 'concat_space' => array('spacing' => 'one'), + 'concat_space' => ['spacing' => 'one'], 'increment_style' => false, 'no_superfluous_phpdoc_tags' => false, 'no_useless_else' => true, @@ -22,12 +22,12 @@ 'phpdoc_no_package' => false, 'phpdoc_order' => true, 'phpdoc_summary' => false, - 'phpdoc_types_order' => array('null_adjustment' => 'none', 'sort_algorithm' => 'none'), + 'phpdoc_types_order' => ['null_adjustment' => 'none', 'sort_algorithm' => 'none'], 'simplified_null_return' => false, 'single_line_throw' => false, 'trailing_comma_in_multiline' => false, 'yoda_style' => false, - )) + ]) ->setFinder($finder) ; diff --git a/CHANGELOG.md b/CHANGELOG.md index fbaa5be1..b16abb0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add missing property in UriResolverTest ([#743](https://github.com/jsonrainbow/json-schema/pull/743)) - Correct casing of paths used in tests ([#745](https://github.com/jsonrainbow/json-schema/pull/745)) +### Changed +- Bump to minimum PHP 7.2 ([#746](https://github.com/jsonrainbow/json-schema/pull/746)) +- Replace traditional syntax array with short syntax array ([#747](https://github.com/jsonrainbow/json-schema/pull/747)) + ## [6.0.0] - 2024-07-30 ### Added - Add URI translation, package:// URI scheme & bundle spec schemas ([#362](https://github.com/jsonrainbow/json-schema/pull/362)) diff --git a/bin/validate-json b/bin/validate-json index 3f9ab811..62c3ab0a 100755 --- a/bin/validate-json +++ b/bin/validate-json @@ -20,8 +20,8 @@ if (!$composerAutoload) { } require($composerAutoload); -$arOptions = array(); -$arArgs = array(); +$arOptions = []; +$arArgs = []; array_shift($argv);//script itself foreach ($argv as $arg) { if ($arg[0] == '-') { @@ -66,7 +66,7 @@ if (count($arArgs) == 1) { function showJsonError() { $constants = get_defined_constants(true); - $json_errors = array(); + $json_errors = []; foreach ($constants['json'] as $name => $value) { if (!strncmp($name, 'JSON_ERROR_', 11)) { $json_errors[$value] = $name; @@ -101,11 +101,11 @@ function getUrlFromPath($path) function parseHeaderValue($headerValue) { if (strpos($headerValue, ';') === false) { - return array('_value' => $headerValue); + return ['_value' => $headerValue]; } $parts = explode(';', $headerValue); - $arData = array('_value' => array_shift($parts)); + $arData = ['_value' => array_shift($parts)]; foreach ($parts as $part) { list($name, $value) = explode('=', $part); $arData[$name] = trim($value, ' "\''); @@ -128,15 +128,15 @@ function output($str) { $urlData = getUrlFromPath($pathData); $context = stream_context_create( - array( - 'http' => array( - 'header' => array( + [ + 'http' => [ + 'header' => [ 'Accept: */*', 'Connection: Close' - ), + ], 'max_redirects' => 5 - ) - ) + ] + ] ); $dataString = file_get_contents($pathData, false, $context); if ($dataString == '') { diff --git a/demo/demo.php b/demo/demo.php index 3f824901..caee4e71 100644 --- a/demo/demo.php +++ b/demo/demo.php @@ -6,7 +6,7 @@ // Validate $validator = new JsonSchema\Validator(); -$validator->validate($data, (object) array('$ref' => 'file://' . realpath('schema.json'))); +$validator->validate($data, (object) ['$ref' => 'file://' . realpath('schema.json')]); if ($validator->isValid()) { echo "The supplied JSON validates against the schema.\n"; diff --git a/src/JsonSchema/ConstraintError.php b/src/JsonSchema/ConstraintError.php index fd5ba8e6..aaa4ec7c 100644 --- a/src/JsonSchema/ConstraintError.php +++ b/src/JsonSchema/ConstraintError.php @@ -55,7 +55,7 @@ class ConstraintError extends Enum public function getMessage() { $name = $this->getValue(); - static $messages = array( + static $messages = [ self::ADDITIONAL_ITEMS => 'The item %s[%s] is not defined and the definition does not allow additional items', self::ADDITIONAL_PROPERTIES => 'The property %s is not defined and the definition does not allow additional properties', self::ALL_OF => 'Failed to match all schemas', @@ -101,7 +101,7 @@ public function getMessage() self::PROPERTIES_MAX => 'Must contain no more than %d properties', self::TYPE => '%s value found, but %s is required', self::UNIQUE_ITEMS => 'There are no duplicates allowed in the array' - ); + ]; if (!isset($messages[$name])) { throw new InvalidArgumentException('Missing error message for ' . $name); diff --git a/src/JsonSchema/Constraints/BaseConstraint.php b/src/JsonSchema/Constraints/BaseConstraint.php index bd07d70f..66be2dcd 100644 --- a/src/JsonSchema/Constraints/BaseConstraint.php +++ b/src/JsonSchema/Constraints/BaseConstraint.php @@ -24,7 +24,7 @@ class BaseConstraint /** * @var array Errors */ - protected $errors = array(); + protected $errors = []; /** * @var int All error types which have occurred @@ -44,11 +44,11 @@ public function __construct(?Factory $factory = null) $this->factory = $factory ?: new Factory(); } - public function addError(ConstraintError $constraint, ?JsonPointer $path = null, array $more = array()) + public function addError(ConstraintError $constraint, ?JsonPointer $path = null, array $more = []) { $message = $constraint ? $constraint->getMessage() : ''; $name = $constraint ? $constraint->getValue() : ''; - $error = array( + $error = [ 'property' => $this->convertJsonPointerIntoPropertyPath($path ?: new JsonPointer('')), 'pointer' => ltrim(strval($path ?: new JsonPointer('')), '#'), 'message' => ucfirst(vsprintf($message, array_map(function ($val) { @@ -58,12 +58,12 @@ public function addError(ConstraintError $constraint, ?JsonPointer $path = null, return json_encode($val); }, array_values($more)))), - 'constraint' => array( + 'constraint' => [ 'name' => $name, 'params' => $more - ), + ], 'context' => $this->factory->getErrorContext(), - ); + ]; if ($this->factory->getConfig(Constraint::CHECK_MODE_EXCEPTIONS)) { throw new ValidationException(sprintf('Error validating %s: %s', $error['pointer'], $error['message'])); @@ -119,7 +119,7 @@ public function isValid() */ public function reset() { - $this->errors = array(); + $this->errors = []; $this->errorMask = Validator::ERROR_NONE; } diff --git a/src/JsonSchema/Constraints/CollectionConstraint.php b/src/JsonSchema/Constraints/CollectionConstraint.php index 98aad564..d563fd77 100644 --- a/src/JsonSchema/Constraints/CollectionConstraint.php +++ b/src/JsonSchema/Constraints/CollectionConstraint.php @@ -27,12 +27,12 @@ public function check(&$value, $schema = null, ?JsonPointer $path = null, $i = n { // Verify minItems if (isset($schema->minItems) && count($value) < $schema->minItems) { - $this->addError(ConstraintError::MIN_ITEMS(), $path, array('minItems' => $schema->minItems)); + $this->addError(ConstraintError::MIN_ITEMS(), $path, ['minItems' => $schema->minItems]); } // Verify maxItems if (isset($schema->maxItems) && count($value) > $schema->maxItems) { - $this->addError(ConstraintError::MAX_ITEMS(), $path, array('maxItems' => $schema->maxItems)); + $this->addError(ConstraintError::MAX_ITEMS(), $path, ['maxItems' => $schema->maxItems]); } // Verify uniqueItems @@ -101,11 +101,11 @@ protected function validateItems(&$value, $schema = null, ?JsonPointer $path = n $this->addError( ConstraintError::ADDITIONAL_ITEMS(), $path, - array( + [ 'item' => $i, 'property' => $k, 'additionalItems' => $schema->additionalItems - ) + ] ); } } else { diff --git a/src/JsonSchema/Constraints/ConstConstraint.php b/src/JsonSchema/Constraints/ConstConstraint.php index 80c45cca..18076048 100644 --- a/src/JsonSchema/Constraints/ConstConstraint.php +++ b/src/JsonSchema/Constraints/ConstConstraint.php @@ -44,6 +44,6 @@ public function check(&$element, $schema = null, ?JsonPointer $path = null, $i = return; } - $this->addError(ConstraintError::CONSTANT(), $path, array('const' => $schema->const)); + $this->addError(ConstraintError::CONSTANT(), $path, ['const' => $schema->const]); } } diff --git a/src/JsonSchema/Constraints/Constraint.php b/src/JsonSchema/Constraints/Constraint.php index 8a988cda..bc20e97b 100644 --- a/src/JsonSchema/Constraints/Constraint.php +++ b/src/JsonSchema/Constraints/Constraint.php @@ -51,7 +51,7 @@ protected function incrementPath(?JsonPointer $path = null, $i) $path = $path->withPropertyPaths( array_merge( $path->getPropertyPaths(), - array($i) + [$i] ) ); @@ -85,7 +85,7 @@ protected function checkArray(&$value, $schema = null, ?JsonPointer $path = null * @param mixed $patternProperties */ protected function checkObject(&$value, $schema = null, ?JsonPointer $path = null, $properties = null, - $additionalProperties = null, $patternProperties = null, $appliedDefaults = array()) + $additionalProperties = null, $patternProperties = null, $appliedDefaults = []) { /** @var ObjectConstraint $validator */ $validator = $this->factory->createInstanceFor('object'); diff --git a/src/JsonSchema/Constraints/ConstraintInterface.php b/src/JsonSchema/Constraints/ConstraintInterface.php index 209e5712..2c2e23d9 100644 --- a/src/JsonSchema/Constraints/ConstraintInterface.php +++ b/src/JsonSchema/Constraints/ConstraintInterface.php @@ -40,7 +40,7 @@ public function addErrors(array $errors); * @param JsonPointer|null $path * @param array $more more array elements to add to the error */ - public function addError(ConstraintError $constraint, ?JsonPointer $path = null, array $more = array()); + public function addError(ConstraintError $constraint, ?JsonPointer $path = null, array $more = []); /** * checks if the validator has not raised errors diff --git a/src/JsonSchema/Constraints/EnumConstraint.php b/src/JsonSchema/Constraints/EnumConstraint.php index 73fb8d24..22686673 100644 --- a/src/JsonSchema/Constraints/EnumConstraint.php +++ b/src/JsonSchema/Constraints/EnumConstraint.php @@ -47,6 +47,6 @@ public function check(&$element, $schema = null, ?JsonPointer $path = null, $i = } } - $this->addError(ConstraintError::ENUM(), $path, array('enum' => $schema->enum)); + $this->addError(ConstraintError::ENUM(), $path, ['enum' => $schema->enum]); } } diff --git a/src/JsonSchema/Constraints/Factory.php b/src/JsonSchema/Constraints/Factory.php index 5f798c99..92f01ad5 100644 --- a/src/JsonSchema/Constraints/Factory.php +++ b/src/JsonSchema/Constraints/Factory.php @@ -39,7 +39,7 @@ class Factory /** * @var TypeCheck\TypeCheckInterface[] */ - private $typeCheck = array(); + private $typeCheck = []; /** * @var int Validation context @@ -49,7 +49,7 @@ class Factory /** * @var array */ - protected $constraintMap = array( + protected $constraintMap = [ 'array' => 'JsonSchema\Constraints\CollectionConstraint', 'collection' => 'JsonSchema\Constraints\CollectionConstraint', 'object' => 'JsonSchema\Constraints\ObjectConstraint', @@ -62,12 +62,12 @@ class Factory 'format' => 'JsonSchema\Constraints\FormatConstraint', 'schema' => 'JsonSchema\Constraints\SchemaConstraint', 'validator' => 'JsonSchema\Validator' - ); + ]; /** * @var array */ - private $instanceCache = array(); + private $instanceCache = []; /** * @param ?SchemaStorage $schemaStorage diff --git a/src/JsonSchema/Constraints/FormatConstraint.php b/src/JsonSchema/Constraints/FormatConstraint.php index a302573f..355c6c0c 100644 --- a/src/JsonSchema/Constraints/FormatConstraint.php +++ b/src/JsonSchema/Constraints/FormatConstraint.php @@ -34,73 +34,73 @@ public function check(&$element, $schema = null, ?JsonPointer $path = null, $i = switch ($schema->format) { case 'date': if (!$date = $this->validateDateTime($element, 'Y-m-d')) { - $this->addError(ConstraintError::FORMAT_DATE(), $path, array( + $this->addError(ConstraintError::FORMAT_DATE(), $path, [ 'date' => $element, 'format' => $schema->format - ) + ] ); } break; case 'time': if (!$this->validateDateTime($element, 'H:i:s')) { - $this->addError(ConstraintError::FORMAT_TIME(), $path, array( + $this->addError(ConstraintError::FORMAT_TIME(), $path, [ 'time' => json_encode($element), 'format' => $schema->format, - ) + ] ); } break; case 'date-time': if (null === Rfc3339::createFromString($element)) { - $this->addError(ConstraintError::FORMAT_DATE_TIME(), $path, array( + $this->addError(ConstraintError::FORMAT_DATE_TIME(), $path, [ 'dateTime' => json_encode($element), 'format' => $schema->format - ) + ] ); } break; case 'utc-millisec': if (!$this->validateDateTime($element, 'U')) { - $this->addError(ConstraintError::FORMAT_DATE_UTC(), $path, array( + $this->addError(ConstraintError::FORMAT_DATE_UTC(), $path, [ 'value' => $element, - 'format' => $schema->format)); + 'format' => $schema->format]); } break; case 'regex': if (!$this->validateRegex($element)) { - $this->addError(ConstraintError::FORMAT_REGEX(), $path, array( + $this->addError(ConstraintError::FORMAT_REGEX(), $path, [ 'value' => $element, 'format' => $schema->format - ) + ] ); } break; case 'color': if (!$this->validateColor($element)) { - $this->addError(ConstraintError::FORMAT_COLOR(), $path, array('format' => $schema->format)); + $this->addError(ConstraintError::FORMAT_COLOR(), $path, ['format' => $schema->format]); } break; case 'style': if (!$this->validateStyle($element)) { - $this->addError(ConstraintError::FORMAT_STYLE(), $path, array('format' => $schema->format)); + $this->addError(ConstraintError::FORMAT_STYLE(), $path, ['format' => $schema->format]); } break; case 'phone': if (!$this->validatePhone($element)) { - $this->addError(ConstraintError::FORMAT_PHONE(), $path, array('format' => $schema->format)); + $this->addError(ConstraintError::FORMAT_PHONE(), $path, ['format' => $schema->format]); } break; case 'uri': if (null === filter_var($element, FILTER_VALIDATE_URL, FILTER_NULL_ON_FAILURE)) { - $this->addError(ConstraintError::FORMAT_URL(), $path, array('format' => $schema->format)); + $this->addError(ConstraintError::FORMAT_URL(), $path, ['format' => $schema->format]); } break; @@ -125,7 +125,7 @@ public function check(&$element, $schema = null, ?JsonPointer $path = null, $i = $validURL = null; } if ($validURL === null) { - $this->addError(ConstraintError::FORMAT_URL_REF(), $path, array('format' => $schema->format)); + $this->addError(ConstraintError::FORMAT_URL_REF(), $path, ['format' => $schema->format]); } } break; @@ -137,27 +137,27 @@ public function check(&$element, $schema = null, ?JsonPointer $path = null, $i = $filterFlags |= constant('FILTER_FLAG_EMAIL_UNICODE'); // @codeCoverageIgnore } if (null === filter_var($element, FILTER_VALIDATE_EMAIL, $filterFlags)) { - $this->addError(ConstraintError::FORMAT_EMAIL(), $path, array('format' => $schema->format)); + $this->addError(ConstraintError::FORMAT_EMAIL(), $path, ['format' => $schema->format]); } break; case 'ip-address': case 'ipv4': if (null === filter_var($element, FILTER_VALIDATE_IP, FILTER_NULL_ON_FAILURE | FILTER_FLAG_IPV4)) { - $this->addError(ConstraintError::FORMAT_IP(), $path, array('format' => $schema->format)); + $this->addError(ConstraintError::FORMAT_IP(), $path, ['format' => $schema->format]); } break; case 'ipv6': if (null === filter_var($element, FILTER_VALIDATE_IP, FILTER_NULL_ON_FAILURE | FILTER_FLAG_IPV6)) { - $this->addError(ConstraintError::FORMAT_IP(), $path, array('format' => $schema->format)); + $this->addError(ConstraintError::FORMAT_IP(), $path, ['format' => $schema->format]); } break; case 'host-name': case 'hostname': if (!$this->validateHostname($element)) { - $this->addError(ConstraintError::FORMAT_HOSTNAME(), $path, array('format' => $schema->format)); + $this->addError(ConstraintError::FORMAT_HOSTNAME(), $path, ['format' => $schema->format]); } break; @@ -194,9 +194,9 @@ protected function validateRegex($regex) protected function validateColor($color) { - if (in_array(strtolower($color), array('aqua', 'black', 'blue', 'fuchsia', + if (in_array(strtolower($color), ['aqua', 'black', 'blue', 'fuchsia', 'gray', 'green', 'lime', 'maroon', 'navy', 'olive', 'orange', 'purple', - 'red', 'silver', 'teal', 'white', 'yellow'))) { + 'red', 'silver', 'teal', 'white', 'yellow'])) { return true; } diff --git a/src/JsonSchema/Constraints/NumberConstraint.php b/src/JsonSchema/Constraints/NumberConstraint.php index 80b9d4dd..90c3eb04 100644 --- a/src/JsonSchema/Constraints/NumberConstraint.php +++ b/src/JsonSchema/Constraints/NumberConstraint.php @@ -29,40 +29,40 @@ public function check(&$element, $schema = null, ?JsonPointer $path = null, $i = if (isset($schema->exclusiveMinimum)) { if (isset($schema->minimum)) { if ($schema->exclusiveMinimum && $element <= $schema->minimum) { - $this->addError(ConstraintError::EXCLUSIVE_MINIMUM(), $path, array('minimum' => $schema->minimum)); + $this->addError(ConstraintError::EXCLUSIVE_MINIMUM(), $path, ['minimum' => $schema->minimum]); } elseif ($element < $schema->minimum) { - $this->addError(ConstraintError::MINIMUM(), $path, array('minimum' => $schema->minimum)); + $this->addError(ConstraintError::MINIMUM(), $path, ['minimum' => $schema->minimum]); } } else { $this->addError(ConstraintError::MISSING_MINIMUM(), $path); } } elseif (isset($schema->minimum) && $element < $schema->minimum) { - $this->addError(ConstraintError::MINIMUM(), $path, array('minimum' => $schema->minimum)); + $this->addError(ConstraintError::MINIMUM(), $path, ['minimum' => $schema->minimum]); } // Verify maximum if (isset($schema->exclusiveMaximum)) { if (isset($schema->maximum)) { if ($schema->exclusiveMaximum && $element >= $schema->maximum) { - $this->addError(ConstraintError::EXCLUSIVE_MAXIMUM(), $path, array('maximum' => $schema->maximum)); + $this->addError(ConstraintError::EXCLUSIVE_MAXIMUM(), $path, ['maximum' => $schema->maximum]); } elseif ($element > $schema->maximum) { - $this->addError(ConstraintError::MAXIMUM(), $path, array('maximum' => $schema->maximum)); + $this->addError(ConstraintError::MAXIMUM(), $path, ['maximum' => $schema->maximum]); } } else { $this->addError(ConstraintError::MISSING_MAXIMUM(), $path); } } elseif (isset($schema->maximum) && $element > $schema->maximum) { - $this->addError(ConstraintError::MAXIMUM(), $path, array('maximum' => $schema->maximum)); + $this->addError(ConstraintError::MAXIMUM(), $path, ['maximum' => $schema->maximum]); } // Verify divisibleBy - Draft v3 if (isset($schema->divisibleBy) && $this->fmod($element, $schema->divisibleBy) != 0) { - $this->addError(ConstraintError::DIVISIBLE_BY(), $path, array('divisibleBy' => $schema->divisibleBy)); + $this->addError(ConstraintError::DIVISIBLE_BY(), $path, ['divisibleBy' => $schema->divisibleBy]); } // Verify multipleOf - Draft v4 if (isset($schema->multipleOf) && $this->fmod($element, $schema->multipleOf) != 0) { - $this->addError(ConstraintError::MULTIPLE_OF(), $path, array('multipleOf' => $schema->multipleOf)); + $this->addError(ConstraintError::MULTIPLE_OF(), $path, ['multipleOf' => $schema->multipleOf]); } $this->checkFormat($element, $schema, $path, $i); diff --git a/src/JsonSchema/Constraints/ObjectConstraint.php b/src/JsonSchema/Constraints/ObjectConstraint.php index d633f372..36daf77d 100644 --- a/src/JsonSchema/Constraints/ObjectConstraint.php +++ b/src/JsonSchema/Constraints/ObjectConstraint.php @@ -23,13 +23,13 @@ class ObjectConstraint extends Constraint /** * @var array List of properties to which a default value has been applied */ - protected $appliedDefaults = array(); + protected $appliedDefaults = []; /** * {@inheritdoc} */ public function check(&$element, $schema = null, ?JsonPointer $path = null, $properties = null, - $additionalProp = null, $patternProperties = null, $appliedDefaults = array()) + $additionalProp = null, $patternProperties = null, $appliedDefaults = []) { if ($element instanceof UndefinedConstraint) { return; @@ -37,7 +37,7 @@ public function check(&$element, $schema = null, ?JsonPointer $path = null, $pro $this->appliedDefaults = $appliedDefaults; - $matches = array(); + $matches = []; if ($patternProperties) { // validate the element pattern properties $matches = $this->validatePatternProperties($element, $path, $patternProperties); @@ -54,13 +54,13 @@ public function check(&$element, $schema = null, ?JsonPointer $path = null, $pro public function validatePatternProperties($element, ?JsonPointer $path = null, $patternProperties) { - $matches = array(); + $matches = []; foreach ($patternProperties as $pregex => $schema) { $fullRegex = self::jsonPatternToPhpRegex($pregex); // Validate the pattern before using it to test for matches if (@preg_match($fullRegex, '') === false) { - $this->addError(ConstraintError::PREGEX_INVALID(), $path, array('pregex' => $pregex)); + $this->addError(ConstraintError::PREGEX_INVALID(), $path, ['pregex' => $pregex]); continue; } foreach ($element as $i => $value) { @@ -94,7 +94,7 @@ public function validateElement($element, $matches, $schema = null, ?JsonPointer // no additional properties allowed if (!in_array($i, $matches) && $additionalProp === false && $this->inlineSchemaProperty !== $i && !$definition) { - $this->addError(ConstraintError::ADDITIONAL_PROPERTIES(), $path, array('property' => $i)); + $this->addError(ConstraintError::ADDITIONAL_PROPERTIES(), $path, ['property' => $i]); } // additional properties defined @@ -109,10 +109,10 @@ public function validateElement($element, $matches, $schema = null, ?JsonPointer // property requires presence of another $require = $this->getProperty($definition, 'requires'); if ($require && !$this->getProperty($element, $require)) { - $this->addError(ConstraintError::REQUIRES(), $path, array( + $this->addError(ConstraintError::REQUIRES(), $path, [ 'property' => $i, 'requiredProperty' => $require - )); + ]); } $property = $this->getProperty($element, $i, $this->factory->createInstanceFor('undefined')); @@ -176,13 +176,13 @@ protected function validateMinMaxConstraint($element, $objectDefinition, ?JsonPo // Verify minimum number of properties if (isset($objectDefinition->minProperties) && !is_object($objectDefinition->minProperties)) { if ($this->getTypeCheck()->propertyCount($element) < $objectDefinition->minProperties) { - $this->addError(ConstraintError::PROPERTIES_MIN(), $path, array('minProperties' => $objectDefinition->minProperties)); + $this->addError(ConstraintError::PROPERTIES_MIN(), $path, ['minProperties' => $objectDefinition->minProperties]); } } // Verify maximum number of properties if (isset($objectDefinition->maxProperties) && !is_object($objectDefinition->maxProperties)) { if ($this->getTypeCheck()->propertyCount($element) > $objectDefinition->maxProperties) { - $this->addError(ConstraintError::PROPERTIES_MAX(), $path, array('maxProperties' => $objectDefinition->maxProperties)); + $this->addError(ConstraintError::PROPERTIES_MAX(), $path, ['maxProperties' => $objectDefinition->maxProperties]); } } } diff --git a/src/JsonSchema/Constraints/StringConstraint.php b/src/JsonSchema/Constraints/StringConstraint.php index 29981f23..ded7e570 100644 --- a/src/JsonSchema/Constraints/StringConstraint.php +++ b/src/JsonSchema/Constraints/StringConstraint.php @@ -27,23 +27,23 @@ public function check(&$element, $schema = null, ?JsonPointer $path = null, $i = { // Verify maxLength if (isset($schema->maxLength) && $this->strlen($element) > $schema->maxLength) { - $this->addError(ConstraintError::LENGTH_MAX(), $path, array( + $this->addError(ConstraintError::LENGTH_MAX(), $path, [ 'maxLength' => $schema->maxLength, - )); + ]); } //verify minLength if (isset($schema->minLength) && $this->strlen($element) < $schema->minLength) { - $this->addError(ConstraintError::LENGTH_MIN(), $path, array( + $this->addError(ConstraintError::LENGTH_MIN(), $path, [ 'minLength' => $schema->minLength, - )); + ]); } // Verify a regex pattern if (isset($schema->pattern) && !preg_match(self::jsonPatternToPhpRegex($schema->pattern), $element)) { - $this->addError(ConstraintError::PATTERN(), $path, array( + $this->addError(ConstraintError::PATTERN(), $path, [ 'pattern' => $schema->pattern, - )); + ]); } $this->checkFormat($element, $schema, $path, $i); diff --git a/src/JsonSchema/Constraints/TypeConstraint.php b/src/JsonSchema/Constraints/TypeConstraint.php index c7a0b593..b898277a 100644 --- a/src/JsonSchema/Constraints/TypeConstraint.php +++ b/src/JsonSchema/Constraints/TypeConstraint.php @@ -25,7 +25,7 @@ class TypeConstraint extends Constraint /** * @var array|string[] type wordings for validation error messages */ - public static $wording = array( + public static $wording = [ 'integer' => 'an integer', 'number' => 'a number', 'boolean' => 'a boolean', @@ -35,7 +35,7 @@ class TypeConstraint extends Constraint 'null' => 'a null', 'any' => null, // validation of 'any' is always true so is not needed in message wording 0 => null, // validation of a false-y value is always true, so not needed as well - ); + ]; /** * {@inheritdoc} @@ -46,7 +46,7 @@ public function check(&$value = null, $schema = null, ?JsonPointer $path = null, $isValid = false; $coerce = $this->factory->getConfig(self::CHECK_MODE_COERCE_TYPES); $earlyCoerce = $this->factory->getConfig(self::CHECK_MODE_EARLY_COERCE); - $wording = array(); + $wording = []; if (is_array($type)) { $this->validateTypesArray($value, $type, $wording, $isValid, $path, $coerce && $earlyCoerce); @@ -69,10 +69,10 @@ public function check(&$value = null, $schema = null, ?JsonPointer $path = null, $this->validateTypeNameWording($type); $wording[] = self::$wording[$type]; } - $this->addError(ConstraintError::TYPE(), $path, array( + $this->addError(ConstraintError::TYPE(), $path, [ 'found' => gettype($value), 'expected' => $this->implodeWith($wording, ', ', 'or') - )); + ]); } } @@ -136,7 +136,7 @@ protected function implodeWith(array $elements, $delimiter = ', ', $listEnd = fa } $lastElement = array_slice($elements, -1); $firsElements = join($delimiter, array_slice($elements, 0, -1)); - $implodedElements = array_merge(array($firsElements), $lastElement); + $implodedElements = array_merge([$firsElements], $lastElement); return join(" $listEnd ", $implodedElements); } @@ -308,7 +308,7 @@ protected function toInteger($value) protected function toArray($value) { if (is_scalar($value) || is_null($value)) { - return array($value); + return [$value]; } return $value; diff --git a/src/JsonSchema/Constraints/UndefinedConstraint.php b/src/JsonSchema/Constraints/UndefinedConstraint.php index 6b4ad5e8..aa28c191 100644 --- a/src/JsonSchema/Constraints/UndefinedConstraint.php +++ b/src/JsonSchema/Constraints/UndefinedConstraint.php @@ -27,7 +27,7 @@ class UndefinedConstraint extends Constraint /** * @var array List of properties to which a default value has been applied */ - protected $appliedDefaults = array(); + protected $appliedDefaults = []; /** * {@inheritdoc} @@ -141,9 +141,9 @@ protected function validateCommonProperties(&$value, $schema, JsonPointer $path, if (!$this->getTypeCheck()->propertyExists($value, $required)) { $this->addError( ConstraintError::REQUIRED(), - $this->incrementPath($path, $required), array( + $this->incrementPath($path, $required), [ 'property' => $required - ) + ] ); } } @@ -152,7 +152,7 @@ protected function validateCommonProperties(&$value, $schema, JsonPointer $path, if ($schema->required && $value instanceof self) { $propertyPaths = $path->getPropertyPaths(); $propertyName = end($propertyPaths); - $this->addError(ConstraintError::REQUIRED(), $path, array('property' => $propertyName)); + $this->addError(ConstraintError::REQUIRED(), $path, ['property' => $propertyName]); } } else { // if the value is both undefined and not required, skip remaining checks @@ -269,7 +269,7 @@ protected function applyDefaultValues(&$value, $schema, $path) } } } elseif (isset($schema->items) && LooseTypeCheck::isArray($value)) { - $items = array(); + $items = []; if (LooseTypeCheck::isArray($schema->items)) { $items = $schema->items; } elseif (isset($schema->minItems) && count($value) < $schema->minItems) { @@ -349,12 +349,12 @@ protected function validateOfProperties(&$value, $schema, JsonPointer $path, $i } if (isset($schema->oneOf)) { - $allErrors = array(); + $allErrors = []; $matchedSchemas = 0; $startErrors = $this->getErrors(); foreach ($schema->oneOf as $oneOf) { try { - $this->errors = array(); + $this->errors = []; $this->checkUndefined($value, $oneOf, $path, $i); if (count($this->getErrors()) == 0) { $matchedSchemas++; @@ -389,19 +389,19 @@ protected function validateDependencies($value, $dependencies, JsonPointer $path if (is_string($dependency)) { // Draft 3 string is allowed - e.g. "dependencies": {"bar": "foo"} if (!$this->getTypeCheck()->propertyExists($value, $dependency)) { - $this->addError(ConstraintError::DEPENDENCIES(), $path, array( + $this->addError(ConstraintError::DEPENDENCIES(), $path, [ 'key' => $key, 'dependency' => $dependency - )); + ]); } } elseif (is_array($dependency)) { // Draft 4 must be an array - e.g. "dependencies": {"bar": ["foo"]} foreach ($dependency as $d) { if (!$this->getTypeCheck()->propertyExists($value, $d)) { - $this->addError(ConstraintError::DEPENDENCIES(), $path, array( + $this->addError(ConstraintError::DEPENDENCIES(), $path, [ 'key' => $key, 'dependency' => $dependency - )); + ]); } } } elseif (is_object($dependency)) { diff --git a/src/JsonSchema/Entity/JsonPointer.php b/src/JsonSchema/Entity/JsonPointer.php index fcaf5b8d..7f7f5a57 100644 --- a/src/JsonSchema/Entity/JsonPointer.php +++ b/src/JsonSchema/Entity/JsonPointer.php @@ -22,7 +22,7 @@ class JsonPointer private $filename; /** @var string[] */ - private $propertyPaths = array(); + private $propertyPaths = []; /** * @var bool Whether the value at this path was set from a schema default @@ -54,7 +54,7 @@ public function __construct($value) */ private function decodePropertyPaths($propertyPathString) { - $paths = array(); + $paths = []; foreach (explode('/', trim($propertyPathString, '/')) as $path) { $path = $this->decodePath($path); if (is_string($path) && '' !== $path) { @@ -71,7 +71,7 @@ private function decodePropertyPaths($propertyPathString) private function encodePropertyPaths() { return array_map( - array($this, 'encodePath'), + [$this, 'encodePath'], $this->getPropertyPaths() ); } @@ -83,7 +83,7 @@ private function encodePropertyPaths() */ private function decodePath($path) { - return strtr($path, array('~1' => '/', '~0' => '~', '%25' => '%')); + return strtr($path, ['~1' => '/', '~0' => '~', '%25' => '%']); } /** @@ -93,7 +93,7 @@ private function decodePath($path) */ private function encodePath($path) { - return strtr($path, array('/' => '~1', '~' => '~0', '%' => '%25')); + return strtr($path, ['/' => '~1', '~' => '~0', '%' => '%25']); } /** diff --git a/src/JsonSchema/Iterator/ObjectIterator.php b/src/JsonSchema/Iterator/ObjectIterator.php index 12dd1c11..97edf43b 100644 --- a/src/JsonSchema/Iterator/ObjectIterator.php +++ b/src/JsonSchema/Iterator/ObjectIterator.php @@ -23,7 +23,7 @@ class ObjectIterator implements \Iterator, \Countable private $position = 0; /** @var array */ - private $data = array(); + private $data = []; /** @var bool */ private $initialized = false; @@ -113,7 +113,7 @@ private function initialize() */ private function buildDataFromObject($object) { - $result = array(); + $result = []; $stack = new \SplStack(); $stack->push($object); @@ -142,7 +142,7 @@ private function buildDataFromObject($object) private function getDataFromItem($item) { if (!is_object($item) && !is_array($item)) { - return array(); + return []; } return is_object($item) ? get_object_vars($item) : $item; diff --git a/src/JsonSchema/SchemaStorage.php b/src/JsonSchema/SchemaStorage.php index 4e407413..69b8b061 100644 --- a/src/JsonSchema/SchemaStorage.php +++ b/src/JsonSchema/SchemaStorage.php @@ -14,7 +14,7 @@ class SchemaStorage implements SchemaStorageInterface protected $uriRetriever; protected $uriResolver; - protected $schemas = array(); + protected $schemas = []; public function __construct( ?UriRetrieverInterface $uriRetriever = null, @@ -121,7 +121,7 @@ public function getSchema($id) /** * {@inheritdoc} */ - public function resolveRef($ref, $resolveStack = array()) + public function resolveRef($ref, $resolveStack = []) { $jsonPointer = new JsonPointer($ref); @@ -156,7 +156,7 @@ public function resolveRef($ref, $resolveStack = array()) /** * {@inheritdoc} */ - public function resolveRefSchema($refSchema, $resolveStack = array()) + public function resolveRefSchema($refSchema, $resolveStack = []) { if (is_object($refSchema) && property_exists($refSchema, '$ref') && is_string($refSchema->{'$ref'})) { if (in_array($refSchema, $resolveStack, true)) { diff --git a/src/JsonSchema/Uri/Retrievers/Curl.php b/src/JsonSchema/Uri/Retrievers/Curl.php index 81c86037..844ca1e4 100644 --- a/src/JsonSchema/Uri/Retrievers/Curl.php +++ b/src/JsonSchema/Uri/Retrievers/Curl.php @@ -41,7 +41,7 @@ public function retrieve($uri) curl_setopt($ch, CURLOPT_URL, $uri); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: ' . Validator::SCHEMA_MEDIA_TYPE)); + curl_setopt($ch, CURLOPT_HTTPHEADER, ['Accept: ' . Validator::SCHEMA_MEDIA_TYPE]); $response = curl_exec($ch); if (false === $response) { diff --git a/src/JsonSchema/Uri/UriResolver.php b/src/JsonSchema/Uri/UriResolver.php index 9785146d..3ba66e51 100644 --- a/src/JsonSchema/Uri/UriResolver.php +++ b/src/JsonSchema/Uri/UriResolver.php @@ -30,13 +30,13 @@ public function parse($uri) { preg_match('|^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?|', (string) $uri, $match); - $components = array(); + $components = []; if (5 < count($match)) { - $components = array( + $components = [ 'scheme' => $match[2], 'authority' => $match[4], 'path' => $match[5] - ); + ]; } if (7 < count($match)) { $components['query'] = $match[7]; diff --git a/src/JsonSchema/Uri/UriRetriever.php b/src/JsonSchema/Uri/UriRetriever.php index ab08e8a3..793e0ea3 100644 --- a/src/JsonSchema/Uri/UriRetriever.php +++ b/src/JsonSchema/Uri/UriRetriever.php @@ -27,18 +27,18 @@ class UriRetriever implements BaseUriRetrieverInterface /** * @var array Map of URL translations */ - protected $translationMap = array( + protected $translationMap = [ // use local copies of the spec schemas '|^https?://json-schema.org/draft-(0[34])/schema#?|' => 'package://dist/schema/json-schema-draft-$1.json' - ); + ]; /** * @var array A list of endpoints for media type check exclusion */ - protected $allowedInvalidContentTypeEndpoints = array( + protected $allowedInvalidContentTypeEndpoints = [ 'http://json-schema.org/', 'https://json-schema.org/' - ); + ]; /** * @var null|UriRetrieverInterface @@ -50,7 +50,7 @@ class UriRetriever implements BaseUriRetrieverInterface * * @see loadSchema */ - private $schemaCache = array(); + private $schemaCache = []; /** * Adds an endpoint to the media type validation exclusion list @@ -79,7 +79,7 @@ public function confirmMediaType($uriRetriever, $uri) return; } - if (in_array($contentType, array(Validator::SCHEMA_MEDIA_TYPE, 'application/json'))) { + if (in_array($contentType, [Validator::SCHEMA_MEDIA_TYPE, 'application/json'])) { return; } @@ -243,13 +243,13 @@ public function parse($uri) { preg_match('|^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?|', $uri, $match); - $components = array(); + $components = []; if (5 < count($match)) { - $components = array( + $components = [ 'scheme' => $match[2], 'authority' => $match[4], 'path' => $match[5] - ); + ]; } if (7 < count($match)) { diff --git a/tests/Constraints/AdditionalPropertiesTest.php b/tests/Constraints/AdditionalPropertiesTest.php index e064312d..d5db24fb 100644 --- a/tests/Constraints/AdditionalPropertiesTest.php +++ b/tests/Constraints/AdditionalPropertiesTest.php @@ -17,8 +17,8 @@ class AdditionalPropertiesTest extends BaseTestCase public function getInvalidTests() { - return array( - array( + return [ + [ '{ "prop":"1", "patternProp":"3", @@ -35,22 +35,22 @@ public function getInvalidTests() "additionalProperties": false }', null, - array( - array( + [ + [ 'property' => '', 'pointer' => '', 'message' => 'The property additionalProp is not defined and the definition does not allow additional properties', - 'constraint' => array( + 'constraint' => [ 'name' => 'additionalProp', - 'params' => array( + 'params' => [ 'property' => 'additionalProp' - ) - ), + ] + ], 'context' => Validator::ERROR_DOCUMENT_VALIDATION - ) - ) - ), - array( + ] + ] + ], + [ '{ "prop":"1", "additionalProp":"2" @@ -62,8 +62,8 @@ public function getInvalidTests() }, "additionalProperties": false }' - ), - array( + ], + [ '{ "prop":"1", "additionalProp":2 @@ -75,8 +75,8 @@ public function getInvalidTests() }, "additionalProperties": {"type":"string"} }' - ), - array( + ], + [ '{ "prop":"1", "additionalProp":2 @@ -88,8 +88,8 @@ public function getInvalidTests() }, "additionalProperties": {"type":"string"} }' - ), - array( + ], + [ '{ "prop1": "a", "prop2": "b" @@ -100,8 +100,8 @@ public function getInvalidTests() "type": "boolean" } }' - ), - array( + ], + [ '{ "prop1": "a", "prop2": "b" @@ -110,14 +110,14 @@ public function getInvalidTests() "type": "object", "additionalProperties": false }' - ), - ); + ], + ]; } public function getValidTests() { - return array( - array( + return [ + [ '{ "prop":"1", "additionalProp":"2" @@ -128,8 +128,8 @@ public function getValidTests() "prop":{"type":"string"} } }' - ), - array( + ], + [ '{ "prop":"1", "additionalProp":"2" @@ -140,8 +140,8 @@ public function getValidTests() "prop":{"type":"string"} } }' - ), - array( + ], + [ '{ "prop":"1", "additionalProp":"2" @@ -153,8 +153,8 @@ public function getValidTests() }, "additionalProperties": {"type":"string"} }' - ), - array( + ], + [ '{ "prop":"1", "additionalProp":[] @@ -166,8 +166,8 @@ public function getValidTests() }, "additionalProperties": true }' - ), - array( + ], + [ '{ "prop1": "a", "prop2": "b" @@ -178,8 +178,8 @@ public function getValidTests() "type": "string" } }' - ), - array( + ], + [ '{ "prop1": "a", "prop2": "b" @@ -188,7 +188,7 @@ public function getValidTests() "type": "object", "additionalProperties": true }' - ), - ); + ], + ]; } } diff --git a/tests/Constraints/ArraysTest.php b/tests/Constraints/ArraysTest.php index 63b97bf1..1d4d08bd 100644 --- a/tests/Constraints/ArraysTest.php +++ b/tests/Constraints/ArraysTest.php @@ -15,8 +15,8 @@ class ArraysTest extends BaseTestCase public function getInvalidTests() { - return array( - array( + return [ + [ '{ "array":[1,2,"a"] }', @@ -29,8 +29,8 @@ public function getInvalidTests() } } }' - ), - array( + ], + [ '{ "array":[1,2,"a"] }', @@ -44,8 +44,8 @@ public function getInvalidTests() } } }' - ), - array( + ], + [ '{ "array":[1,2,null] }', @@ -58,8 +58,8 @@ public function getInvalidTests() } } }' - ), - array( + ], + [ '{"data": [1, 2, 3, "foo"]}', '{ "type": "object", @@ -71,8 +71,8 @@ public function getInvalidTests() } } }' - ), - array( // Test array items.enum where type string fail validation if value(s) is/are not in items.enum + ], + [ // Test array items.enum where type string fail validation if value(s) is/are not in items.enum '{"data": ["a", "b"]}', '{ "type": "object", @@ -86,8 +86,8 @@ public function getInvalidTests() } } }' - ), - array( // Test array items.enum where type integer fail validation if value(s) is/are not in items.enum + ], + [ // Test array items.enum where type integer fail validation if value(s) is/are not in items.enum '{"data": [1, 2]}', '{ "type": "object", @@ -101,8 +101,8 @@ public function getInvalidTests() } } }' - ), - array( // Test array items.enum where type number fail validation if value(s) is/are not in items.enum + ], + [ // 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", @@ -116,14 +116,14 @@ public function getInvalidTests() } } }' - ) - ); + ] + ]; } public function getValidTests() { - return array( - array( + return [ + [ '{ "array":[1,2,"a"] }', @@ -133,8 +133,8 @@ public function getValidTests() "array":{"type":"array"} } }' - ), - array( + ], + [ '{ "array":[1,2,"a"] }', @@ -148,8 +148,8 @@ public function getValidTests() } } }' - ), - array( + ], + [ '{"data": [1, 2, 3, 4]}', '{ "type": "object", @@ -161,8 +161,8 @@ public function getValidTests() } } }' - ), - array( + ], + [ '{"data": [1, "foo", false]}', '{ "type": "object", @@ -173,8 +173,8 @@ public function getValidTests() } } }' - ), - array( + ], + [ '{"data": [1, "foo", false]}', '{ "type": "object", @@ -185,8 +185,8 @@ public function getValidTests() } } }' - ), - array( + ], + [ '{"data": [1, 2, 3, 4, 5]}', '{ "type": "object", @@ -197,8 +197,8 @@ public function getValidTests() } } }' - ), - array( // test more schema items than array items + ], + [ // test more schema items than array items '{"data": [1, 2]}', '{ "type": "object", @@ -213,8 +213,8 @@ public function getValidTests() } } }' - ), - array( // Test array items.enum where type string passes validation if value(s) is/are in items.enum + ], + [ // Test array items.enum where type string passes validation if value(s) is/are in items.enum '{"data": ["c", "c", "b"]}', '{ "type": "object", @@ -228,8 +228,8 @@ public function getValidTests() } } }' - ), - array( // Test array items.enum where type integer passes validation if value(s) is/are in items.enum + ], + [ // Test array items.enum where type integer passes validation if value(s) is/are in items.enum '{"data": [1, 1, 2]}', '{ "type": "object", @@ -243,8 +243,8 @@ public function getValidTests() } } }' - ), - array( // Test array items.enum where type number passes validation if value(s) is/are in items.enum + ], + [ // 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", @@ -258,7 +258,7 @@ public function getValidTests() } } }' - ) - ); + ] + ]; } } diff --git a/tests/Constraints/BaseTestCase.php b/tests/Constraints/BaseTestCase.php index 50efbd82..21972c58 100644 --- a/tests/Constraints/BaseTestCase.php +++ b/tests/Constraints/BaseTestCase.php @@ -26,7 +26,7 @@ abstract class BaseTestCase extends VeryBaseTestCase /** * @dataProvider getInvalidTests */ - public function testInvalidCases($input, $schema, $checkMode = Constraint::CHECK_MODE_NORMAL, $errors = array()) + public function testInvalidCases($input, $schema, $checkMode = Constraint::CHECK_MODE_NORMAL, $errors = []) { $checkMode = $checkMode === null ? Constraint::CHECK_MODE_NORMAL : $checkMode; if ($this->validateSchema) { @@ -46,7 +46,7 @@ public function testInvalidCases($input, $schema, $checkMode = Constraint::CHECK $this->assertTrue((bool) ($errorMask & Validator::ERROR_DOCUMENT_VALIDATION)); $this->assertGreaterThan(0, $validator->numErrors()); - if (array() !== $errors) { + if ([] !== $errors) { $this->assertEquals($errors, $validator->getErrors(), print_r($validator->getErrors(), true)); } $this->assertFalse($validator->isValid(), print_r($validator->getErrors(), true)); @@ -55,7 +55,7 @@ public function testInvalidCases($input, $schema, $checkMode = Constraint::CHECK /** * @dataProvider getInvalidForAssocTests */ - public function testInvalidCasesUsingAssoc($input, $schema, $checkMode = Constraint::CHECK_MODE_TYPE_CAST, $errors = array()) + public function testInvalidCasesUsingAssoc($input, $schema, $checkMode = Constraint::CHECK_MODE_TYPE_CAST, $errors = []) { $checkMode = $checkMode === null ? Constraint::CHECK_MODE_TYPE_CAST : $checkMode; if ($this->validateSchema) { @@ -78,7 +78,7 @@ public function testInvalidCasesUsingAssoc($input, $schema, $checkMode = Constra $this->assertTrue((bool) ($errorMask & Validator::ERROR_DOCUMENT_VALIDATION)); $this->assertGreaterThan(0, $validator->numErrors()); - if (array() !== $errors) { + if ([] !== $errors) { $this->assertEquals($errors, $validator->getErrors(), print_r($validator->getErrors(), true)); } $this->assertFalse($validator->isValid(), print_r($validator->getErrors(), true)); diff --git a/tests/Constraints/BasicTypesTest.php b/tests/Constraints/BasicTypesTest.php index 0e88ef42..c238dba3 100644 --- a/tests/Constraints/BasicTypesTest.php +++ b/tests/Constraints/BasicTypesTest.php @@ -16,8 +16,8 @@ class BasicTypesTest extends BaseTestCase public function getInvalidTests() { - return array( - array( + return [ + [ '{ "string":null }', @@ -28,8 +28,8 @@ public function getInvalidTests() }, "additionalProperties":false }' - ), - array( + ], + [ '{ "number":null }', @@ -40,8 +40,8 @@ public function getInvalidTests() }, "additionalProperties":false }' - ), - array( + ], + [ '{ "integer":null }', @@ -52,8 +52,8 @@ public function getInvalidTests() }, "additionalProperties":false }' - ), - array( + ], + [ '{ "boolean":null }', @@ -64,8 +64,8 @@ public function getInvalidTests() }, "additionalProperties":false }' - ), - array( + ], + [ '{ "object":null }', @@ -76,8 +76,8 @@ public function getInvalidTests() }, "additionalProperties":false }' - ), - array( + ], + [ '{ "array":null }', @@ -88,8 +88,8 @@ public function getInvalidTests() }, "additionalProperties":false }' - ), - array( + ], + [ '{ "null":1 }', @@ -100,14 +100,14 @@ public function getInvalidTests() }, "additionalProperties":false }' - ) - ); + ] + ]; } public function getValidTests() { - return array( - array( + return [ + [ '{ "string":"string test", "number":1, @@ -144,7 +144,7 @@ public function getValidTests() }, "additionalProperties":false }' - ) - ); + ] + ]; } } diff --git a/tests/Constraints/CoerciveTest.php b/tests/Constraints/CoerciveTest.php index 3c08d384..1f8670cf 100644 --- a/tests/Constraints/CoerciveTest.php +++ b/tests/Constraints/CoerciveTest.php @@ -27,162 +27,162 @@ public function setUp(): void public function dataCoerceCases() { // check type conversions - $types = array( + $types = [ // toType - 'string' => array( + 'string' => [ // fromType fromValue toValue valid Test Number - array('string', '"ABC"', 'ABC', true), // #0 - array('integer', '45', '45', true), // #1 - array('boolean', 'true', 'true', true), // #2 - array('boolean', 'false', 'false', true), // #3 - array('NULL', 'null', '', true), // #4 - array('array', '[45]', '45', true), // #5 - array('object', '{"a":"b"}', null, false), // #6 - array('array', '[{"a":"b"}]', null, false), // #7 - array('array', '[1,2]', array(1, 2), false), // #8 - ), - 'integer' => array( - array('string', '"45"', 45, true), // #9 - array('integer', '45', 45, true), // #10 - array('boolean', 'true', 1, true), // #11 - array('boolean', 'false', 0, true), // #12 - array('NULL', 'null', 0, true), // #13 - array('array', '["-45"]', -45, true), // #14 - array('object', '{"a":"b"}', null, false), // #15 - array('array', '["ABC"]', null, false), // #16 - ), - 'boolean' => array( - array('string', '"true"', true, true), // #17 - array('integer', '1', true, true), // #18 - array('boolean', 'true', true, true), // #19 - array('NULL', 'null', false, true), // #20 - array('array', '["true"]', true, true), // #21 - array('object', '{"a":"b"}', null, false), // #22 - array('string', '""', null, false), // #23 - array('string', '"ABC"', null, false), // #24 - array('integer', '2', null, false), // #25 - ), - 'NULL' => array( - array('string', '""', null, true), // #26 - array('integer', '0', null, true), // #27 - array('boolean', 'false', null, true), // #28 - array('NULL', 'null', null, true), // #29 - array('array', '[0]', null, true), // #30 - array('object', '{"a":"b"}', null, false), // #31 - array('string', '"null"', null, false), // #32 - array('integer', '-1', null, false), // #33 - ), - 'array' => array( - array('string', '"ABC"', array('ABC'), true), // #34 - array('integer', '45', array(45), true), // #35 - array('boolean', 'true', array(true), true), // #36 - array('NULL', 'null', array(null), true), // #37 - array('array', '["ABC"]', array('ABC'), true), // #38 - array('object', '{"a":"b"}', null, false), // #39 - ), - ); + ['string', '"ABC"', 'ABC', true], // #0 + ['integer', '45', '45', true], // #1 + ['boolean', 'true', 'true', true], // #2 + ['boolean', 'false', 'false', true], // #3 + ['NULL', 'null', '', true], // #4 + ['array', '[45]', '45', true], // #5 + ['object', '{"a":"b"}', null, false], // #6 + ['array', '[{"a":"b"}]', null, false], // #7 + ['array', '[1,2]', [1, 2], false], // #8 + ], + 'integer' => [ + ['string', '"45"', 45, true], // #9 + ['integer', '45', 45, true], // #10 + ['boolean', 'true', 1, true], // #11 + ['boolean', 'false', 0, true], // #12 + ['NULL', 'null', 0, true], // #13 + ['array', '["-45"]', -45, true], // #14 + ['object', '{"a":"b"}', null, false], // #15 + ['array', '["ABC"]', null, false], // #16 + ], + 'boolean' => [ + ['string', '"true"', true, true], // #17 + ['integer', '1', true, true], // #18 + ['boolean', 'true', true, true], // #19 + ['NULL', 'null', false, true], // #20 + ['array', '["true"]', true, true], // #21 + ['object', '{"a":"b"}', null, false], // #22 + ['string', '""', null, false], // #23 + ['string', '"ABC"', null, false], // #24 + ['integer', '2', null, false], // #25 + ], + 'NULL' => [ + ['string', '""', null, true], // #26 + ['integer', '0', null, true], // #27 + ['boolean', 'false', null, true], // #28 + ['NULL', 'null', null, true], // #29 + ['array', '[0]', null, true], // #30 + ['object', '{"a":"b"}', null, false], // #31 + ['string', '"null"', null, false], // #32 + ['integer', '-1', null, false], // #33 + ], + 'array' => [ + ['string', '"ABC"', ['ABC'], true], // #34 + ['integer', '45', [45], true], // #35 + ['boolean', 'true', [true], true], // #36 + ['NULL', 'null', [null], true], // #37 + ['array', '["ABC"]', ['ABC'], true], // #38 + ['object', '{"a":"b"}', null, false], // #39 + ], + ]; // #40 check multiple types (first valid) - $tests[] = array( + $tests[] = [ '{"properties":{"propertyOne":{"type":["number", "string"]}}}', '{"propertyOne":42}', 'integer', 'integer', 42, true - ); + ]; // #41 check multiple types (last valid) - $tests[] = array( + $tests[] = [ '{"properties":{"propertyOne":{"type":["number", "string"]}}}', '{"propertyOne":"42"}', 'string', 'string', '42', true - ); + ]; // #42 check the meaning of life - $tests[] = array( + $tests[] = [ '{"properties":{"propertyOne":{"type":"any"}}}', '{"propertyOne":"42"}', 'string', 'string', '42', true - ); + ]; // #43 check turple coercion - $tests[] = array( + $tests[] = [ '{"properties":{"propertyOne":{"type":"array","items":[{"type":"number"},{"type":"string"}]}}}', '{"propertyOne":["42", 42]}', - 'array', 'array', array(42, '42'), true - ); + 'array', 'array', [42, '42'], true + ]; // #44 check early coercion - $tests[] = array( + $tests[] = [ '{"properties":{"propertyOne":{"type":["object", "number", "string"]}}}', '{"propertyOne":"42"}', 'string', 'integer', 42, true, Constraint::CHECK_MODE_EARLY_COERCE - ); + ]; // #45 check multiple types (none valid) - $tests[] = array( + $tests[] = [ '{"properties":{"propertyOne":{"type":["number", "boolean"]}}}', '{"propertyOne":"42"}', 'string', 'integer', 42, true - ); + ]; // #46 check coercion with "const" - $tests[] = array( + $tests[] = [ '{"properties":{"propertyOne":{"type":"string","const":"42"}}}', '{"propertyOne":42}', 'integer', 'string', '42', true - ); + ]; // #47 check coercion with "const" - $tests[] = array( + $tests[] = [ '{"properties":{"propertyOne":{"type":"number","const":42}}}', '{"propertyOne":"42"}', 'string', 'integer', 42, true - ); + ]; // #48 check boolean coercion with "const" - $tests[] = array( + $tests[] = [ '{"properties":{"propertyOne":{"type":"boolean","const":false}}}', '{"propertyOne":"false"}', 'string', 'boolean', false, true - ); + ]; // #49 check boolean coercion with "const" - $tests[] = array( + $tests[] = [ '{"properties":{"propertyOne":{"type":"boolean","const":true}}}', '{"propertyOne":"true"}', 'string', 'boolean', true, true - ); + ]; // #50 check boolean coercion with "const" - $tests[] = array( + $tests[] = [ '{"properties":{"propertyOne":{"type":"boolean","const":true}}}', '{"propertyOne":1}', 'integer', 'boolean', true, true - ); + ]; // #51 check boolean coercion with "const" - $tests[] = array( + $tests[] = [ '{"properties":{"propertyOne":{"type":"boolean","const":false}}}', '{"propertyOne":"false"}', 'string', 'boolean', false, true - ); + ]; // #52 check post-coercion validation (to array) - $tests[] = array( + $tests[] = [ '{"properties":{"propertyOne":{"type":"array","items":[{"type":"number"}]}}}', '{"propertyOne":"ABC"}', 'string', null, null, false - ); + ]; foreach ($types as $toType => $testCases) { foreach ($testCases as $testCase) { - $tests[] = array( + $tests[] = [ sprintf('{"properties":{"propertyOne":{"type":"%s"}}}', strtolower($toType)), sprintf('{"propertyOne":%s}', $testCase[1]), $testCase[0], $toType, $testCase[2], $testCase[3] - ); + ]; } } diff --git a/tests/Constraints/ConstTest.php b/tests/Constraints/ConstTest.php index e694c6f1..bcd8b966 100644 --- a/tests/Constraints/ConstTest.php +++ b/tests/Constraints/ConstTest.php @@ -16,8 +16,8 @@ class ConstTest extends BaseTestCase public function getInvalidTests() { - return array( - array( + return [ + [ '{"value":"foo"}', '{ "type":"object", @@ -26,8 +26,8 @@ public function getInvalidTests() }, "additionalProperties":false }' - ), - array( + ], + [ '{"value":5}', '{ "type":"object", @@ -36,8 +36,8 @@ public function getInvalidTests() }, "additionalProperties":false }' - ), - array( + ], + [ '{"value":false}', '{ "type":"object", @@ -46,8 +46,8 @@ public function getInvalidTests() }, "additionalProperties":false }' - ), - array( + ], + [ '{ "value": { "foo": "12" @@ -64,14 +64,14 @@ public function getInvalidTests() } } }' - ) - ); + ] + ]; } public function getValidTests() { - return array( - array( + return [ + [ '{"value":"bar"}', '{ "type":"object", @@ -80,8 +80,8 @@ public function getValidTests() }, "additionalProperties":false }' - ), - array( + ], + [ '{"value":false}', '{ "type":"object", @@ -90,8 +90,8 @@ public function getValidTests() }, "additionalProperties":false }' - ), - array( + ], + [ '{"value":true}', '{ "type":"object", @@ -100,8 +100,8 @@ public function getValidTests() }, "additionalProperties":false }' - ), - array( + ], + [ '{"value":5}', '{ "type":"object", @@ -110,8 +110,8 @@ public function getValidTests() }, "additionalProperties":false }' - ), - array( + ], + [ '{ "value": { "foo": 12 @@ -128,7 +128,7 @@ public function getValidTests() } } }' - ) - ); + ] + ]; } } diff --git a/tests/Constraints/DefaultPropertiesTest.php b/tests/Constraints/DefaultPropertiesTest.php index cc5eb909..95dde8e9 100644 --- a/tests/Constraints/DefaultPropertiesTest.php +++ b/tests/Constraints/DefaultPropertiesTest.php @@ -18,7 +18,7 @@ class DefaultPropertiesTest extends VeryBaseTestCase { public function getValidTests() { - return array( + return [ /* // This test case was intended to check whether a default value can be applied for the // entire object, however testing this case is impossible, because there is no way to @@ -31,72 +31,72 @@ public function getValidTests() '"valueOne"' ), */ - array(// #0 default value in an empty object + [// #0 default value in an empty object '{}', '{"properties":{"propertyOne":{"default":"valueOne"}}}', '{"propertyOne":"valueOne"}' - ), - array(// #1 default value for top-level property + ], + [// #1 default value for top-level property '{"propertyOne":"valueOne"}', '{"properties":{"propertyTwo":{"default":"valueTwo"}}}', '{"propertyOne":"valueOne","propertyTwo":"valueTwo"}' - ), - array(// #2 default value for sub-property + ], + [// #2 default value for sub-property '{"propertyOne":{}}', '{"properties":{"propertyOne":{"properties":{"propertyTwo":{"default":"valueTwo"}}}}}', '{"propertyOne":{"propertyTwo":"valueTwo"}}' - ), - array(// #3 default value for sub-property with sibling + ], + [// #3 default value for sub-property with sibling '{"propertyOne":{"propertyTwo":"valueTwo"}}', '{"properties":{"propertyOne":{"properties":{"propertyThree":{"default":"valueThree"}}}}}', '{"propertyOne":{"propertyTwo":"valueTwo","propertyThree":"valueThree"}}' - ), - array(// #4 default value for top-level property with type check + ], + [// #4 default value for top-level property with type check '{"propertyOne":"valueOne"}', '{"properties":{"propertyTwo":{"default":"valueTwo","type":"string"}}}', '{"propertyOne":"valueOne","propertyTwo":"valueTwo"}' - ), - array(// #5 default value for top-level property with v3 required check + ], + [// #5 default value for top-level property with v3 required check '{"propertyOne":"valueOne"}', '{"properties":{"propertyTwo":{"default":"valueTwo","required":"true"}}}', '{"propertyOne":"valueOne","propertyTwo":"valueTwo"}' - ), - array(// #6 default value for top-level property with v4 required check + ], + [// #6 default value for top-level property with v4 required check '{"propertyOne":"valueOne"}', '{"properties":{"propertyTwo":{"default":"valueTwo"}},"required":["propertyTwo"]}', '{"propertyOne":"valueOne","propertyTwo":"valueTwo"}' - ), - array(// #7 default value for an already set property + ], + [// #7 default value for an already set property '{"propertyOne":"alreadySetValueOne"}', '{"properties":{"propertyOne":{"default":"valueOne"}}}', '{"propertyOne":"alreadySetValueOne"}' - ), - array(// #8 default item value for an array + ], + [// #8 default item value for an array '["valueOne"]', '{"type":"array","items":[{},{"type":"string","default":"valueTwo"}]}', '["valueOne","valueTwo"]' - ), - array(// #9 default item value for an empty array + ], + [// #9 default item value for an empty array '[]', '{"type":"array","items":[{"type":"string","default":"valueOne"}]}', '["valueOne"]' - ), - array(// #10 property without a default available + ], + [// #10 property without a default available '{"propertyOne":"alreadySetValueOne"}', '{"properties":{"propertyOne":{"type":"string"}}}', '{"propertyOne":"alreadySetValueOne"}' - ), - array(// #11 default property value is an object + ], + [// #11 default property value is an object '{"propertyOne":"valueOne"}', '{"properties":{"propertyTwo":{"default":{}}}}', '{"propertyOne":"valueOne","propertyTwo":{}}' - ), - array(// #12 default item value is an object + ], + [// #12 default item value is an object '[]', '{"type":"array","items":[{"default":{}}]}', '[{}]' - ), - array(// #13 only set required values (draft-04) + ], + [// #13 only set required values (draft-04) '{}', '{ "properties": { @@ -107,8 +107,8 @@ public function getValidTests() }', '{"propertyTwo":"valueTwo"}', Constraint::CHECK_MODE_ONLY_REQUIRED_DEFAULTS - ), - array(// #14 only set required values (draft-03) + ], + [// #14 only set required values (draft-03) '{}', '{ "properties": { @@ -118,53 +118,53 @@ public function getValidTests() }', '{"propertyTwo":"valueTwo"}', Constraint::CHECK_MODE_ONLY_REQUIRED_DEFAULTS - ), - array(// #15 infinite recursion via $ref (object) + ], + [// #15 infinite recursion via $ref (object) '{}', '{"properties":{"propertyOne": {"$ref": "#","default": "valueOne"}}, "default": {}}', '{"propertyOne":{}}' - ), - array(// #16 infinite recursion via $ref (array) + ], + [// #16 infinite recursion via $ref (array) '[]', '{"items":[{"$ref":"#","default":"valueOne"}], "default": []}', '[[]]' - ), - array(// #17 default top value does not overwrite defined null + ], + [// #17 default top value does not overwrite defined null 'null', '{"default":"valueOne"}', 'null' - ), - array(// #18 default property value does not overwrite defined null + ], + [// #18 default property value does not overwrite defined null '{"propertyOne":null}', '{"properties":{"propertyOne":{"default":"valueOne"}}}', '{"propertyOne":null}' - ), - array(// #19 default value in an object is null + ], + [// #19 default value in an object is null '{}', '{"properties":{"propertyOne":{"default":null}}}', '{"propertyOne":null}' - ), - array(// #20 default value in an array is null + ], + [// #20 default value in an array is null '[]', '{"items":[{"default":null}]}', '[null]' - ), - array(// #21 items might be a schema (instead of an array of schema) + ], + [// #21 items might be a schema (instead of an array of schema) '[{}]', '{"items":{"properties":{"propertyOne":{"default":"valueOne"}}}}', '[{"propertyOne":"valueOne"}]' - ), - array(// #22 if items is not an array, it does not create a new item + ], + [// #22 if items is not an array, it does not create a new item '[]', '{"items":{"properties":{"propertyOne":{"default":"valueOne"}}}}', '[]' - ), - array(// #23 if items is a schema with a default value and minItems is present, fill the array + ], + [// #23 if items is a schema with a default value and minItems is present, fill the array '["a"]', '{"items":{"default":"b"}, "minItems": 3}', '["a","b","b"]' - ), - ); + ], + ]; } /** diff --git a/tests/Constraints/DependenciesTest.php b/tests/Constraints/DependenciesTest.php index f7f9d532..38483f88 100644 --- a/tests/Constraints/DependenciesTest.php +++ b/tests/Constraints/DependenciesTest.php @@ -16,26 +16,26 @@ class DependenciesTest extends BaseTestCase public function getInvalidTests() { - return array( - array( + return [ + [ '{"bar": 1}', '{ "dependencies": {"bar": "foo"} }' - ), - array( + ], + [ '{"bar": 1}', '{ "dependencies": {"bar": ["foo"]} }' - ), - array( + ], + [ '{"bar": 1, "foo": 1}', '{ "dependencies": {"bar": ["foo", "baz"]} }' - ), - array( + ], + [ '{"bar": 1, "foo": 1}', '{ "dependencies": {"bar": { @@ -44,8 +44,8 @@ public function getInvalidTests() } }} }' - ), - array( + ], + [ '{"bar": 1}', '{ "dependencies": {"bar": { @@ -54,8 +54,8 @@ public function getInvalidTests() } }} }' - ), - array( + ], + [ '{"bar": 1}', '{ "dependencies": {"bar": { @@ -65,8 +65,8 @@ public function getInvalidTests() "required": ["foo"] }} }' - ), - array( + ], + [ '{"bar": true, "foo": "ick"}', '{ "dependencies": {"bar": { @@ -76,56 +76,56 @@ public function getInvalidTests() } }} }' - ) - ); + ] + ]; } public function getValidTests() { - return array( - array( + return [ + [ '{}', '{ "dependencies": {"bar": "foo"} }' - ), - array( + ], + [ '{"foo": 1}', '{ "dependencies": {"bar": "foo"} }' - ), - array( + ], + [ '"foo"', '{ "dependencies": {"bar": "foo"} }' - ), - array( + ], + [ '{"bar": 1, "foo": 1}', '{ "dependencies": {"bar": "foo"} }' - ), - array( + ], + [ '{"bar": 1, "foo": 1, "baz": 1}', '{ "dependencies": {"bar": ["foo", "baz"]} }' - ), - array( + ], + [ '{}', '{ "dependencies": {"bar": ["foo", "baz"]} }' - ), - array( + ], + [ '{"foo": 1, "baz": 1}', '{ "dependencies": {"bar": ["foo", "baz"]} }' - ), - array( + ], + [ '{"bar": 1}', '{ "dependencies": {"bar": { @@ -134,8 +134,8 @@ public function getValidTests() } }} }' - ), - array( + ], + [ '{"bar": 1, "foo": 1}', '{ "dependencies": {"bar": { @@ -145,7 +145,7 @@ public function getValidTests() } }} }' - ) - ); + ] + ]; } } diff --git a/tests/Constraints/DisallowTest.php b/tests/Constraints/DisallowTest.php index f00d2fab..6a61dcea 100644 --- a/tests/Constraints/DisallowTest.php +++ b/tests/Constraints/DisallowTest.php @@ -21,8 +21,8 @@ class DisallowTest extends BaseTestCase public function getInvalidTests() { - return array( - array( + return [ + [ '{ "value":"The xpto is weird" }', @@ -35,8 +35,8 @@ public function getInvalidTests() } } }' - ), - array( + ], + [ '{ "value":null }', @@ -49,8 +49,8 @@ public function getInvalidTests() } } }' - ), - array( + ], + [ '{"value": 1}', '{ "type": "object", @@ -58,8 +58,8 @@ public function getInvalidTests() "value": {"type": "any", "disallow": "integer"} } }' - ), - array( + ], + [ '{"value": true}', '{ "type": "object", @@ -67,8 +67,8 @@ public function getInvalidTests() "value": {"type": "any", "disallow": ["integer", "boolean"]} } }' - ), - array( + ], + [ '{"value": "foo"}', '{ "type": "object", @@ -85,8 +85,8 @@ public function getInvalidTests() } } }' - ), - array( + ], + [ '{"value": {"foo": "bar"}}', '{ "type": "object", @@ -103,14 +103,14 @@ public function getInvalidTests() } } }' - ) - ); + ] + ]; } public function getValidTests() { - return array( - array( + return [ + [ '{ "value":"The xpto is weird" }', @@ -123,8 +123,8 @@ public function getValidTests() } } }' - ), - array( + ], + [ '{ "value":1 }', @@ -137,8 +137,8 @@ public function getValidTests() } } }' - ), - array( + ], + [ '{"value": {"foo": 1}}', '{ "type": "object", @@ -155,8 +155,8 @@ public function getValidTests() } } }' - ), - array( + ], + [ '{"value": true}', '{ "type": "object", @@ -164,7 +164,7 @@ public function getValidTests() "value": {"type": "any", "disallow": "string"} } }' - ) - ); + ] + ]; } } diff --git a/tests/Constraints/DivisibleByTest.php b/tests/Constraints/DivisibleByTest.php index b88a87a1..e08e2b9d 100644 --- a/tests/Constraints/DivisibleByTest.php +++ b/tests/Constraints/DivisibleByTest.php @@ -15,8 +15,8 @@ class DivisibleByTest extends BaseTestCase public function getInvalidTests() { - return array( - array( + return [ + [ '{"value": 5.6333}', '{ "type":"object", @@ -24,8 +24,8 @@ public function getInvalidTests() "value":{"type":"number","divisibleBy":3} } }' - ), - array( + ], + [ '{"value": 35}', '{ "type": "object", @@ -33,8 +33,8 @@ public function getInvalidTests() "value": {"type": "integer", "divisibleBy": 1.5} } }' - ), - array( + ], + [ '{"value": 0.00751}', '{ "type": "object", @@ -42,8 +42,8 @@ public function getInvalidTests() "value": {"type": "number", "divisibleBy": 0.0001} } }' - ), - array( + ], + [ '{"value": 7}', '{ "type": "object", @@ -51,14 +51,14 @@ public function getInvalidTests() "value": {"type": "integer", "divisibleBy": 2} } }' - ) - ); + ] + ]; } public function getValidTests() { - return array( - array( + return [ + [ '{"value": 6}', '{ "type":"object", @@ -66,8 +66,8 @@ public function getValidTests() "value":{"type":"number","divisibleBy":3} } }' - ), - array( + ], + [ '{"value": 4.5}', '{ "type": "object", @@ -75,23 +75,23 @@ public function getValidTests() "value": {"type": "number", "divisibleBy": 1.5} } }' - ), - array( + ], + [ '{"value": 0.0075}', '{ "properties": { "value": {"type": "number", "divisibleBy": 0.0001} } }' - ), - array( + ], + [ '{"value": 1}', '{ "properties": { "value": {"type": "number", "divisibleBy": 0.02} } }' - ) - ); + ] + ]; } } diff --git a/tests/Constraints/EnumTest.php b/tests/Constraints/EnumTest.php index 25830b3a..8b7a7d51 100644 --- a/tests/Constraints/EnumTest.php +++ b/tests/Constraints/EnumTest.php @@ -16,8 +16,8 @@ class EnumTest extends BaseTestCase public function getInvalidTests() { - return array( - array( + return [ + [ '{ "value":"Morango" }', @@ -28,8 +28,8 @@ public function getInvalidTests() }, "additionalProperties":false }' - ), - array( + ], + [ '{}', '{ "type":"object", @@ -42,8 +42,8 @@ public function getInvalidTests() }, "additionalProperties":false }' - ), - array( + ], + [ '{"value": "4"}', '{ "type": "object", @@ -54,8 +54,8 @@ public function getInvalidTests() }, "additionalProperties": false }' - ), - array( + ], + [ '{"value": {"foo": false}}', '{ "type": "object", @@ -66,8 +66,8 @@ public function getInvalidTests() }, "additionalProperties": false }' - ), - array( + ], + [ '{ "value": { "foo": "12" @@ -90,14 +90,14 @@ public function getInvalidTests() } } }' - ) - ); + ] + ]; } public function getValidTests() { - return array( - array( + return [ + [ '{ "value":"Abacate" }', @@ -108,8 +108,8 @@ public function getValidTests() }, "additionalProperties":false }' - ), - array( + ], + [ '{}', '{ "type":"object", @@ -118,8 +118,8 @@ public function getValidTests() }, "additionalProperties":false }' - ), - array( + ], + [ '{}', '{ "type":"object", @@ -132,8 +132,8 @@ public function getValidTests() }, "additionalProperties":false }' - ), - array( + ], + [ '{"value": 1}', '{ "type": "object", @@ -141,8 +141,8 @@ public function getValidTests() "value": {"type": "integer", "enum": [1, 2, 3]} } }' - ), - array( + ], + [ '{"value": []}', '{ "type": "object", @@ -151,8 +151,8 @@ public function getValidTests() }, "additionalProperties": false }' - ), - array( + ], + [ '{ "value": { "foo": 12 @@ -175,7 +175,7 @@ public function getValidTests() } } }' - ) - ); + ] + ]; } } diff --git a/tests/Constraints/ExtendsTest.php b/tests/Constraints/ExtendsTest.php index 5df1fa27..ee53ed84 100644 --- a/tests/Constraints/ExtendsTest.php +++ b/tests/Constraints/ExtendsTest.php @@ -16,8 +16,8 @@ class ExtendsTest extends BaseTestCase public function getInvalidTests() { - return array( - array( + return [ + [ '{ "name":"bruno", "age":50 @@ -36,8 +36,8 @@ public function getInvalidTests() } } }' - ), - array( + ], + [ '{ "name":"bruno", "age":180 @@ -56,8 +56,8 @@ public function getInvalidTests() } } }' - ), - array( + ], + [ '{"foo": 2, "bar": "baz"}', '{ "properties": { @@ -69,8 +69,8 @@ public function getInvalidTests() } } }' - ), - array( + ], + [ '{"bar": 2}', '{ "properties": { @@ -89,14 +89,14 @@ public function getInvalidTests() } ] }' - ) - ); + ] + ]; } public function getValidTests() { - return array( - array( + return [ + [ '{ "name":"bruno", "age":80 @@ -115,8 +115,8 @@ public function getValidTests() } } }' - ), - array( + ], + [ '{"foo": "baz", "bar": 2}', '{ "properties": { @@ -128,8 +128,8 @@ public function getValidTests() } } }' - ), - array( + ], + [ '{"foo": "ick", "bar": 2, "baz": null}', '{ "properties": { @@ -148,7 +148,7 @@ public function getValidTests() } ] }' - ) - ); + ] + ]; } } diff --git a/tests/Constraints/FactoryTest.php b/tests/Constraints/FactoryTest.php index ea65e246..451fa94d 100644 --- a/tests/Constraints/FactoryTest.php +++ b/tests/Constraints/FactoryTest.php @@ -63,19 +63,19 @@ public function testCreateInstanceForConstraintName($constraintName, $expectedCl public function constraintNameProvider() { - return array( - array('array', 'JsonSchema\Constraints\CollectionConstraint'), - array('collection', 'JsonSchema\Constraints\CollectionConstraint'), - array('object', 'JsonSchema\Constraints\ObjectConstraint'), - array('type', 'JsonSchema\Constraints\TypeConstraint'), - array('undefined', 'JsonSchema\Constraints\UndefinedConstraint'), - array('string', 'JsonSchema\Constraints\StringConstraint'), - array('number', 'JsonSchema\Constraints\NumberConstraint'), - array('enum', 'JsonSchema\Constraints\EnumConstraint'), - array('const', 'JsonSchema\Constraints\ConstConstraint'), - array('format', 'JsonSchema\Constraints\FormatConstraint'), - array('schema', 'JsonSchema\Constraints\SchemaConstraint'), - ); + return [ + ['array', 'JsonSchema\Constraints\CollectionConstraint'], + ['collection', 'JsonSchema\Constraints\CollectionConstraint'], + ['object', 'JsonSchema\Constraints\ObjectConstraint'], + ['type', 'JsonSchema\Constraints\TypeConstraint'], + ['undefined', 'JsonSchema\Constraints\UndefinedConstraint'], + ['string', 'JsonSchema\Constraints\StringConstraint'], + ['number', 'JsonSchema\Constraints\NumberConstraint'], + ['enum', 'JsonSchema\Constraints\EnumConstraint'], + ['const', 'JsonSchema\Constraints\ConstConstraint'], + ['format', 'JsonSchema\Constraints\FormatConstraint'], + ['schema', 'JsonSchema\Constraints\SchemaConstraint'], + ]; } /** @@ -91,9 +91,9 @@ public function testExceptionWhenCreateInstanceForInvalidConstraintName($constra public function invalidConstraintNameProvider() { - return array( - array('invalidConstraintName'), - ); + return [ + ['invalidConstraintName'], + ]; } public function testSetConstraintClassExistsCondition() diff --git a/tests/Constraints/FormatTest.php b/tests/Constraints/FormatTest.php index c49b5c68..bb511607 100644 --- a/tests/Constraints/FormatTest.php +++ b/tests/Constraints/FormatTest.php @@ -97,131 +97,131 @@ public function testDisabledFormat($string, $format) public function getValidFormats() { - return array( - array('2001-01-23', 'date'), - array('2000-02-29', 'date'), - - array('12:22:01', 'time'), - array('00:00:00', 'time'), - array('23:59:59', 'time'), - - array('2000-05-01T12:12:12Z', 'date-time'), - array('2000-05-01T12:12:12+0100', 'date-time'), - array('2000-05-01T12:12:12+01:00', 'date-time'), - array('2000-05-01T12:12:12.123456Z', 'date-time'), - array('2000-05-01T12:12:12.123Z', 'date-time'), - array('2000-05-01T12:12:12.123000Z', 'date-time'), - array('2000-05-01T12:12:12.0Z', 'date-time'), - array('2000-05-01T12:12:12.000Z', 'date-time'), - array('2000-05-01T12:12:12.000000Z', 'date-time'), - - array('0', 'utc-millisec'), - - array('aqua', 'color'), - array('black', 'color'), - array('blue', 'color'), - array('fuchsia', 'color'), - array('gray', 'color'), - array('green', 'color'), - array('lime', 'color'), - array('maroon', 'color'), - array('navy', 'color'), - array('olive', 'color'), - array('orange', 'color'), - array('purple', 'color'), - array('red', 'color'), - array('silver', 'color'), - array('teal', 'color'), - array('white', 'color'), - array('yellow', 'color'), - array('#fff', 'color'), - array('#00cc00', 'color'), - - array('background: blue', 'style'), - array('color: #000;', 'style'), - - array('555 320 1212', 'phone'), - - array('http://bluebox.org', 'uri'), - array('//bluebox.org', 'uri-reference'), - array('/absolutePathReference/', 'uri-reference'), - array('./relativePathReference/', 'uri-reference'), - array('./relative:PathReference/', 'uri-reference'), - array('relativePathReference/', 'uri-reference'), - array('relative/Path:Reference/', 'uri-reference'), - - array('info@something.edu', 'email'), - - array('10.10.10.10', 'ip-address'), - array('127.0.0.1', 'ip-address'), - - array('::ff', 'ipv6'), - - array('www.example.com', 'host-name'), - array('3v4l.org', 'host-name'), - array('a-valid-host.com', 'host-name'), - array('localhost', 'host-name'), - - array('anything', '*'), - array('unknown', '*'), - ); + return [ + ['2001-01-23', 'date'], + ['2000-02-29', 'date'], + + ['12:22:01', 'time'], + ['00:00:00', 'time'], + ['23:59:59', 'time'], + + ['2000-05-01T12:12:12Z', 'date-time'], + ['2000-05-01T12:12:12+0100', 'date-time'], + ['2000-05-01T12:12:12+01:00', 'date-time'], + ['2000-05-01T12:12:12.123456Z', 'date-time'], + ['2000-05-01T12:12:12.123Z', 'date-time'], + ['2000-05-01T12:12:12.123000Z', 'date-time'], + ['2000-05-01T12:12:12.0Z', 'date-time'], + ['2000-05-01T12:12:12.000Z', 'date-time'], + ['2000-05-01T12:12:12.000000Z', 'date-time'], + + ['0', 'utc-millisec'], + + ['aqua', 'color'], + ['black', 'color'], + ['blue', 'color'], + ['fuchsia', 'color'], + ['gray', 'color'], + ['green', 'color'], + ['lime', 'color'], + ['maroon', 'color'], + ['navy', 'color'], + ['olive', 'color'], + ['orange', 'color'], + ['purple', 'color'], + ['red', 'color'], + ['silver', 'color'], + ['teal', 'color'], + ['white', 'color'], + ['yellow', 'color'], + ['#fff', 'color'], + ['#00cc00', 'color'], + + ['background: blue', 'style'], + ['color: #000;', 'style'], + + ['555 320 1212', 'phone'], + + ['http://bluebox.org', 'uri'], + ['//bluebox.org', 'uri-reference'], + ['/absolutePathReference/', 'uri-reference'], + ['./relativePathReference/', 'uri-reference'], + ['./relative:PathReference/', 'uri-reference'], + ['relativePathReference/', 'uri-reference'], + ['relative/Path:Reference/', 'uri-reference'], + + ['info@something.edu', 'email'], + + ['10.10.10.10', 'ip-address'], + ['127.0.0.1', 'ip-address'], + + ['::ff', 'ipv6'], + + ['www.example.com', 'host-name'], + ['3v4l.org', 'host-name'], + ['a-valid-host.com', 'host-name'], + ['localhost', 'host-name'], + + ['anything', '*'], + ['unknown', '*'], + ]; } public function getInvalidFormats() { - return array( - array('January 1st, 1910', 'date'), - array('199-01-1', 'date'), - array('2012-0-11', 'date'), - array('2012-10-1', 'date'), + return [ + ['January 1st, 1910', 'date'], + ['199-01-1', 'date'], + ['2012-0-11', 'date'], + ['2012-10-1', 'date'], - array('24:01:00', 'time'), - array('00:00:60', 'time'), - array('25:00:00', 'time'), + ['24:01:00', 'time'], + ['00:00:60', 'time'], + ['25:00:00', 'time'], - array('invalid_value_2000-05-01T12:12:12Z', 'date-time'), - array('2000-05-01T12:12:12Z_invalid_value', 'date-time'), - array('1999-1-11T00:00:00Z', 'date-time'), - array('1999-01-11T00:00:00+100', 'date-time'), - array('1999-01-11T00:00:00+1:00', 'date-time'), - array('1999.000Z-01-11T00:00:00+1:00', 'date-time'), + ['invalid_value_2000-05-01T12:12:12Z', 'date-time'], + ['2000-05-01T12:12:12Z_invalid_value', 'date-time'], + ['1999-1-11T00:00:00Z', 'date-time'], + ['1999-01-11T00:00:00+100', 'date-time'], + ['1999-01-11T00:00:00+1:00', 'date-time'], + ['1999.000Z-01-11T00:00:00+1:00', 'date-time'], - array(PHP_INT_MAX, 'utc-millisec'), + [PHP_INT_MAX, 'utc-millisec'], - array('grey', 'color'), - array('#HHH', 'color'), - array('#000a', 'color'), - array('#aa', 'color'), + ['grey', 'color'], + ['#HHH', 'color'], + ['#000a', 'color'], + ['#aa', 'color'], - array('background; blue', 'style'), + ['background; blue', 'style'], - array('1 123 4424', 'phone'), + ['1 123 4424', 'phone'], - array('htt:/bluebox.org', 'uri'), - array('.relative:path/reference/', 'uri'), - array('', 'uri'), - array('//bluebox.org', 'uri'), - array('/absolutePathReference/', 'uri'), - array('./relativePathReference/', 'uri'), - array('./relative:PathReference/', 'uri'), - array('relativePathReference/', 'uri'), - array('relative/Path:Reference/', 'uri'), + ['htt:/bluebox.org', 'uri'], + ['.relative:path/reference/', 'uri'], + ['', 'uri'], + ['//bluebox.org', 'uri'], + ['/absolutePathReference/', 'uri'], + ['./relativePathReference/', 'uri'], + ['./relative:PathReference/', 'uri'], + ['relativePathReference/', 'uri'], + ['relative/Path:Reference/', 'uri'], - array('info@somewhere', 'email'), + ['info@somewhere', 'email'], - array('256.2.2.2', 'ip-address'), + ['256.2.2.2', 'ip-address'], - array(':::ff', 'ipv6'), + [':::ff', 'ipv6'], - array('@localhost', 'host-name'), - array('..nohost', 'host-name'), - ); + ['@localhost', 'host-name'], + ['..nohost', 'host-name'], + ]; } public function getValidTests() { - return array( - array( + return [ + [ '{ "counter": "10" }', '{ "type": "object", @@ -232,14 +232,14 @@ public function getValidTests() "pattern": "[0-9]+" } } - }'), - ); + }'], + ]; } public function getInvalidTests() { - return array( - array( + return [ + [ '{ "counter": "blue" }', '{ "type": "object", @@ -251,8 +251,8 @@ public function getInvalidTests() } } }' - ), - array( + ], + [ '{ "color": "blueberry" }', '{ "type": "object", @@ -263,7 +263,7 @@ public function getInvalidTests() } } }' - ) - ); + ] + ]; } } diff --git a/tests/Constraints/MinItemsMaxItemsTest.php b/tests/Constraints/MinItemsMaxItemsTest.php index 62fbaa9a..477eb609 100644 --- a/tests/Constraints/MinItemsMaxItemsTest.php +++ b/tests/Constraints/MinItemsMaxItemsTest.php @@ -15,8 +15,8 @@ class MinItemsMaxItemsTest extends BaseTestCase public function getInvalidTests() { - return array( - array( + return [ + [ '{ "value":[2] }', @@ -26,8 +26,8 @@ public function getInvalidTests() "value":{"type":"array","minItems":2,"maxItems":4} } }' - ), - array( + ], + [ '{ "value":[2,2,5,8,5] }', @@ -37,14 +37,14 @@ public function getInvalidTests() "value":{"type":"array","minItems":2,"maxItems":4} } }' - ) - ); + ] + ]; } public function getValidTests() { - return array( - array( + return [ + [ '{ "value":[2,2] }', @@ -54,8 +54,8 @@ public function getValidTests() "value":{"type":"array","minItems":2,"maxItems":4} } }' - ), - array( + ], + [ '{ "value":[2,2,5,8] }', @@ -65,7 +65,7 @@ public function getValidTests() "value":{"type":"array","minItems":2,"maxItems":4} } }' - ) - ); + ] + ]; } } diff --git a/tests/Constraints/MinLengthMaxLengthMultiByteTest.php b/tests/Constraints/MinLengthMaxLengthMultiByteTest.php index 3e7d91e2..2b8b6ca7 100644 --- a/tests/Constraints/MinLengthMaxLengthMultiByteTest.php +++ b/tests/Constraints/MinLengthMaxLengthMultiByteTest.php @@ -22,8 +22,8 @@ protected function setUp(): void public function getInvalidTests() { - return array( - array( + return [ + [ '{ "value":"☀" }', @@ -33,8 +33,8 @@ public function getInvalidTests() "value":{"type":"string","minLength":2,"maxLength":4} } }' - ), - array( + ], + [ '{ "value":"☀☁☂☃☺" }', @@ -44,14 +44,14 @@ public function getInvalidTests() "value":{"type":"string","minLength":2,"maxLength":4} } }' - ) - ); + ] + ]; } public function getValidTests() { - return array( - array( + return [ + [ '{ "value":"☀☁" }', @@ -61,8 +61,8 @@ public function getValidTests() "value":{"type":"string","minLength":2,"maxLength":4} } }' - ), - array( + ], + [ '{ "value":"☀☁☂☃" }', @@ -72,7 +72,7 @@ public function getValidTests() "value":{"type":"string","minLength":2,"maxLength":4} } }' - ) - ); + ] + ]; } } diff --git a/tests/Constraints/MinLengthMaxLengthTest.php b/tests/Constraints/MinLengthMaxLengthTest.php index 8dfa7158..78d27abb 100644 --- a/tests/Constraints/MinLengthMaxLengthTest.php +++ b/tests/Constraints/MinLengthMaxLengthTest.php @@ -15,8 +15,8 @@ class MinLengthMaxLengthTest extends BaseTestCase public function getInvalidTests() { - return array( - array( + return [ + [ '{ "value":"w" }', @@ -26,8 +26,8 @@ public function getInvalidTests() "value":{"type":"string","minLength":2,"maxLength":4} } }' - ), - array( + ], + [ '{ "value":"wo7us" }', @@ -37,14 +37,14 @@ public function getInvalidTests() "value":{"type":"string","minLength":2,"maxLength":4} } }' - ) - ); + ] + ]; } public function getValidTests() { - return array( - array( + return [ + [ '{ "value":"wo" }', @@ -54,8 +54,8 @@ public function getValidTests() "value":{"type":"string","minLength":2,"maxLength":4} } }' - ), - array( + ], + [ '{ "value":"wo7u" }', @@ -65,7 +65,7 @@ public function getValidTests() "value":{"type":"string","minLength":2,"maxLength":4} } }' - ), - ); + ], + ]; } } diff --git a/tests/Constraints/MinMaxPropertiesTest.php b/tests/Constraints/MinMaxPropertiesTest.php index 90774b91..763b80e0 100644 --- a/tests/Constraints/MinMaxPropertiesTest.php +++ b/tests/Constraints/MinMaxPropertiesTest.php @@ -18,8 +18,8 @@ class MinMaxPropertiesTest extends BaseTestCase */ public function getValidTests() { - return array( - array( + return [ + [ '{ "value": {} }', @@ -29,8 +29,8 @@ public function getValidTests() "value": {"type": "object", "minProperties": 0} } }' - ), - array( + ], + [ '{ "value": {} }', @@ -40,8 +40,8 @@ public function getValidTests() "value": {"type": "object", "maxProperties": 1} } }' - ), - array( + ], + [ '{ "value": {} }', @@ -51,8 +51,8 @@ public function getValidTests() "value": {"type": "object", "minProperties": 0,"maxProperties": 1} } }' - ), - array( + ], + [ '{ "value": {"foo": 1, "bar": 2} }', @@ -62,8 +62,8 @@ public function getValidTests() "value": {"type": "object", "minProperties": 1,"maxProperties": 2} } }' - ), - ); + ], + ]; } /** @@ -71,8 +71,8 @@ public function getValidTests() */ public function getInvalidTests() { - return array( - array( + return [ + [ '{ "value": {} }', @@ -82,8 +82,8 @@ public function getInvalidTests() "value": {"type": "object", "minProperties": 1} } }' - ), - array( + ], + [ '{}', '{ "type": "object", @@ -97,8 +97,8 @@ public function getInvalidTests() }, "minProperties": 1 }' - ), - array( + ], + [ '{ "value": { "propertyOne": "valueOne", @@ -111,8 +111,8 @@ public function getInvalidTests() "value": {"type": "object", "maxProperties": 1} } }' - ), - array( + ], + [ '{ "value": {"foo": 1, "bar": 2, "baz": 3} }', @@ -122,8 +122,8 @@ public function getInvalidTests() "value": {"type": "object", "minProperties": 1,"maxProperties": 2} } }' - ), - array( + ], + [ '{ "value": [] }', @@ -132,7 +132,7 @@ public function getInvalidTests() "value": {"minProperties": 1,"maxProperties": 2} } }' - ), - ); + ], + ]; } } diff --git a/tests/Constraints/MinimumMaximumTest.php b/tests/Constraints/MinimumMaximumTest.php index 508c0253..ab02bfd0 100644 --- a/tests/Constraints/MinimumMaximumTest.php +++ b/tests/Constraints/MinimumMaximumTest.php @@ -15,8 +15,8 @@ class MinimumMaximumTest extends BaseTestCase public function getInvalidTests() { - return array( - array( + return [ + [ '{ "value":2 }', @@ -26,8 +26,8 @@ public function getInvalidTests() "value":{"type":"integer","minimum":4} } }' - ), - array( + ], + [ '{"value": 3}', '{ "type": "object", @@ -35,8 +35,8 @@ public function getInvalidTests() "value": {"type": "integer", "minimum": 3, "exclusiveMinimum": true} } }' - ), - array( + ], + [ '{ "value":16 }', @@ -46,8 +46,8 @@ public function getInvalidTests() "value":{"type":"integer","maximum":8} } }' - ), - array( + ], + [ '{"value": 8}', '{ "type": "object", @@ -55,8 +55,8 @@ public function getInvalidTests() "value": {"type": "integer", "maximum": 8, "exclusiveMaximum": true} } }' - ), - array( + ], + [ '{"value": 4}', '{ "type": "object", @@ -64,8 +64,8 @@ public function getInvalidTests() "value": {"type": "integer", "exclusiveMinimum": true} } }' - ), - array( + ], + [ '{"value": 4}', '{ "type": "object", @@ -73,8 +73,8 @@ public function getInvalidTests() "value": {"type": "integer", "exclusiveMaximum": true} } }' - ), - array( + ], + [ '{"value": 4}', '{ "type": "object", @@ -82,38 +82,38 @@ public function getInvalidTests() "value": {"type": "integer", "minimum": 5, "exclusiveMinimum": false} } }' - ), - array( + ], + [ '{"value": 4}', '{ "properties": { "value": {"type": "integer", "maximum": 3, "exclusiveMaximum": false} } }' - ), - array( + ], + [ '{"value": 0.00}', '{ "properties": { "value": {"type": "number", "minimum": 0, "exclusiveMinimum": true} } }' - ), - array( + ], + [ '{"value": 0.00}', '{ "properties": { "value": {"type": "number", "maximum": 0, "exclusiveMaximum": true} } }' - ) - ); + ] + ]; } public function getValidTests() { - return array( - array( + return [ + [ '{ "value":6 }', @@ -123,8 +123,8 @@ public function getValidTests() "value":{"type":"integer","minimum":4} } }' - ), - array( + ], + [ '{ "value":6 }', @@ -134,8 +134,8 @@ public function getValidTests() "value":{"type":"integer","maximum":8} } }' - ), - array( + ], + [ '{"value": 6}', '{ "type": "object", @@ -143,8 +143,8 @@ public function getValidTests() "value": {"type": "integer", "minimum": 6, "exclusiveMinimum": false} } }' - ), - array( + ], + [ '{"value": 6}', '{ "type": "object", @@ -152,8 +152,8 @@ public function getValidTests() "value": {"type": "integer", "maximum": 6, "exclusiveMaximum": false} } }' - ), - array( + ], + [ '{"value": 6}', '{ "type": "object", @@ -161,8 +161,8 @@ public function getValidTests() "value": {"type": "integer", "minimum": 6} } }' - ), - array( + ], + [ '{"value": 6}', '{ "type": "object", @@ -170,7 +170,7 @@ public function getValidTests() "value": {"type": "integer", "maximum": 6} } }' - ) - ); + ] + ]; } } diff --git a/tests/Constraints/NotTest.php b/tests/Constraints/NotTest.php index 6183f684..092b2e39 100644 --- a/tests/Constraints/NotTest.php +++ b/tests/Constraints/NotTest.php @@ -15,8 +15,8 @@ class NotTest extends BaseTestCase public function getInvalidTests() { - return array( - array( + return [ + [ '{ "x": [1, 2] }', @@ -31,8 +31,8 @@ public function getInvalidTests() } } }' - ), - array( // check that a missing, required property is correctly validated + ], + [ // check that a missing, required property is correctly validated '{"y": "foo"}', '{ "type": "object", @@ -45,14 +45,14 @@ public function getInvalidTests() } } }' - ) - ); + ] + ]; } public function getValidTests() { - return array( - array( + return [ + [ '{ "x": [1] }', @@ -67,8 +67,8 @@ public function getValidTests() } } }' - ), - array( + ], + [ '{ "x": ["foo", 2] }', @@ -83,8 +83,8 @@ public function getValidTests() } } }' - ), - array( // check that a missing, non-required property isn't validated + ], + [ // check that a missing, non-required property isn't validated '{"y": "foo"}', '{ "type": "object", @@ -96,7 +96,7 @@ public function getValidTests() } } }' - ) - ); + ] + ]; } } diff --git a/tests/Constraints/NumberAndIntegerTypesTest.php b/tests/Constraints/NumberAndIntegerTypesTest.php index 6c7277b9..79216a24 100644 --- a/tests/Constraints/NumberAndIntegerTypesTest.php +++ b/tests/Constraints/NumberAndIntegerTypesTest.php @@ -15,8 +15,8 @@ class NumberAndIntegerTypesTest extends BaseTestCase public function getInvalidTests() { - return array( - array( + return [ + [ '{ "integer": 1.4 }', @@ -26,8 +26,8 @@ public function getInvalidTests() "integer":{"type":"integer"} } }' - ), - array( + ], + [ '{"integer": 1.001}', '{ "type": "object", @@ -35,8 +35,8 @@ public function getInvalidTests() "integer": {"type": "integer"} } }' - ), - array( + ], + [ '{"integer": true}', '{ "type": "object", @@ -44,8 +44,8 @@ public function getInvalidTests() "integer": {"type": "integer"} } }' - ), - array( + ], + [ '{"number": "x"}', '{ "type": "object", @@ -53,14 +53,14 @@ public function getInvalidTests() "number": {"type": "number"} } }' - ) - ); + ] + ]; } public function getValidTests() { - return array( - array( + return [ + [ '{ "integer": 1 }', @@ -70,8 +70,8 @@ public function getValidTests() "integer":{"type":"integer"} } }' - ), - array( + ], + [ '{ "number": 1.4 }', @@ -81,8 +81,8 @@ public function getValidTests() "number":{"type":"number"} } }' - ), - array( + ], + [ '{"number": 1e5}', '{ "type": "object", @@ -90,8 +90,8 @@ public function getValidTests() "number": {"type": "number"} } }' - ), - array( + ], + [ '{"number": 1}', '{ "type": "object", @@ -100,8 +100,8 @@ public function getValidTests() } }' - ), - array( + ], + [ '{"number": -49.89}', '{ "type": "object", @@ -112,7 +112,7 @@ public function getValidTests() } } }' - ) - ); + ] + ]; } } diff --git a/tests/Constraints/OfPropertiesTest.php b/tests/Constraints/OfPropertiesTest.php index ff8bded3..ac31db92 100644 --- a/tests/Constraints/OfPropertiesTest.php +++ b/tests/Constraints/OfPropertiesTest.php @@ -20,8 +20,8 @@ class OfPropertiesTest extends BaseTestCase public function getValidTests() { - return array( - array( + return [ + [ '{"prop1": "abc"}', '{ "type": "object", @@ -36,8 +36,8 @@ public function getValidTests() }, "required": ["prop1"] }' - ), - array( + ], + [ '{"prop1": "abc", "prop2": 23}', '{ "type": "object", @@ -52,14 +52,14 @@ public function getValidTests() }, "required": ["prop1"] }' - ), - ); + ], + ]; } public function getInvalidTests() { - return array( - array( + return [ + [ '{"prop1": "abc", "prop2": []}', '{ "type": "object", @@ -75,46 +75,46 @@ public function getInvalidTests() "required": ["prop1"] }', null, - array( - array( + [ + [ 'property' => 'prop2', 'pointer' => '/prop2', 'message' => 'Array value found, but a string is required', - 'constraint' => array( + 'constraint' => [ 'name' => 'type', - 'params' => array( + 'params' => [ 'expected' => 'a string', 'found' => 'array' - ) - ), + ] + ], 'context' => Validator::ERROR_DOCUMENT_VALIDATION - ), - array( + ], + [ 'property' => 'prop2', 'pointer' => '/prop2', 'message' => 'Array value found, but a number is required', - 'constraint' => array( + 'constraint' => [ 'name' => 'type', - 'params' => array( + 'params' => [ 'expected' => 'a number', 'found' => 'array' - ) - ), + ] + ], 'context' => Validator::ERROR_DOCUMENT_VALIDATION - ), - array( + ], + [ 'property' => 'prop2', 'pointer' => '/prop2', 'message' => 'Failed to match exactly one schema', - 'constraint' => array( + 'constraint' => [ 'name' => 'oneOf', - 'params' => array() - ), + 'params' => [] + ], 'context' => Validator::ERROR_DOCUMENT_VALIDATION - ), - ), - ), - array( + ], + ], + ], + [ '{"prop1": [1,2]}', '{ "type": "object", @@ -133,8 +133,8 @@ public function getInvalidTests() } } }' - ), - array( + ], + [ '{"prop1": [1,2]}', '{ "type": "object", @@ -149,8 +149,8 @@ public function getInvalidTests() } } }' - ), - array( + ], + [ '{"prop1": [1,2]}', '{ "type": "object", @@ -168,8 +168,8 @@ public function getInvalidTests() } } }' - ), - array( + ], + [ '{"prop1": [1,2]}', '{ "type": "object", @@ -187,8 +187,8 @@ public function getInvalidTests() } } }' - ), - array( + ], + [ '{"prop1": [1,2]}', '{ "type": "object", @@ -207,8 +207,8 @@ public function getInvalidTests() } } }' - ), - array( + ], + [ '{"prop1": [1,2]}', '{ "type": "object", @@ -228,8 +228,8 @@ public function getInvalidTests() } } }' - ) - ); + ] + ]; } public function testNoPrematureAnyOfException() diff --git a/tests/Constraints/PatternPropertiesTest.php b/tests/Constraints/PatternPropertiesTest.php index 8dede058..0672fb01 100644 --- a/tests/Constraints/PatternPropertiesTest.php +++ b/tests/Constraints/PatternPropertiesTest.php @@ -15,200 +15,200 @@ class PatternPropertiesTest extends BaseTestCase public function getInvalidTests() { - return array( + return [ // matches pattern but invalid schema for object - array( - json_encode(array( - 'someobject' => array( + [ + json_encode([ + 'someobject' => [ 'foobar' => 'foo', 'barfoo' => 'bar', - ) - )), - json_encode(array( + ] + ]), + json_encode([ 'type' => 'object', - 'patternProperties' => array( - '^someobject$' => array( + 'patternProperties' => [ + '^someobject$' => [ 'type' => 'object', 'additionalProperties' => false, - 'properties' => array( - 'barfoo' => array( + 'properties' => [ + 'barfoo' => [ 'type' => 'string', - ), - ) - ) - ) - )) - ), + ], + ] + ] + ] + ]) + ], // Does not match pattern - array( - json_encode(array( + [ + json_encode([ 'regex_us' => false, - )), - json_encode(array( + ]), + json_encode([ 'type' => 'object', - 'patternProperties' => array( - '^[a-z]+_(jp|de)$' => array( - 'type' => array('boolean') - ) - ), + 'patternProperties' => [ + '^[a-z]+_(jp|de)$' => [ + 'type' => ['boolean'] + ] + ], 'additionalProperties' => false - )) - ), + ]) + ], // Does not match pattern with unicode - array( - json_encode(array( + [ + json_encode([ '猡猡獛' => false, - )), - json_encode(array( + ]), + json_encode([ 'type' => 'object', - 'patternProperties' => array( - '^[\\x{0080}-\\x{006FFF}]+$' => array( - 'type' => array('boolean') - ) - ), + 'patternProperties' => [ + '^[\\x{0080}-\\x{006FFF}]+$' => [ + 'type' => ['boolean'] + ] + ], 'additionalProperties' => false - )) - ), + ]) + ], // An invalid regular expression pattern - array( - json_encode(array( + [ + json_encode([ 'regex_us' => false, - )), - json_encode(array( + ]), + json_encode([ 'type' => 'object', - 'patternProperties' => array( - '^[a-z+_jp|de)$' => array( - 'type' => array('boolean') - ) - ), + 'patternProperties' => [ + '^[a-z+_jp|de)$' => [ + 'type' => ['boolean'] + ] + ], 'additionalProperties' => false - )) - ), - ); + ]) + ], + ]; } public function getValidTests() { - return array( - array( + return [ + [ // validates pattern schema - json_encode(array( - 'someobject' => array( + json_encode([ + 'someobject' => [ 'foobar' => 'foo', 'barfoo' => 'bar', - ), - 'someotherobject' => array( + ], + 'someotherobject' => [ 'foobar' => 1234, - ), - '/products' => array( - 'get' => array() - ), - '#products' => array( - 'get' => array() - ), - '+products' => array( - 'get' => array() - ), - '~products' => array( - 'get' => array() - ), - '*products' => array( - 'get' => array() - ), - '%products' => array( - 'get' => array() - ) - )), - json_encode(array( + ], + '/products' => [ + 'get' => [] + ], + '#products' => [ + 'get' => [] + ], + '+products' => [ + 'get' => [] + ], + '~products' => [ + 'get' => [] + ], + '*products' => [ + 'get' => [] + ], + '%products' => [ + 'get' => [] + ] + ]), + json_encode([ 'type' => 'object', 'additionalProperties' => false, - 'patternProperties' => array( - '^someobject$' => array( + 'patternProperties' => [ + '^someobject$' => [ 'type' => 'object', - 'properties' => array( - 'foobar' => array('type' => 'string'), - 'barfoo' => array('type' => 'string'), - ), - ), - '^someotherobject$' => array( + 'properties' => [ + 'foobar' => ['type' => 'string'], + 'barfoo' => ['type' => 'string'], + ], + ], + '^someotherobject$' => [ 'type' => 'object', - 'properties' => array( - 'foobar' => array('type' => 'number'), - ), - ), - '^/' => array( + 'properties' => [ + 'foobar' => ['type' => 'number'], + ], + ], + '^/' => [ 'type' => 'object', - 'properties' => array( - 'get' => array('type' => 'array') - ) - ), - '^#' => array( + 'properties' => [ + 'get' => ['type' => 'array'] + ] + ], + '^#' => [ 'type' => 'object', - 'properties' => array( - 'get' => array('type' => 'array') - ) - ), - '^\+' => array( + 'properties' => [ + 'get' => ['type' => 'array'] + ] + ], + '^\+' => [ 'type' => 'object', - 'properties' => array( - 'get' => array('type' => 'array') - ) - ), - '^~' => array( + 'properties' => [ + 'get' => ['type' => 'array'] + ] + ], + '^~' => [ 'type' => 'object', - 'properties' => array( - 'get' => array('type' => 'array') - ) - ), - '^\*' => array( + 'properties' => [ + 'get' => ['type' => 'array'] + ] + ], + '^\*' => [ 'type' => 'object', - 'properties' => array( - 'get' => array('type' => 'array') - ) - ), - '^%' => array( + 'properties' => [ + 'get' => ['type' => 'array'] + ] + ], + '^%' => [ 'type' => 'object', - 'properties' => array( - 'get' => array('type' => 'array') - ) - ) - ) - )) - ), - array( - json_encode(array( + 'properties' => [ + 'get' => ['type' => 'array'] + ] + ] + ] + ]) + ], + [ + json_encode([ 'foobar' => true, 'regex_us' => 'foo', 'regex_de' => 1234 - )), - json_encode(array( + ]), + json_encode([ 'type' => 'object', - 'properties' => array( - 'foobar' => array('type' => 'boolean') - ), - 'patternProperties' => array( - '^[a-z]+_(us|de)$' => array( - 'type' => array('string', 'integer') - ) - ), + 'properties' => [ + 'foobar' => ['type' => 'boolean'] + ], + 'patternProperties' => [ + '^[a-z]+_(us|de)$' => [ + 'type' => ['string', 'integer'] + ] + ], 'additionalProperties' => false - )) - ), + ]) + ], // Does match pattern with unicode - array( - json_encode(array( + [ + json_encode([ 'ðæſ' => 'unicode', - )), - json_encode(array( + ]), + json_encode([ 'type' => 'object', - 'patternProperties' => array( - '^[\\x{0080}-\\x{10FFFF}]+$' => array( - 'type' => array('string') - ) - ), + 'patternProperties' => [ + '^[\\x{0080}-\\x{10FFFF}]+$' => [ + 'type' => ['string'] + ] + ], 'additionalProperties' => false - )) - ), - ); + ]) + ], + ]; } } diff --git a/tests/Constraints/PatternTest.php b/tests/Constraints/PatternTest.php index c017600c..3ffd2656 100644 --- a/tests/Constraints/PatternTest.php +++ b/tests/Constraints/PatternTest.php @@ -15,8 +15,8 @@ class PatternTest extends BaseTestCase public function getInvalidTests() { - return array( - array( + return [ + [ '{ "value":"Abacates" }', @@ -27,8 +27,8 @@ public function getInvalidTests() }, "additionalProperties":false }' - ), - array( + ], + [ '{"value": "abc"}', '{ "type": "object", @@ -37,8 +37,8 @@ public function getInvalidTests() }, "additionalProperties": false }' - ), - array( + ], + [ '{"value": "ü"}', '{ "type": "object", @@ -47,14 +47,14 @@ public function getInvalidTests() }, "additionalProperties": false }' - ), - ); + ], + ]; } public function getValidTests() { - return array( - array( + return [ + [ '{ "value":"Abacates" }', @@ -65,8 +65,8 @@ public function getValidTests() }, "additionalProperties":false }' - ), - array( + ], + [ '{ "value":"Abacates" }', @@ -77,8 +77,8 @@ public function getValidTests() }, "additionalProperties":false }' - ), - array( + ], + [ '{"value": "aaa"}', '{ "type": "object", @@ -87,8 +87,8 @@ public function getValidTests() }, "additionalProperties": false }' - ), - array( + ], + [ '{"value": "↓æ→"}', '{ "type": "object", @@ -97,7 +97,7 @@ public function getValidTests() }, "additionalProperties": false }' - ) - ); + ] + ]; } } diff --git a/tests/Constraints/PointerTest.php b/tests/Constraints/PointerTest.php index ef52e44b..09bcb755 100644 --- a/tests/Constraints/PointerTest.php +++ b/tests/Constraints/PointerTest.php @@ -18,124 +18,124 @@ class PointerTest extends TestCase public function testVariousPointers() { - $schema = array( + $schema = [ 'type' => 'object', - 'required' => array('prop1', 'prop2', 'prop3', 'prop4'), - 'properties' => array( - 'prop1' => array( + 'required' => ['prop1', 'prop2', 'prop3', 'prop4'], + 'properties' => [ + 'prop1' => [ 'type' => 'string' - ), - 'prop2' => array( + ], + 'prop2' => [ 'type' => 'object', - 'required' => array('prop2.1'), - 'properties' => array( - 'prop2.1' => array( + 'required' => ['prop2.1'], + 'properties' => [ + 'prop2.1' => [ 'type' => 'string' - ) - ) - ), - 'prop3' => array( + ] + ] + ], + 'prop3' => [ 'type' => 'object', - 'required' => array('prop3/1'), - 'properties' => array( - 'prop3/1' => array( + 'required' => ['prop3/1'], + 'properties' => [ + 'prop3/1' => [ 'type' => 'object', - 'required' => array('prop3/1.1'), - 'properties' => array( - 'prop3/1.1' => array( + 'required' => ['prop3/1.1'], + 'properties' => [ + 'prop3/1.1' => [ 'type' => 'string' - ) - ) - ) - ) - ), - 'prop4' => array( + ] + ] + ] + ] + ], + 'prop4' => [ 'type' => 'array', 'minItems' => 1, - 'items' => array( + 'items' => [ 'type' => 'object', - 'required' => array('prop4-child'), - 'properties' => array( - 'prop4-child' => array( + 'required' => ['prop4-child'], + 'properties' => [ + 'prop4-child' => [ 'type' => 'string' - ) - ) - ) - ) - ) - ); + ] + ] + ] + ] + ] + ]; - $value = array( - 'prop2' => array( + $value = [ + 'prop2' => [ 'foo' => 'bar' - ), - 'prop3' => array( - 'prop3/1' => array( + ], + 'prop3' => [ + 'prop3/1' => [ 'foo' => 'bar' - ) - ), - 'prop4' => array( - array( + ] + ], + 'prop4' => [ + [ 'foo' => 'bar' - ) - ) - ); + ] + ] + ]; $validator = new Validator(); $checkValue = json_decode(json_encode($value)); $validator->validate($checkValue, json_decode(json_encode($schema))); $this->assertEquals( - array( - array( + [ + [ 'property' => 'prop1', 'pointer' => '/prop1', 'message' => 'The property prop1 is required', - 'constraint' => array( + 'constraint' => [ 'name' => 'required', - 'params' => array( + 'params' => [ 'property' => 'prop1' - ) - ), + ] + ], 'context' => Validator::ERROR_DOCUMENT_VALIDATION - ), - array( + ], + [ 'property' => 'prop2.prop2.1', 'pointer' => '/prop2/prop2.1', 'message' => 'The property prop2.1 is required', - 'constraint' => array( + 'constraint' => [ 'name' => 'required', - 'params' => array( + 'params' => [ 'property' => 'prop2.1' - ) - ), + ] + ], 'context' => Validator::ERROR_DOCUMENT_VALIDATION - ), - array( + ], + [ 'property' => 'prop3.prop3/1.prop3/1.1', 'pointer' => '/prop3/prop3~11/prop3~11.1', 'message' => 'The property prop3/1.1 is required', - 'constraint' => array( + 'constraint' => [ 'name' => 'required', - 'params' => array( + 'params' => [ 'property' => 'prop3/1.1' - ) - ), + ] + ], 'context' => Validator::ERROR_DOCUMENT_VALIDATION - ), - array( + ], + [ 'property' => 'prop4[0].prop4-child', 'pointer' => '/prop4/0/prop4-child', 'message' => 'The property prop4-child is required', - 'constraint' => array( + 'constraint' => [ 'name' => 'required', - 'params' => array( + 'params' => [ 'property' => 'prop4-child' - ) - ), + ] + ], 'context' => Validator::ERROR_DOCUMENT_VALIDATION - ) - ), + ] + ], $validator->getErrors() ); } diff --git a/tests/Constraints/ReadOnlyTest.php b/tests/Constraints/ReadOnlyTest.php index 23434406..95b98333 100644 --- a/tests/Constraints/ReadOnlyTest.php +++ b/tests/Constraints/ReadOnlyTest.php @@ -16,8 +16,8 @@ class ReadOnlyTest extends BaseTestCase public function getInvalidTests() { //is readonly really required? - return array( - array( + return [ + [ '{ "number": [] }', '{ "type":"object", @@ -25,14 +25,14 @@ public function getInvalidTests() "number":{"type":"string","readonly":true} } }' - ) - ); + ] + ]; } public function getValidTests() { - return array( - array( + return [ + [ '{ "number": "1.4" }', @@ -42,7 +42,7 @@ public function getValidTests() "number":{"type":"string","readonly":true} } }' - ) - ); + ] + ]; } } diff --git a/tests/Constraints/RequireTest.php b/tests/Constraints/RequireTest.php index efb6f63e..e90489d0 100644 --- a/tests/Constraints/RequireTest.php +++ b/tests/Constraints/RequireTest.php @@ -15,8 +15,8 @@ class RequireTest extends BaseTestCase public function getInvalidTests() { - return array( - array( + return [ + [ '{ "state":"DF" }', @@ -27,14 +27,14 @@ public function getInvalidTests() "city":{"type":"string"} } }' - ) - ); + ] + ]; } public function getValidTests() { - return array( - array( + return [ + [ '{ "state":"DF", "city":"Brasília" @@ -46,7 +46,7 @@ public function getValidTests() "city":{"type":"string"} } }' - ) - ); + ] + ]; } } diff --git a/tests/Constraints/RequiredPropertyTest.php b/tests/Constraints/RequiredPropertyTest.php index 31545a64..d798ceff 100644 --- a/tests/Constraints/RequiredPropertyTest.php +++ b/tests/Constraints/RequiredPropertyTest.php @@ -115,8 +115,8 @@ protected function assertErrorHasExpectedPropertyValue($error, $propertyValue) public function getInvalidTests() { - return array( - array( + return [ + [ '{}', '{ "type":"object", @@ -124,8 +124,8 @@ public function getInvalidTests() "number":{"type":"number","required":true} } }' - ), - array( + ], + [ '{}', '{ "type": "object", @@ -134,8 +134,8 @@ public function getInvalidTests() }, "required": ["number"] }' - ), - array( + ], + [ '{ "foo": {} }', @@ -151,8 +151,8 @@ public function getInvalidTests() } } }' - ), - array( + ], + [ '{ "bar": 1.4 }', @@ -164,14 +164,14 @@ public function getInvalidTests() }, "required": ["bar"] }' - ), - array( + ], + [ '{}', '{ "required": ["foo"] }' - ), - array( + ], + [ '{ }', '{ @@ -180,8 +180,8 @@ public function getInvalidTests() "foo": { "required": true } } }' - ), - array( + ], + [ '{ "string":{} }', @@ -191,8 +191,8 @@ public function getInvalidTests() "string":{"type":"string", "required": true} } }' - ), - array( + ], + [ '{ "number":{} }', @@ -202,8 +202,8 @@ public function getInvalidTests() "number":{"type":"number", "required": true} } }' - ), - array( + ], + [ '{ "integer":{} }', @@ -213,8 +213,8 @@ public function getInvalidTests() "integer":{"type":"integer", "required": true} } }' - ), - array( + ], + [ '{ "boolean":{} }', @@ -224,8 +224,8 @@ public function getInvalidTests() "boolean":{"type":"boolean", "required": true} } }' - ), - array( + ], + [ '{ "array":{} }', @@ -236,8 +236,8 @@ public function getInvalidTests() } }', Constraint::CHECK_MODE_NORMAL - ), - array( + ], + [ '{ "null":{} }', @@ -247,8 +247,8 @@ public function getInvalidTests() "null":{"type":"null", "required": true} } }' - ), - array( + ], + [ '{ "foo": {"baz": 1.5} }', @@ -264,8 +264,8 @@ public function getInvalidTests() } } }' - ), - array( + ], + [ '{ "foo": {"baz": 1.5} }', @@ -280,14 +280,14 @@ public function getInvalidTests() } } }' - ), - ); + ], + ]; } public function getValidTests() { - return array( - array( + return [ + [ '{ "number": 1.4 }', @@ -297,8 +297,8 @@ public function getValidTests() "number":{"type":"number","required":true} } }' - ), - array( + ], + [ '{}', '{ "type":"object", @@ -306,8 +306,8 @@ public function getValidTests() "number":{"type":"number"} } }' - ), - array( + ], + [ '{}', '{ "type":"object", @@ -315,8 +315,8 @@ public function getValidTests() "number":{"type":"number","required":false} } }' - ), - array( + ], + [ '{ "number": 0 }', @@ -326,8 +326,8 @@ public function getValidTests() "number":{"type":"integer","required":true} } }' - ), - array( + ], + [ '{ "is_active": false }', @@ -337,8 +337,8 @@ public function getValidTests() "is_active":{"type":"boolean","required":true} } }' - ), - array( + ], + [ '{ "status": null }', @@ -348,8 +348,8 @@ public function getValidTests() "status":{"type":"null","required":true} } }' - ), - array( + ], + [ '{ "users": [] }', @@ -359,8 +359,8 @@ public function getValidTests() "users":{"type":"array","required":true} } }' - ), - array( + ], + [ '{ "foo": "foo", "bar": 1.4 @@ -373,8 +373,8 @@ public function getValidTests() }, "required": ["bar"] }' - ), - array( + ], + [ '{ "foo": {"bar": 1.5} }', @@ -391,8 +391,8 @@ public function getValidTests() }, "required": ["foo"] }' - ), - array( + ], + [ '{ "foo": {} }', @@ -402,8 +402,8 @@ public function getValidTests() "foo": { "required": true } } }' - ), - array( + ], + [ '{ "boo": {"bar": 1.5} }', @@ -419,8 +419,8 @@ public function getValidTests() } } }' - ), - array( + ], + [ '{ "boo": {"bar": 1.5} }', @@ -435,7 +435,7 @@ public function getValidTests() } } }' - ), - ); + ], + ]; } } diff --git a/tests/Constraints/SchemaValidationTest.php b/tests/Constraints/SchemaValidationTest.php index 08bc42cb..f158cfe3 100644 --- a/tests/Constraints/SchemaValidationTest.php +++ b/tests/Constraints/SchemaValidationTest.php @@ -19,8 +19,8 @@ class SchemaValidationTest extends TestCase public function getInvalidTests() { - return array( - array(// invalid v4 schema (uses v3 require) + return [ + [// invalid v4 schema (uses v3 require) '{ "$schema": "http://json-schema.org/draft-04/schema#", "properties": { @@ -30,8 +30,8 @@ public function getInvalidTests() } } }' - ), - array(// invalid v4 schema (uses v3 required), use default spec instead of specifying $schema + ], + [// invalid v4 schema (uses v3 required), use default spec instead of specifying $schema '{ "properties": { "propertyOne": { @@ -40,14 +40,14 @@ public function getInvalidTests() } } }' - ) - ); + ] + ]; } public function getValidTests() { - return array( - array(// valid v4 schema (uses v4 require) + return [ + [// valid v4 schema (uses v4 require) '{ "$schema": "http://json-schema.org/draft-04/schema#", "properties": { @@ -57,8 +57,8 @@ public function getValidTests() }, "required": ["propertyOne"] }' - ) - ); + ] + ]; } /** diff --git a/tests/Constraints/SelfDefinedSchemaTest.php b/tests/Constraints/SelfDefinedSchemaTest.php index 2dc4871b..2fcd4906 100644 --- a/tests/Constraints/SelfDefinedSchemaTest.php +++ b/tests/Constraints/SelfDefinedSchemaTest.php @@ -17,8 +17,8 @@ class SelfDefinedSchemaTest extends BaseTestCase public function getInvalidTests() { - return array( - array( + return [ + [ '{ "$schema": { "$schema": "http://json-schema.org/draft-04/schema#", @@ -37,14 +37,14 @@ public function getInvalidTests() "type" : "object" }', '' - ) - ); + ] + ]; } public function getValidTests() { - return array( - array( + return [ + [ '{ "$schema": { "$schema": "http://json-schema.org/draft-04/schema#", @@ -63,8 +63,8 @@ public function getValidTests() "type" : "object" }', '' - ) - ); + ] + ]; } public function testInvalidArgumentException() diff --git a/tests/Constraints/TupleTypingTest.php b/tests/Constraints/TupleTypingTest.php index 08fedc0a..52feceb2 100644 --- a/tests/Constraints/TupleTypingTest.php +++ b/tests/Constraints/TupleTypingTest.php @@ -15,8 +15,8 @@ class TupleTypingTest extends BaseTestCase public function getInvalidTests() { - return array( - array( + return [ + [ '{ "tupleTyping":[2,"a"] }', @@ -32,8 +32,8 @@ public function getInvalidTests() } } }' - ), - array( + ], + [ '{ "tupleTyping":["2",2,true] }', @@ -50,8 +50,8 @@ public function getInvalidTests() } } }' - ), - array( + ], + [ '{ "tupleTyping":["2",2,3] }', @@ -68,8 +68,8 @@ public function getInvalidTests() } } }' - ), - array( + ], + [ '{"data": [1, "foo", true, 1.5]}', '{ "type": "object", @@ -81,14 +81,14 @@ public function getInvalidTests() } } }' - ) - ); + ] + ]; } public function getValidTests() { - return array( - array( + return [ + [ '{ "tupleTyping":["2", 1] }', @@ -104,8 +104,8 @@ public function getValidTests() } } }' - ), - array( + ], + [ '{ "tupleTyping":["2",2,3] }', @@ -121,8 +121,8 @@ public function getValidTests() } } }' - ), - array( + ], + [ '{"data": [1, "foo", true]}', '{ "type": "object", @@ -134,7 +134,7 @@ public function getValidTests() } } }' - ) - ); + ] + ]; } } diff --git a/tests/Constraints/TypeTest.php b/tests/Constraints/TypeTest.php index ae35b449..4b30dacb 100644 --- a/tests/Constraints/TypeTest.php +++ b/tests/Constraints/TypeTest.php @@ -29,18 +29,18 @@ class TypeTest extends TestCase */ public function provideIndefiniteArticlesForTypes() { - return array( - array('integer', 'an integer'), - array('number', 'a number'), - array('boolean', 'a boolean'), - array('object', 'an object'), - array('array', 'an array'), - array('string', 'a string'), - array('null', 'a null', array(), 'array'), - array(array('string', 'boolean', 'integer'), 'a string, a boolean or an integer'), - array(array('string', 'boolean'), 'a string or a boolean'), - array(array('string'), 'a string'), - ); + return [ + ['integer', 'an integer'], + ['number', 'a number'], + ['boolean', 'a boolean'], + ['object', 'an object'], + ['array', 'an array'], + ['string', 'a string'], + ['null', 'a null', [], 'array'], + [['string', 'boolean', 'integer'], 'a string, a boolean or an integer'], + [['string', 'boolean'], 'a string or a boolean'], + [['string'], 'a string'], + ]; } /** @@ -49,7 +49,7 @@ public function provideIndefiniteArticlesForTypes() public function testIndefiniteArticleForTypeInTypeCheckErrorMessage($type, $wording, $value = null, $label = 'NULL') { $constraint = new TypeConstraint(); - $constraint->check($value, (object) array('type' => $type)); + $constraint->check($value, (object) ['type' => $type]); $this->assertTypeConstraintError(ucwords($label) . " value found, but $wording is required", $constraint); } @@ -96,10 +96,10 @@ private function assertTypeConstraintError($expected, TypeConstraint $actual) public function validNameWordingDataProvider() { - $wordings = array(); + $wordings = []; foreach (array_keys(TypeConstraint::$wording) as $value) { - $wordings[] = array($value); + $wordings[] = [$value]; } return $wordings; diff --git a/tests/Constraints/UnionTypesTest.php b/tests/Constraints/UnionTypesTest.php index 42676308..9757b3c2 100644 --- a/tests/Constraints/UnionTypesTest.php +++ b/tests/Constraints/UnionTypesTest.php @@ -15,8 +15,8 @@ class UnionTypesTest extends BaseTestCase public function getInvalidTests() { - return array( - array( + return [ + [ '{ "stringOrNumber":4.8, "booleanOrNull":5 @@ -28,14 +28,14 @@ public function getInvalidTests() "booleanOrNull":{"type":["boolean","null"]} } }' - ) - ); + ] + ]; } public function getValidTests() { - return array( - array( + return [ + [ '{ "stringOrNumber":4.8, "booleanOrNull":false @@ -47,7 +47,7 @@ public function getValidTests() "booleanOrNull":{"type":["boolean","null"]} } }' - ) - ); + ] + ]; } } diff --git a/tests/Constraints/UnionWithNullValueTest.php b/tests/Constraints/UnionWithNullValueTest.php index 60301f2e..ad5ea31e 100644 --- a/tests/Constraints/UnionWithNullValueTest.php +++ b/tests/Constraints/UnionWithNullValueTest.php @@ -15,8 +15,8 @@ class UnionWithNullValueTest extends BaseTestCase public function getInvalidTests() { - return array( - array( + return [ + [ '{ "stringOrNumber":null, "booleanOrNull":null @@ -28,14 +28,14 @@ public function getInvalidTests() "booleanOrNull":{"type":["boolean","null"]} } }' - ) - ); + ] + ]; } public function getValidTests() { - return array( - array( + return [ + [ '{ "stringOrNumber":12, "booleanOrNull":null @@ -47,7 +47,7 @@ public function getValidTests() "booleanOrNull":{"type":["boolean","null"]} } }' - ) - ); + ] + ]; } } diff --git a/tests/Constraints/UniqueItemsTest.php b/tests/Constraints/UniqueItemsTest.php index 099b407c..91843f45 100644 --- a/tests/Constraints/UniqueItemsTest.php +++ b/tests/Constraints/UniqueItemsTest.php @@ -15,147 +15,147 @@ class UniqueItemsTest extends BaseTestCase public function getInvalidTests() { - return array( - array( + return [ + [ '[1,2,2]', '{ "type":"array", "uniqueItems": true }' - ), - array( + ], + [ '[{"a":"b"},{"a":"c"},{"a":"b"}]', '{ "type":"array", "uniqueItems": true }' - ), - array( + ], + [ '[{"foo": {"bar" : {"baz" : true}}}, {"foo": {"bar" : {"baz" : true}}}]', '{ "type": "array", "uniqueItems": true }' - ), - array( + ], + [ '[1.0, 1.00, 1]', '{ "type": "array", "uniqueItems": true }' - ), - array( + ], + [ '[["foo"], ["foo"]]', '{ "type": "array", "uniqueItems": true }' - ), - array( + ], + [ '[{}, [1], true, null, {}, 1]', '{ "type": "array", "uniqueItems": true }' - ) - ); + ] + ]; } public function getValidTests() { - return array( - array( + return [ + [ '[1,2,3]', '{ "type":"array", "uniqueItems": true }' - ), - array( + ], + [ '[{"foo": 12}, {"bar": false}]', '{ "type": "array", "uniqueItems": true }' - ), - array( + ], + [ '[1, true]', '{ "type": "array", "uniqueItems": true }' - ), - array( + ], + [ '[0, false]', '{ "type": "array", "uniqueItems": true }' - ), - array( + ], + [ '[{"foo": {"bar" : {"baz" : true}}}, {"foo": {"bar" : {"baz" : false}}}]', '{ "type": "array", "uniqueItems": true }' - ), - array( + ], + [ '[["foo"], ["bar"]]', '{ "type": "array", "uniqueItems": true }' - ), - array( + ], + [ '[{}, [1], true, null, 1]', '{ "type": "array", "uniqueItems": true }' - ), + ], // below equals the invalid tests, but with uniqueItems set to false - array( + [ '[1,2,2]', '{ "type":"array", "uniqueItems": false }' - ), - array( + ], + [ '[{"a":"b"},{"a":"c"},{"a":"b"}]', '{ "type":"array", "uniqueItems": false }' - ), - array( + ], + [ '[{"foo": {"bar" : {"baz" : true}}}, {"foo": {"bar" : {"baz" : true}}}]', '{ "type": "array", "uniqueItems": false }' - ), - array( + ], + [ '[1.0, 1.00, 1]', '{ "type": "array", "uniqueItems": false }' - ), - array( + ], + [ '[["foo"], ["foo"]]', '{ "type": "array", "uniqueItems": false }' - ), - array( + ], + [ '[{}, [1], true, null, {}, 1]', '{ "type": "array", "uniqueItems": false }' - ) - ); + ] + ]; } } diff --git a/tests/Constraints/WrongMessagesFailingTestCaseTest.php b/tests/Constraints/WrongMessagesFailingTestCaseTest.php index 80a14421..aae9b552 100644 --- a/tests/Constraints/WrongMessagesFailingTestCaseTest.php +++ b/tests/Constraints/WrongMessagesFailingTestCaseTest.php @@ -15,8 +15,8 @@ class WrongMessagesFailingTestCaseTest extends BaseTestCase public function getInvalidTests() { - return array( - array( + return [ + [ '{ "stringOrNumber":4.8, "booleanOrNull":["A","B"] @@ -28,14 +28,14 @@ public function getInvalidTests() "booleanOrNull":{"type":["boolean","null"]} } }' - ) - ); + ] + ]; } public function getValidTests() { - return array( - array( + return [ + [ '{ "stringOrNumber":4.8, "booleanOrNull":true @@ -47,7 +47,7 @@ public function getValidTests() "booleanOrNull":{"type":["boolean","null"]} } }' - ) - ); + ] + ]; } } diff --git a/tests/Drafts/BaseDraftTestCase.php b/tests/Drafts/BaseDraftTestCase.php index 8af703e7..cd2d4c86 100644 --- a/tests/Drafts/BaseDraftTestCase.php +++ b/tests/Drafts/BaseDraftTestCase.php @@ -16,7 +16,7 @@ private function setUpTests($isValid) { $filePaths = $this->getFilePaths(); $skippedTests = $this->getSkippedTests(); - $tests = array(); + $tests = []; foreach ($filePaths as $path) { foreach (glob($path . '/*.json') as $file) { @@ -33,7 +33,7 @@ private function setUpTests($isValid) if ($isValid === $test->valid) { $tests[ $this->createDataSetPath($filename, $suiteDescription, $testCaseDescription) - ] = array(json_encode($test->data), json_encode($suite->schema)); + ] = [json_encode($test->data), json_encode($suite->schema)]; } } } diff --git a/tests/Drafts/Draft3Test.php b/tests/Drafts/Draft3Test.php index 84d2353f..f6cf41ad 100644 --- a/tests/Drafts/Draft3Test.php +++ b/tests/Drafts/Draft3Test.php @@ -22,10 +22,10 @@ class Draft3Test extends BaseDraftTestCase */ protected function getFilePaths() { - return array( + return [ realpath(__DIR__ . $this->relativeTestsRoot . '/draft3'), realpath(__DIR__ . $this->relativeTestsRoot . '/draft3/optional') - ); + ]; } public function getInvalidForAssocTests() @@ -55,12 +55,12 @@ public function getValidForAssocTests() */ protected function getSkippedTests() { - return array( + return [ // Optional 'bignum.json', 'format.json', 'jsregex.json', 'zeroTerminatedFloats.json' - ); + ]; } } diff --git a/tests/Drafts/Draft4Test.php b/tests/Drafts/Draft4Test.php index 54eee4c4..e129ad80 100644 --- a/tests/Drafts/Draft4Test.php +++ b/tests/Drafts/Draft4Test.php @@ -22,10 +22,10 @@ class Draft4Test extends BaseDraftTestCase */ protected function getFilePaths() { - return array( + return [ realpath(__DIR__ . $this->relativeTestsRoot . '/draft4'), realpath(__DIR__ . $this->relativeTestsRoot . '/draft4/optional') - ); + ]; } public function getInvalidForAssocTests() @@ -55,13 +55,13 @@ public function getValidForAssocTests() */ protected function getSkippedTests() { - return array( + return [ // Optional 'bignum.json', 'format.json', 'zeroTerminatedFloats.json', // Required 'not.json' // only one test case failing - ); + ]; } } diff --git a/tests/Entity/JsonPointerTest.php b/tests/Entity/JsonPointerTest.php index 70feb172..48203824 100644 --- a/tests/Entity/JsonPointerTest.php +++ b/tests/Entity/JsonPointerTest.php @@ -47,67 +47,67 @@ public function testJsonPointer( */ public function getTestData() { - return array( - 'testDataSet_01' => array( + return [ + 'testDataSet_01' => [ 'testValue' => '#/definitions/date', 'expectedFileName' => '', - 'expectedPropertyPaths' => array('definitions', 'date'), + 'expectedPropertyPaths' => ['definitions', 'date'], 'expectedPropertyPathAsString' => '#/definitions/date', 'expectedToString' => '#/definitions/date' - ), - 'testDataSet_02' => array( + ], + 'testDataSet_02' => [ 'testValue' => 'http://www.example.com/definitions.json#/definitions/date', 'expectedFileName' => 'http://www.example.com/definitions.json', - 'expectedPropertyPaths' => array('definitions', 'date'), + 'expectedPropertyPaths' => ['definitions', 'date'], 'expectedPropertyPathAsString' => '#/definitions/date', 'expectedToString' => 'http://www.example.com/definitions.json#/definitions/date' - ), - 'testDataSet_03' => array( + ], + 'testDataSet_03' => [ 'testValue' => '/tmp/schema.json#definitions/common/date/', 'expectedFileName' => '/tmp/schema.json', - 'expectedPropertyPaths' => array('definitions', 'common', 'date'), + 'expectedPropertyPaths' => ['definitions', 'common', 'date'], 'expectedPropertyPathAsString' => '#/definitions/common/date', 'expectedToString' => '/tmp/schema.json#/definitions/common/date' - ), - 'testDataSet_04' => array( + ], + 'testDataSet_04' => [ 'testValue' => './definitions.json#', 'expectedFileName' => './definitions.json', - 'expectedPropertyPaths' => array(), + 'expectedPropertyPaths' => [], 'expectedPropertyPathAsString' => '#', 'expectedToString' => './definitions.json#' - ), - 'testDataSet_05' => array( + ], + 'testDataSet_05' => [ 'testValue' => '/schema.json#~0definitions~1general/%custom%25', 'expectedFileName' => '/schema.json', - 'expectedPropertyPaths' => array('~definitions/general', '%custom%'), + 'expectedPropertyPaths' => ['~definitions/general', '%custom%'], 'expectedPropertyPathAsString' => '#/~0definitions~1general/%25custom%25', 'expectedToString' => '/schema.json#/~0definitions~1general/%25custom%25' - ), - 'testDataSet_06' => array( + ], + 'testDataSet_06' => [ 'testValue' => '#/items/0', 'expectedFileName' => '', - 'expectedPropertyPaths' => array('items', '0'), + 'expectedPropertyPaths' => ['items', '0'], 'expectedPropertyPathAsString' => '#/items/0', 'expectedToString' => '#/items/0' - ) - ); + ] + ]; } public function testJsonPointerWithPropertyPaths() { $initial = new JsonPointer('#/definitions/date'); - $this->assertEquals(array('definitions', 'date'), $initial->getPropertyPaths()); + $this->assertEquals(['definitions', 'date'], $initial->getPropertyPaths()); $this->assertEquals('#/definitions/date', $initial->getPropertyPathAsString()); - $modified = $initial->withPropertyPaths(array('~definitions/general', '%custom%')); + $modified = $initial->withPropertyPaths(['~definitions/general', '%custom%']); $this->assertNotSame($initial, $modified); - $this->assertEquals(array('definitions', 'date'), $initial->getPropertyPaths()); + $this->assertEquals(['definitions', 'date'], $initial->getPropertyPaths()); $this->assertEquals('#/definitions/date', $initial->getPropertyPathAsString()); - $this->assertEquals(array('~definitions/general', '%custom%'), $modified->getPropertyPaths()); + $this->assertEquals(['~definitions/general', '%custom%'], $modified->getPropertyPaths()); $this->assertEquals('#/~0definitions~1general/%25custom%25', $modified->getPropertyPathAsString()); } diff --git a/tests/Iterators/ObjectIteratorTest.php b/tests/Iterators/ObjectIteratorTest.php index a226c060..80b711f3 100644 --- a/tests/Iterators/ObjectIteratorTest.php +++ b/tests/Iterators/ObjectIteratorTest.php @@ -18,21 +18,21 @@ class ObjectIteratorTest extends TestCase public function setUp(): void { - $this->testObject = (object) array( - 'subOne' => (object) array( + $this->testObject = (object) [ + 'subOne' => (object) [ 'propertyOne' => 'valueOne', 'propertyTwo' => 'valueTwo', 'propertyThree' => 'valueThree' - ), - 'subTwo' => (object) array( + ], + 'subTwo' => (object) [ 'propertyFour' => 'valueFour', - 'subThree' => (object) array( + 'subThree' => (object) [ 'propertyFive' => 'valueFive', 'propertySix' => 'valueSix' - ) - ), + ] + ], 'propertySeven' => 'valueSeven' - ); + ]; } public function testCreate() diff --git a/tests/RefTest.php b/tests/RefTest.php index a356a413..94f9cf91 100644 --- a/tests/RefTest.php +++ b/tests/RefTest.php @@ -16,10 +16,10 @@ class RefTest extends TestCase { public function dataRefIgnoresSiblings() { - return array( + return [ // #0 check that $ref is resolved and the instance is validated against // the referenced schema - array( + [ '{ "definitions":{"test": {"type": "integer"}}, "properties": { @@ -28,9 +28,9 @@ public function dataRefIgnoresSiblings() }', '{"propertyOne": "not an integer"}', false - ), + ], // #1 check that sibling properties of $ref are ignored during validation - array( + [ '{ "definitions":{ "test": {"type": "integer"} @@ -44,9 +44,9 @@ public function dataRefIgnoresSiblings() }', '{"propertyOne": 10}', true - ), + ], // #2 infinite-loop / unresolveable circular reference - array( + [ '{ "definitions": { "test1": {"$ref": "#/definitions/test2"}, @@ -57,8 +57,8 @@ public function dataRefIgnoresSiblings() '{"propertyOne": 5}', true, '\JsonSchema\Exception\UnresolvableJsonPointerException' - ) - ); + ] + ]; } /** @dataProvider dataRefIgnoresSiblings */ diff --git a/tests/Rfc3339Test.php b/tests/Rfc3339Test.php index e489d389..890aa57e 100644 --- a/tests/Rfc3339Test.php +++ b/tests/Rfc3339Test.php @@ -31,46 +31,46 @@ public function testCreateFromInvalidString($string) public function provideValidFormats() { - return array( - array( + return [ + [ '2000-05-01T12:12:12Z', \DateTime::createFromFormat('Y-m-d\TH:i:s', '2000-05-01T12:12:12', new \DateTimeZone('UTC')) - ), - array( + ], + [ '2000-05-01T12:12:12+0100', \DateTime::createFromFormat('Y-m-d\TH:i:sP', '2000-05-01T12:12:12+01:00') - ), - array( + ], + [ '2000-05-01T12:12:12+01:00', \DateTime::createFromFormat('Y-m-d\TH:i:sP', '2000-05-01T12:12:12+01:00') - ), - array( + ], + [ '2000-05-01T12:12:12.123456Z', \DateTime::createFromFormat('Y-m-d\TH:i:s.u', '2000-05-01T12:12:12.123456', new \DateTimeZone('UTC')) - ), - array( + ], + [ '2000-05-01T12:12:12.123Z', \DateTime::createFromFormat('Y-m-d\TH:i:s.u', '2000-05-01T12:12:12.123000', new \DateTimeZone('UTC')) - ), - array( + ], + [ '2000-05-01 12:12:12.123Z', \DateTime::createFromFormat('Y-m-d H:i:s.u', '2000-05-01 12:12:12.123000', new \DateTimeZone('UTC')) - ), - array( + ], + [ '2000-05-01 12:12:12.123456Z', \DateTime::createFromFormat('Y-m-d H:i:s.u', '2000-05-01 12:12:12.123456', new \DateTimeZone('UTC')) - ) - ); + ] + ]; } public function provideInvalidFormats() { - return array( - array('1999-1-11T00:00:00Z'), - array('1999-01-11T00:00:00+100'), - array('1999-01-11T00:00:00+1:00'), - array('1999-01-01 00:00:00Z'), - array('1999-1-11 00:00:00Z') - ); + return [ + ['1999-1-11T00:00:00Z'], + ['1999-01-11T00:00:00+100'], + ['1999-01-11T00:00:00+1:00'], + ['1999-01-01 00:00:00Z'], + ['1999-1-11 00:00:00Z'] + ]; } } diff --git a/tests/SchemaStorageTest.php b/tests/SchemaStorageTest.php index d4e812cb..8dd7e582 100644 --- a/tests/SchemaStorageTest.php +++ b/tests/SchemaStorageTest.php @@ -27,7 +27,7 @@ public function testResolveRef() $schemaStorage = new SchemaStorage($uriRetriever->reveal()); $this->assertEquals( - (object) array('type' => 'string'), + (object) ['type' => 'string'], $schemaStorage->resolveRef("$mainSchemaPath#/definitions/house/properties/door") ); } @@ -131,61 +131,61 @@ public function testResolveRefWithNoAssociatedFileName() */ private function getMainSchema() { - return (object) array( + return (object) [ 'version' => 'v1', '$schema' => 'http://json-schema.org/draft-04/schema#', 'id' => 'http://www.example.com/schema.json', 'type' => 'object', 'additionalProperties' => true, - 'required' => array( + 'required' => [ 'car' - ), - 'properties' => (object) array( - 'car' => (object) array( + ], + 'properties' => (object) [ + 'car' => (object) [ '$ref' => 'http://www.my-domain.com/schema2.json#/definitions/car' - ), - 'house' => (object) array( + ], + 'house' => (object) [ 'additionalProperties' => true, '$ref' => '#/definitions/house' - ), - 'yard' => (object) array( + ], + 'yard' => (object) [ 'type' => 'object', 'additionalProperties' => false, - 'properties' => (object) array( + 'properties' => (object) [ '$ref' => '#/definitions/yardproperties' - ) - ) - ), - 'definitions' => (object) array( - 'house' => (object) array( + ] + ] + ], + 'definitions' => (object) [ + 'house' => (object) [ 'type' => 'object', 'additionalProperties' => false, - 'required' => array( + 'required' => [ 'door', 'window' - ), - 'properties' => (object) array( - 'door' => (object) array( + ], + 'properties' => (object) [ + 'door' => (object) [ 'type' => 'string' - ), - 'window' => (object) array( + ], + 'window' => (object) [ 'type' => 'string' - ), - 'house' => (object) array( + ], + 'house' => (object) [ '$ref' => '#/definitions/house' - ) - ) - ), - 'yardproperties' => (object) array( - 'tree'=>(object) array( + ] + ] + ], + 'yardproperties' => (object) [ + 'tree'=>(object) [ 'type' => 'string' - ), - 'pool'=>(object) array( + ], + 'pool'=>(object) [ 'type' => 'string' - ) - ) - ) - ); + ] + ] + ] + ]; } /** @@ -193,29 +193,29 @@ private function getMainSchema() */ private function getSchema2() { - return (object) array( + return (object) [ 'version' => 'v1', '$schema' => 'http://json-schema.org/draft-04/schema#', 'id' => 'http://www.my-domain.com/schema2.json', - 'definitions' => (object) array( - 'car' => (object) array( + 'definitions' => (object) [ + 'car' => (object) [ 'type' => 'object', 'additionalProperties' => false, - 'properties' => (object) array( - 'id' => (object) array( + 'properties' => (object) [ + 'id' => (object) [ 'type' => 'integer' - ), - 'name' => (object) array( + ], + 'name' => (object) [ 'type' => 'string', 'minLength' => 1 - ), - 'wheel' => (object) array( + ], + 'wheel' => (object) [ '$ref' => './schema3.json#/wheel' - ) - ) - ) - ) - ); + ] + ] + ] + ] + ]; } /** @@ -223,24 +223,24 @@ private function getSchema2() */ private function getSchema3() { - return (object) array( + return (object) [ 'version' => 'v1', '$schema' => 'http://json-schema.org/draft-04/schema#', 'title' => 'wheel', - 'wheel' => (object) array( - 'properties' => (object) array( - 'spokes' => (object) array( + 'wheel' => (object) [ + 'properties' => (object) [ + 'spokes' => (object) [ 'type' => 'integer' - ), - 'size' => (object) array( + ], + 'size' => (object) [ 'type' => 'integer' - ), - 'car' => (object) array( + ], + 'car' => (object) [ '$ref' => './schema2.json#/definitions/car' - ) - ) - ) - ); + ] + ] + ] + ]; } /** @@ -248,28 +248,28 @@ private function getSchema3() */ private function getInvalidSchema() { - return (object) array( + return (object) [ 'version' => 'v1', '$schema' => 'http://json-schema.org/draft-04/schema#', 'type' => 'object', - 'properties' => (object) array( - 'spokes' => (object) array( + 'properties' => (object) [ + 'spokes' => (object) [ 'type' => 'integer' - ), - 'size' => (object) array( + ], + 'size' => (object) [ 'type' => 'integer' - ), - 'car' => (object) array( + ], + 'car' => (object) [ '$ref' => '#/definitions/car' - ) - ), - 'definitions' => (object) array( - 'date' => (object) array( + ] + ], + 'definitions' => (object) [ + 'date' => (object) [ 'type' => 'string', 'pattern' => '^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$' - ) - ) - ); + ] + ] + ]; } public function testGetUriRetriever() diff --git a/tests/Uri/Retrievers/CurlTest.php b/tests/Uri/Retrievers/CurlTest.php index 40293905..bac8c32e 100644 --- a/tests/Uri/Retrievers/CurlTest.php +++ b/tests/Uri/Retrievers/CurlTest.php @@ -43,9 +43,9 @@ function curl_exec($curl) if ($uri === realpath(__DIR__ . '/../../fixtures/foobar.json')) { // return file with headers - $headers = implode("\n", array( + $headers = implode("\n", [ 'Content-Type: application/json' - )); + ]); return sprintf("%s\r\n\r\n%s", $headers, file_get_contents($uri)); } elseif ($uri === realpath(__DIR__ . '/../../fixtures') . '/foobar-noheader.json') { diff --git a/tests/Uri/Retrievers/FileGetContentsTest.php b/tests/Uri/Retrievers/FileGetContentsTest.php index 6f8f2b3f..eab18b2f 100644 --- a/tests/Uri/Retrievers/FileGetContentsTest.php +++ b/tests/Uri/Retrievers/FileGetContentsTest.php @@ -34,8 +34,8 @@ public function testContentType() $fetchContentType = $reflector->getMethod('fetchContentType'); $fetchContentType->setAccessible(true); - $this->assertTrue($fetchContentType->invoke($res, array('Content-Type: application/json'))); - $this->assertFalse($fetchContentType->invoke($res, array('X-Some-Header: whateverValue'))); + $this->assertTrue($fetchContentType->invoke($res, ['Content-Type: application/json'])); + $this->assertFalse($fetchContentType->invoke($res, ['X-Some-Header: whateverValue'])); } public function testCanHandleHttp301PermanentRedirect() diff --git a/tests/Uri/Retrievers/PredefinedArrayTest.php b/tests/Uri/Retrievers/PredefinedArrayTest.php index 84ecf3c7..7572a88b 100644 --- a/tests/Uri/Retrievers/PredefinedArrayTest.php +++ b/tests/Uri/Retrievers/PredefinedArrayTest.php @@ -15,10 +15,10 @@ class PredefinedArrayTest extends TestCase public function setUp(): void { $this->retriever = new PredefinedArray( - array( + [ 'http://acme.com/schemas/person#' => 'THE_PERSON_SCHEMA', 'http://acme.com/schemas/address#' => 'THE_ADDRESS_SCHEMA', - ), + ], 'THE_CONTENT_TYPE' ); } diff --git a/tests/Uri/UriResolverTest.php b/tests/Uri/UriResolverTest.php index 38274409..98b48a2e 100644 --- a/tests/Uri/UriResolverTest.php +++ b/tests/Uri/UriResolverTest.php @@ -17,11 +17,11 @@ public function setUp(): void public function testParse() { $this->assertEquals( - array( + [ 'scheme' => 'http', 'authority' => 'example.org', 'path' => '/path/to/file.json' - ), + ], $this->resolver->parse('http://example.org/path/to/file.json') ); } @@ -29,13 +29,13 @@ public function testParse() public function testParseAnchor() { $this->assertEquals( - array( + [ 'scheme' => 'http', 'authority' => 'example.org', 'path' => '/path/to/file.json', 'query' => '', 'fragment' => 'foo' - ), + ], $this->resolver->parse('http://example.org/path/to/file.json#foo') ); } @@ -174,13 +174,13 @@ public function testReversable() $split = $this->resolver->parse($uri); // check that the URI was split as expected - $this->assertEquals(array( + $this->assertEquals([ 'scheme' => 'scheme', 'authority' => 'user:password@authority', 'path' => '/path', 'query' => 'query', 'fragment' => 'fragment' - ), $split); + ], $split); // check that the recombined URI matches the original input $this->assertEquals($uri, $this->resolver->generate($split)); diff --git a/tests/Uri/UriRetrieverTest.php b/tests/Uri/UriRetrieverTest.php index b494dcd1..94e59bd9 100644 --- a/tests/Uri/UriRetrieverTest.php +++ b/tests/Uri/UriRetrieverTest.php @@ -145,16 +145,16 @@ public function jsonProvider() } EOF; - return array( - array($childSchema, $parentSchema) - ); + return [ + [$childSchema, $parentSchema] + ]; } public function testResolvePointerNoFragment() { - $schema = (object) array( + $schema = (object) [ 'title' => 'schema' - ); + ]; $retriever = new UriRetriever(); $this->assertEquals( @@ -167,14 +167,14 @@ public function testResolvePointerNoFragment() public function testResolvePointerFragment() { - $schema = (object) array( - 'definitions' => (object) array( - 'foo' => (object) array( + $schema = (object) [ + 'definitions' => (object) [ + 'foo' => (object) [ 'title' => 'foo' - ) - ), + ] + ], 'title' => 'schema' - ); + ]; $retriever = new UriRetriever(); $this->assertEquals( @@ -187,14 +187,14 @@ public function testResolvePointerFragment() public function testResolvePointerFragmentNotFound() { - $schema = (object) array( - 'definitions' => (object) array( - 'foo' => (object) array( + $schema = (object) [ + 'definitions' => (object) [ + 'foo' => (object) [ 'title' => 'foo' - ) - ), + ] + ], 'title' => 'schema' - ); + ]; $retriever = new UriRetriever(); @@ -206,14 +206,14 @@ public function testResolvePointerFragmentNotFound() public function testResolvePointerFragmentNoArray() { - $schema = (object) array( - 'definitions' => (object) array( - 'foo' => array( + $schema = (object) [ + 'definitions' => (object) [ + 'foo' => [ 'title' => 'foo' - ) - ), + ] + ], 'title' => 'schema' - ); + ]; $retriever = new UriRetriever(); @@ -371,7 +371,7 @@ public function testSchemaCache() // inject a schema cache value $schemaCache = $reflector->getProperty('schemaCache'); $schemaCache->setAccessible(true); - $schemaCache->setValue($retriever, array('local://test/uri' => 'testSchemaValue')); + $schemaCache->setValue($retriever, ['local://test/uri' => 'testSchemaValue']); // retrieve from schema cache $loadSchema = $reflector->getMethod('loadSchema'); @@ -395,13 +395,13 @@ public function testLoadSchemaJSONDecodingException() public function testGenerateURI() { $retriever = new UriRetriever(); - $components = array( + $components = [ 'scheme' => 'scheme', 'authority' => 'authority', 'path' => '/path', 'query' => '?query', 'fragment' => '#fragment' - ); + ]; $this->assertEquals('scheme://authority/path?query#fragment', $retriever->generate($components)); } @@ -416,10 +416,10 @@ public function testResolveHTTP() public function combinedURITests() { - return array( - array('blue', 'http://example.com/red', 'http://example.com/blue'), - array('blue', 'http://example.com/', 'http://example.com/blue'), - ); + return [ + ['blue', 'http://example.com/red', 'http://example.com/blue'], + ['blue', 'http://example.com/', 'http://example.com/blue'], + ]; } /** diff --git a/tests/ValidatorTest.php b/tests/ValidatorTest.php index 774d2c11..eec59a10 100644 --- a/tests/ValidatorTest.php +++ b/tests/ValidatorTest.php @@ -26,7 +26,7 @@ public function testBadAssocSchemaInput() if (defined('HHVM_VERSION')) { $this->markTestSkipped('HHVM has no problem with encoding resources'); } - $schema = array('propertyOne' => fopen('php://stdout', 'w')); + $schema = ['propertyOne' => fopen('php://stdout', 'w')]; $data = json_decode('{"propertyOne":[42]}', true); $validator = new Validator();