diff --git a/CHANGELOG.md b/CHANGELOG.md index c0f6e614..05570ce1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,46 @@ # Change Log All notable changes to this project will be documented in this file. +## 3.2.7 - 2019-12-19 + +### Fixes +- Reinstated the `@method` return type for `Assert\LazyAssertion` methods to show that the return type is `LazyAssertion`. + +## 3.2.6 - 2019-10-10 + +### Fixes +- Make `Assert\Assertion::stringify()` UTF-8 safe (Thanks to [Pedram Azimaei](https://github.com/beberlei/assert/pull/290)) + +## 3.2.5 - 2019-10-10 - Fix the broken things release. + +### Notice +- Sigh! + - Richard Quadling + +### Fixes +- REALLY Removed dependency of the intl extension. +- Updated the Docblocks for `Assert\Assertion::all()` helper to show that the value is expected to be an array. + +## 3.2.4 - 2019-10-10 - Fix the broken things release. + +### Notice +- It seems I've been slightly lax in verifying the signature changes and expected extensions. + Hopefully, both of these have been fixed in this version. + Truly sorry for breaking the internet! + - Richard Quadling + +### Fixes +- Restored `\Assert\Assertion::createException()` signature to 3.2.2. +- Removed dependency of the intl extension. If the extension is available, then `Assert\Assertion::count()`, + `Assert\Assertion::isCountable()`, `Assert\Assertion::minCount()`, and `Assert\Assertion::maxCount()` will operate on + `ResourceBundles`. +- Fixed the `@method` return type for `Assert\LazyAssertion` methods to show that the return type is `static` for + extensions of `Assert\LazyAssertion`. + *NOTE :* Docblock does not have the ability to differentiate between a non static `@method` whose returns type is of + the subclass and a `@method` that is called statically ([PSR-5#899](https://github.com/php-fig/fig-standards/pull/899)). + So the use of `static static` is a fudge that sort of works for IDEs that need to know about the method that MAY be + overridden in a subclass. + ## 3.2.3 - 2019-08-23 ### Other changes diff --git a/bin/MethodDocGenerator.php b/bin/MethodDocGenerator.php index 1e666458..8e36e61b 100644 --- a/bin/MethodDocGenerator.php +++ b/bin/MethodDocGenerator.php @@ -81,6 +81,10 @@ private function generateMethodDocs($methods, $format, $skipParameterTest, $pref } } + if ($prefix === 'all' && strpos($type, 'null') === false && $parameterIndex === 0) { + $type = str_replace('|', '[]|', $type).'[]'; + } + if ($prefix === 'nullOr' && strpos($type, 'null') === false && $parameterIndex === 0) { $type .= '|null'; } @@ -197,8 +201,8 @@ public function generateLazyAssertionDocs() }; $docs = array_merge( - $this->generateMethodDocs($this->gatherAssertions(), ' * @method $this %s(%s) %s.', $skipParameterTest), - $this->generateMethodDocs($this->gatherAssertionChainSwitches(), ' * @method $this %s(%s) %s.', false) + $this->generateMethodDocs($this->gatherAssertions(), ' * @method LazyAssertion %s(%s) %s.', $skipParameterTest), + $this->generateMethodDocs($this->gatherAssertionChainSwitches(), ' * @method LazyAssertion %s(%s) %s.', false) ); $this->generateFile($phpFile, $docs, 'class'); diff --git a/composer.json b/composer.json index 21e27cb6..e1187047 100644 --- a/composer.json +++ b/composer.json @@ -19,22 +19,6 @@ "assertion", "validation" ], - "config": { - "sort-packages": true - }, - "require": { - "php": "^7", - "ext-intl": "*", - "ext-simplexml": "*", - "ext-mbstring": "*", - "ext-ctype": "*", - "ext-json": "*" - }, - "require-dev": { - "friendsofphp/php-cs-fixer": "*", - "phpstan/phpstan-shim": "*", - "phpunit/phpunit": ">=6.0.0 <8" - }, "autoload": { "psr-4": { "Assert\\": "lib/Assert" @@ -51,11 +35,29 @@ "tests/Assert/Tests/Fixtures/functions.php" ] }, + "config": { + "sort-packages": true + }, + "require": { + "php": "^7", + "ext-simplexml": "*", + "ext-mbstring": "*", + "ext-ctype": "*", + "ext-json": "*" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "*", + "phpstan/phpstan-shim": "*", + "phpunit/phpunit": ">=6.0.0 <8" + }, "scripts": { "assert:generate-docs": "php bin/generate_method_docs.php", "assert:cs-lint": "php-cs-fixer fix --diff -vvv --dry-run", "assert:cs-fix": "php-cs-fixer fix . -vvv || true", "assert:sa-code": "vendor/bin/phpstan analyse --configuration=phpstan-code.neon --no-progress --ansi -l 7 bin lib", "assert:sa-tests": "vendor/bin/phpstan analyse --configuration=phpstan-tests.neon --no-progress --ansi -l 7 tests" + }, + "suggest": { + "ext-intl": "Needed to allow Assertion::count(), Assertion::isCountable(), Assertion::minCount(), and Assertion::maxCount() to operate on ResourceBundles" } } diff --git a/lib/Assert/Assertion.php b/lib/Assert/Assertion.php index 6f5b3c2d..a8b04e52 100644 --- a/lib/Assert/Assertion.php +++ b/lib/Assert/Assertion.php @@ -30,94 +30,94 @@ * * @author Benjamin Eberlei * - * @method static bool allAlnum(mixed $value, string|callable $message = null, string $propertyPath = null) Assert that value is alphanumeric for all values. - * @method static bool allBase64(string $value, string|callable $message = null, string $propertyPath = null) Assert that a constant is defined for all values. - * @method static bool allBetween(mixed $value, mixed $lowerLimit, mixed $upperLimit, string|callable $message = null, string $propertyPath = null) Assert that a value is greater or equal than a lower limit, and less than or equal to an upper limit for all values. - * @method static bool allBetweenExclusive(mixed $value, mixed $lowerLimit, mixed $upperLimit, string|callable $message = null, string $propertyPath = null) Assert that a value is greater than a lower limit, and less than an upper limit for all values. - * @method static bool allBetweenLength(mixed $value, int $minLength, int $maxLength, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string length is between min and max lengths for all values. - * @method static bool allBoolean(mixed $value, string|callable $message = null, string $propertyPath = null) Assert that value is php boolean for all values. - * @method static bool allChoice(mixed $value, array $choices, string|callable $message = null, string $propertyPath = null) Assert that value is in array of choices for all values. - * @method static bool allChoicesNotEmpty(array $values, array $choices, string|callable $message = null, string $propertyPath = null) Determines if the values array has every choice as key and that this choice has content for all values. - * @method static bool allClassExists(mixed $value, string|callable $message = null, string $propertyPath = null) Assert that the class exists for all values. - * @method static bool allContains(mixed $string, string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string contains a sequence of chars for all values. - * @method static bool allCount(array|Countable|ResourceBundle|SimpleXMLElement $countable, int $count, string|callable $message = null, string $propertyPath = null) Assert that the count of countable is equal to count for all values. - * @method static bool allDate(string $value, string $format, string|callable $message = null, string $propertyPath = null) Assert that date is valid and corresponds to the given format for all values. - * @method static bool allDefined(mixed $constant, string|callable $message = null, string $propertyPath = null) Assert that a constant is defined for all values. - * @method static bool allDigit(mixed $value, string|callable $message = null, string $propertyPath = null) Validates if an integer or integerish is a digit for all values. - * @method static bool allDirectory(string $value, string|callable $message = null, string $propertyPath = null) Assert that a directory exists for all values. - * @method static bool allE164(string $value, string|callable $message = null, string $propertyPath = null) Assert that the given string is a valid E164 Phone Number for all values. - * @method static bool allEmail(mixed $value, string|callable $message = null, string $propertyPath = null) Assert that value is an email address (using input_filter/FILTER_VALIDATE_EMAIL) for all values. - * @method static bool allEndsWith(mixed $string, string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string ends with a sequence of chars for all values. - * @method static bool allEq(mixed $value, mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that two values are equal (using ==) for all values. - * @method static bool allEqArraySubset(mixed $value, mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that the array contains the subset for all values. - * @method static bool allExtensionLoaded(mixed $value, string|callable $message = null, string $propertyPath = null) Assert that extension is loaded for all values. - * @method static bool allExtensionVersion(string $extension, string $operator, mixed $version, string|callable $message = null, string $propertyPath = null) Assert that extension is loaded and a specific version is installed for all values. - * @method static bool allFalse(mixed $value, string|callable $message = null, string $propertyPath = null) Assert that the value is boolean False for all values. - * @method static bool allFile(string $value, string|callable $message = null, string $propertyPath = null) Assert that a file exists for all values. - * @method static bool allFloat(mixed $value, string|callable $message = null, string $propertyPath = null) Assert that value is a php float for all values. - * @method static bool allGreaterOrEqualThan(mixed $value, mixed $limit, string|callable $message = null, string $propertyPath = null) Determines if the value is greater or equal than given limit for all values. - * @method static bool allGreaterThan(mixed $value, mixed $limit, string|callable $message = null, string $propertyPath = null) Determines if the value is greater than given limit for all values. - * @method static bool allImplementsInterface(mixed $class, string $interfaceName, string|callable $message = null, string $propertyPath = null) Assert that the class implements the interface for all values. - * @method static bool allInArray(mixed $value, array $choices, string|callable $message = null, string $propertyPath = null) Assert that value is in array of choices. This is an alias of Assertion::choice() for all values. - * @method static bool allInteger(mixed $value, string|callable $message = null, string $propertyPath = null) Assert that value is a php integer for all values. - * @method static bool allIntegerish(mixed $value, string|callable $message = null, string $propertyPath = null) Assert that value is a php integer'ish for all values. - * @method static bool allInterfaceExists(mixed $value, string|callable $message = null, string $propertyPath = null) Assert that the interface exists for all values. - * @method static bool allIp(string $value, int $flag = null, string|callable $message = null, string $propertyPath = null) Assert that value is an IPv4 or IPv6 address for all values. - * @method static bool allIpv4(string $value, int $flag = null, string|callable $message = null, string $propertyPath = null) Assert that value is an IPv4 address for all values. - * @method static bool allIpv6(string $value, int $flag = null, string|callable $message = null, string $propertyPath = null) Assert that value is an IPv6 address for all values. - * @method static bool allIsArray(mixed $value, string|callable $message = null, string $propertyPath = null) Assert that value is an array for all values. - * @method static bool allIsArrayAccessible(mixed $value, string|callable $message = null, string $propertyPath = null) Assert that value is an array or an array-accessible object for all values. - * @method static bool allIsCallable(mixed $value, string|callable $message = null, string $propertyPath = null) Determines that the provided value is callable for all values. - * @method static bool allIsCountable(array|Countable|ResourceBundle|SimpleXMLElement $value, string|callable $message = null, string $propertyPath = null) Assert that value is countable for all values. - * @method static bool allIsInstanceOf(mixed $value, string $className, string|callable $message = null, string $propertyPath = null) Assert that value is instance of given class-name for all values. - * @method static bool allIsJsonString(mixed $value, string|callable $message = null, string $propertyPath = null) Assert that the given string is a valid json string for all values. - * @method static bool allIsObject(mixed $value, string|callable $message = null, string $propertyPath = null) Determines that the provided value is an object for all values. - * @method static bool allIsResource(mixed $value, string|callable $message = null, string $propertyPath = null) Assert that value is a resource for all values. - * @method static bool allIsTraversable(mixed $value, string|callable $message = null, string $propertyPath = null) Assert that value is an array or a traversable object for all values. - * @method static bool allKeyExists(mixed $value, string|int $key, string|callable $message = null, string $propertyPath = null) Assert that key exists in an array for all values. - * @method static bool allKeyIsset(mixed $value, string|int $key, string|callable $message = null, string $propertyPath = null) Assert that key exists in an array/array-accessible object using isset() for all values. - * @method static bool allKeyNotExists(mixed $value, string|int $key, string|callable $message = null, string $propertyPath = null) Assert that key does not exist in an array for all values. - * @method static bool allLength(mixed $value, int $length, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string has a given length for all values. - * @method static bool allLessOrEqualThan(mixed $value, mixed $limit, string|callable $message = null, string $propertyPath = null) Determines if the value is less or equal than given limit for all values. - * @method static bool allLessThan(mixed $value, mixed $limit, string|callable $message = null, string $propertyPath = null) Determines if the value is less than given limit for all values. - * @method static bool allMax(mixed $value, mixed $maxValue, string|callable $message = null, string $propertyPath = null) Assert that a number is smaller as a given limit for all values. - * @method static bool allMaxCount(array|Countable|ResourceBundle|SimpleXMLElement $countable, int $count, string|callable $message = null, string $propertyPath = null) Assert that the countable have at most $count elements for all values. - * @method static bool allMaxLength(mixed $value, int $maxLength, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string value is not longer than $maxLength chars for all values. - * @method static bool allMethodExists(string $value, mixed $object, string|callable $message = null, string $propertyPath = null) Determines that the named method is defined in the provided object for all values. - * @method static bool allMin(mixed $value, mixed $minValue, string|callable $message = null, string $propertyPath = null) Assert that a value is at least as big as a given limit for all values. - * @method static bool allMinCount(array|Countable|ResourceBundle|SimpleXMLElement $countable, int $count, string|callable $message = null, string $propertyPath = null) Assert that the countable have at least $count elements for all values. - * @method static bool allMinLength(mixed $value, int $minLength, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that a string is at least $minLength chars long for all values. - * @method static bool allNoContent(mixed $value, string|callable $message = null, string $propertyPath = null) Assert that value is empty for all values. - * @method static bool allNotBlank(mixed $value, string|callable $message = null, string $propertyPath = null) Assert that value is not blank for all values. - * @method static bool allNotContains(mixed $string, string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string does not contains a sequence of chars for all values. - * @method static bool allNotEmpty(mixed $value, string|callable $message = null, string $propertyPath = null) Assert that value is not empty for all values. - * @method static bool allNotEmptyKey(mixed $value, string|int $key, string|callable $message = null, string $propertyPath = null) Assert that key exists in an array/array-accessible object and its value is not empty for all values. - * @method static bool allNotEq(mixed $value1, mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that two values are not equal (using ==) for all values. - * @method static bool allNotInArray(mixed $value, array $choices, string|callable $message = null, string $propertyPath = null) Assert that value is not in array of choices for all values. - * @method static bool allNotIsInstanceOf(mixed $value, string $className, string|callable $message = null, string $propertyPath = null) Assert that value is not instance of given class-name for all values. - * @method static bool allNotNull(mixed $value, string|callable $message = null, string $propertyPath = null) Assert that value is not null for all values. - * @method static bool allNotRegex(mixed $value, string $pattern, string|callable $message = null, string $propertyPath = null) Assert that value does not match a regex for all values. - * @method static bool allNotSame(mixed $value1, mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that two values are not the same (using ===) for all values. - * @method static bool allNull(mixed $value, string|callable $message = null, string $propertyPath = null) Assert that value is null for all values. - * @method static bool allNumeric(mixed $value, string|callable $message = null, string $propertyPath = null) Assert that value is numeric for all values. - * @method static bool allObjectOrClass(mixed $value, string|callable $message = null, string $propertyPath = null) Assert that the value is an object, or a class that exists for all values. - * @method static bool allPhpVersion(string $operator, mixed $version, string|callable $message = null, string $propertyPath = null) Assert on PHP version for all values. - * @method static bool allPropertiesExist(mixed $value, array $properties, string|callable $message = null, string $propertyPath = null) Assert that the value is an object or class, and that the properties all exist for all values. - * @method static bool allPropertyExists(mixed $value, string $property, string|callable $message = null, string $propertyPath = null) Assert that the value is an object or class, and that the property exists for all values. - * @method static bool allRange(mixed $value, mixed $minValue, mixed $maxValue, string|callable $message = null, string $propertyPath = null) Assert that value is in range of numbers for all values. - * @method static bool allReadable(string $value, string|callable $message = null, string $propertyPath = null) Assert that the value is something readable for all values. - * @method static bool allRegex(mixed $value, string $pattern, string|callable $message = null, string $propertyPath = null) Assert that value matches a regex for all values. - * @method static bool allSame(mixed $value, mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that two values are the same (using ===) for all values. - * @method static bool allSatisfy(mixed $value, callable $callback, string|callable $message = null, string $propertyPath = null) Assert that the provided value is valid according to a callback for all values. - * @method static bool allScalar(mixed $value, string|callable $message = null, string $propertyPath = null) Assert that value is a PHP scalar for all values. - * @method static bool allStartsWith(mixed $string, string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string starts with a sequence of chars for all values. - * @method static bool allString(mixed $value, string|callable $message = null, string $propertyPath = null) Assert that value is a string for all values. - * @method static bool allSubclassOf(mixed $value, string $className, string|callable $message = null, string $propertyPath = null) Assert that value is subclass of given class-name for all values. - * @method static bool allTrue(mixed $value, string|callable $message = null, string $propertyPath = null) Assert that the value is boolean True for all values. - * @method static bool allUrl(mixed $value, string|callable $message = null, string $propertyPath = null) Assert that value is an URL for all values. - * @method static bool allUuid(string $value, string|callable $message = null, string $propertyPath = null) Assert that the given string is a valid UUID for all values. - * @method static bool allVersion(string $version1, string $operator, string $version2, string|callable $message = null, string $propertyPath = null) Assert comparison of two versions for all values. - * @method static bool allWriteable(string $value, string|callable $message = null, string $propertyPath = null) Assert that the value is something writeable for all values. + * @method static bool allAlnum(mixed[] $value, string|callable $message = null, string $propertyPath = null) Assert that value is alphanumeric for all values. + * @method static bool allBase64(string[] $value, string|callable $message = null, string $propertyPath = null) Assert that a constant is defined for all values. + * @method static bool allBetween(mixed[] $value, mixed $lowerLimit, mixed $upperLimit, string|callable $message = null, string $propertyPath = null) Assert that a value is greater or equal than a lower limit, and less than or equal to an upper limit for all values. + * @method static bool allBetweenExclusive(mixed[] $value, mixed $lowerLimit, mixed $upperLimit, string|callable $message = null, string $propertyPath = null) Assert that a value is greater than a lower limit, and less than an upper limit for all values. + * @method static bool allBetweenLength(mixed[] $value, int $minLength, int $maxLength, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string length is between min and max lengths for all values. + * @method static bool allBoolean(mixed[] $value, string|callable $message = null, string $propertyPath = null) Assert that value is php boolean for all values. + * @method static bool allChoice(mixed[] $value, array $choices, string|callable $message = null, string $propertyPath = null) Assert that value is in array of choices for all values. + * @method static bool allChoicesNotEmpty(array[] $values, array $choices, string|callable $message = null, string $propertyPath = null) Determines if the values array has every choice as key and that this choice has content for all values. + * @method static bool allClassExists(mixed[] $value, string|callable $message = null, string $propertyPath = null) Assert that the class exists for all values. + * @method static bool allContains(mixed[] $string, string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string contains a sequence of chars for all values. + * @method static bool allCount(array[]|Countable[]|ResourceBundle[]|SimpleXMLElement[] $countable, int $count, string|callable $message = null, string $propertyPath = null) Assert that the count of countable is equal to count for all values. + * @method static bool allDate(string[] $value, string $format, string|callable $message = null, string $propertyPath = null) Assert that date is valid and corresponds to the given format for all values. + * @method static bool allDefined(mixed[] $constant, string|callable $message = null, string $propertyPath = null) Assert that a constant is defined for all values. + * @method static bool allDigit(mixed[] $value, string|callable $message = null, string $propertyPath = null) Validates if an integer or integerish is a digit for all values. + * @method static bool allDirectory(string[] $value, string|callable $message = null, string $propertyPath = null) Assert that a directory exists for all values. + * @method static bool allE164(string[] $value, string|callable $message = null, string $propertyPath = null) Assert that the given string is a valid E164 Phone Number for all values. + * @method static bool allEmail(mixed[] $value, string|callable $message = null, string $propertyPath = null) Assert that value is an email address (using input_filter/FILTER_VALIDATE_EMAIL) for all values. + * @method static bool allEndsWith(mixed[] $string, string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string ends with a sequence of chars for all values. + * @method static bool allEq(mixed[] $value, mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that two values are equal (using ==) for all values. + * @method static bool allEqArraySubset(mixed[] $value, mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that the array contains the subset for all values. + * @method static bool allExtensionLoaded(mixed[] $value, string|callable $message = null, string $propertyPath = null) Assert that extension is loaded for all values. + * @method static bool allExtensionVersion(string[] $extension, string $operator, mixed $version, string|callable $message = null, string $propertyPath = null) Assert that extension is loaded and a specific version is installed for all values. + * @method static bool allFalse(mixed[] $value, string|callable $message = null, string $propertyPath = null) Assert that the value is boolean False for all values. + * @method static bool allFile(string[] $value, string|callable $message = null, string $propertyPath = null) Assert that a file exists for all values. + * @method static bool allFloat(mixed[] $value, string|callable $message = null, string $propertyPath = null) Assert that value is a php float for all values. + * @method static bool allGreaterOrEqualThan(mixed[] $value, mixed $limit, string|callable $message = null, string $propertyPath = null) Determines if the value is greater or equal than given limit for all values. + * @method static bool allGreaterThan(mixed[] $value, mixed $limit, string|callable $message = null, string $propertyPath = null) Determines if the value is greater than given limit for all values. + * @method static bool allImplementsInterface(mixed[] $class, string $interfaceName, string|callable $message = null, string $propertyPath = null) Assert that the class implements the interface for all values. + * @method static bool allInArray(mixed[] $value, array $choices, string|callable $message = null, string $propertyPath = null) Assert that value is in array of choices. This is an alias of Assertion::choice() for all values. + * @method static bool allInteger(mixed[] $value, string|callable $message = null, string $propertyPath = null) Assert that value is a php integer for all values. + * @method static bool allIntegerish(mixed[] $value, string|callable $message = null, string $propertyPath = null) Assert that value is a php integer'ish for all values. + * @method static bool allInterfaceExists(mixed[] $value, string|callable $message = null, string $propertyPath = null) Assert that the interface exists for all values. + * @method static bool allIp(string[] $value, int $flag = null, string|callable $message = null, string $propertyPath = null) Assert that value is an IPv4 or IPv6 address for all values. + * @method static bool allIpv4(string[] $value, int $flag = null, string|callable $message = null, string $propertyPath = null) Assert that value is an IPv4 address for all values. + * @method static bool allIpv6(string[] $value, int $flag = null, string|callable $message = null, string $propertyPath = null) Assert that value is an IPv6 address for all values. + * @method static bool allIsArray(mixed[] $value, string|callable $message = null, string $propertyPath = null) Assert that value is an array for all values. + * @method static bool allIsArrayAccessible(mixed[] $value, string|callable $message = null, string $propertyPath = null) Assert that value is an array or an array-accessible object for all values. + * @method static bool allIsCallable(mixed[] $value, string|callable $message = null, string $propertyPath = null) Determines that the provided value is callable for all values. + * @method static bool allIsCountable(array[]|Countable[]|ResourceBundle[]|SimpleXMLElement[] $value, string|callable $message = null, string $propertyPath = null) Assert that value is countable for all values. + * @method static bool allIsInstanceOf(mixed[] $value, string $className, string|callable $message = null, string $propertyPath = null) Assert that value is instance of given class-name for all values. + * @method static bool allIsJsonString(mixed[] $value, string|callable $message = null, string $propertyPath = null) Assert that the given string is a valid json string for all values. + * @method static bool allIsObject(mixed[] $value, string|callable $message = null, string $propertyPath = null) Determines that the provided value is an object for all values. + * @method static bool allIsResource(mixed[] $value, string|callable $message = null, string $propertyPath = null) Assert that value is a resource for all values. + * @method static bool allIsTraversable(mixed[] $value, string|callable $message = null, string $propertyPath = null) Assert that value is an array or a traversable object for all values. + * @method static bool allKeyExists(mixed[] $value, string|int $key, string|callable $message = null, string $propertyPath = null) Assert that key exists in an array for all values. + * @method static bool allKeyIsset(mixed[] $value, string|int $key, string|callable $message = null, string $propertyPath = null) Assert that key exists in an array/array-accessible object using isset() for all values. + * @method static bool allKeyNotExists(mixed[] $value, string|int $key, string|callable $message = null, string $propertyPath = null) Assert that key does not exist in an array for all values. + * @method static bool allLength(mixed[] $value, int $length, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string has a given length for all values. + * @method static bool allLessOrEqualThan(mixed[] $value, mixed $limit, string|callable $message = null, string $propertyPath = null) Determines if the value is less or equal than given limit for all values. + * @method static bool allLessThan(mixed[] $value, mixed $limit, string|callable $message = null, string $propertyPath = null) Determines if the value is less than given limit for all values. + * @method static bool allMax(mixed[] $value, mixed $maxValue, string|callable $message = null, string $propertyPath = null) Assert that a number is smaller as a given limit for all values. + * @method static bool allMaxCount(array[]|Countable[]|ResourceBundle[]|SimpleXMLElement[] $countable, int $count, string|callable $message = null, string $propertyPath = null) Assert that the countable have at most $count elements for all values. + * @method static bool allMaxLength(mixed[] $value, int $maxLength, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string value is not longer than $maxLength chars for all values. + * @method static bool allMethodExists(string[] $value, mixed $object, string|callable $message = null, string $propertyPath = null) Determines that the named method is defined in the provided object for all values. + * @method static bool allMin(mixed[] $value, mixed $minValue, string|callable $message = null, string $propertyPath = null) Assert that a value is at least as big as a given limit for all values. + * @method static bool allMinCount(array[]|Countable[]|ResourceBundle[]|SimpleXMLElement[] $countable, int $count, string|callable $message = null, string $propertyPath = null) Assert that the countable have at least $count elements for all values. + * @method static bool allMinLength(mixed[] $value, int $minLength, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that a string is at least $minLength chars long for all values. + * @method static bool allNoContent(mixed[] $value, string|callable $message = null, string $propertyPath = null) Assert that value is empty for all values. + * @method static bool allNotBlank(mixed[] $value, string|callable $message = null, string $propertyPath = null) Assert that value is not blank for all values. + * @method static bool allNotContains(mixed[] $string, string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string does not contains a sequence of chars for all values. + * @method static bool allNotEmpty(mixed[] $value, string|callable $message = null, string $propertyPath = null) Assert that value is not empty for all values. + * @method static bool allNotEmptyKey(mixed[] $value, string|int $key, string|callable $message = null, string $propertyPath = null) Assert that key exists in an array/array-accessible object and its value is not empty for all values. + * @method static bool allNotEq(mixed[] $value1, mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that two values are not equal (using ==) for all values. + * @method static bool allNotInArray(mixed[] $value, array $choices, string|callable $message = null, string $propertyPath = null) Assert that value is not in array of choices for all values. + * @method static bool allNotIsInstanceOf(mixed[] $value, string $className, string|callable $message = null, string $propertyPath = null) Assert that value is not instance of given class-name for all values. + * @method static bool allNotNull(mixed[] $value, string|callable $message = null, string $propertyPath = null) Assert that value is not null for all values. + * @method static bool allNotRegex(mixed[] $value, string $pattern, string|callable $message = null, string $propertyPath = null) Assert that value does not match a regex for all values. + * @method static bool allNotSame(mixed[] $value1, mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that two values are not the same (using ===) for all values. + * @method static bool allNull(mixed[] $value, string|callable $message = null, string $propertyPath = null) Assert that value is null for all values. + * @method static bool allNumeric(mixed[] $value, string|callable $message = null, string $propertyPath = null) Assert that value is numeric for all values. + * @method static bool allObjectOrClass(mixed[] $value, string|callable $message = null, string $propertyPath = null) Assert that the value is an object, or a class that exists for all values. + * @method static bool allPhpVersion(string[] $operator, mixed $version, string|callable $message = null, string $propertyPath = null) Assert on PHP version for all values. + * @method static bool allPropertiesExist(mixed[] $value, array $properties, string|callable $message = null, string $propertyPath = null) Assert that the value is an object or class, and that the properties all exist for all values. + * @method static bool allPropertyExists(mixed[] $value, string $property, string|callable $message = null, string $propertyPath = null) Assert that the value is an object or class, and that the property exists for all values. + * @method static bool allRange(mixed[] $value, mixed $minValue, mixed $maxValue, string|callable $message = null, string $propertyPath = null) Assert that value is in range of numbers for all values. + * @method static bool allReadable(string[] $value, string|callable $message = null, string $propertyPath = null) Assert that the value is something readable for all values. + * @method static bool allRegex(mixed[] $value, string $pattern, string|callable $message = null, string $propertyPath = null) Assert that value matches a regex for all values. + * @method static bool allSame(mixed[] $value, mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that two values are the same (using ===) for all values. + * @method static bool allSatisfy(mixed[] $value, callable $callback, string|callable $message = null, string $propertyPath = null) Assert that the provided value is valid according to a callback for all values. + * @method static bool allScalar(mixed[] $value, string|callable $message = null, string $propertyPath = null) Assert that value is a PHP scalar for all values. + * @method static bool allStartsWith(mixed[] $string, string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string starts with a sequence of chars for all values. + * @method static bool allString(mixed[] $value, string|callable $message = null, string $propertyPath = null) Assert that value is a string for all values. + * @method static bool allSubclassOf(mixed[] $value, string $className, string|callable $message = null, string $propertyPath = null) Assert that value is subclass of given class-name for all values. + * @method static bool allTrue(mixed[] $value, string|callable $message = null, string $propertyPath = null) Assert that the value is boolean True for all values. + * @method static bool allUrl(mixed[] $value, string|callable $message = null, string $propertyPath = null) Assert that value is an URL for all values. + * @method static bool allUuid(string[] $value, string|callable $message = null, string $propertyPath = null) Assert that the given string is a valid UUID for all values. + * @method static bool allVersion(string[] $version1, string $operator, string $version2, string|callable $message = null, string $propertyPath = null) Assert comparison of two versions for all values. + * @method static bool allWriteable(string[] $value, string|callable $message = null, string $propertyPath = null) Assert that the value is something writeable for all values. * @method static bool nullOrAlnum(mixed|null $value, string|callable $message = null, string $propertyPath = null) Assert that value is alphanumeric or that the value is null. * @method static bool nullOrBase64(string|null $value, string|callable $message = null, string $propertyPath = null) Assert that a constant is defined or that the value is null. * @method static bool nullOrBetween(mixed|null $value, mixed $lowerLimit, mixed $upperLimit, string|callable $message = null, string $propertyPath = null) Assert that a value is greater or equal than a lower limit, and less than or equal to an upper limit or that the value is null. @@ -2745,7 +2745,7 @@ public static function base64($value, $message = null, string $propertyPath = nu * * @return mixed */ - protected static function createException($value, $message, $code, string $propertyPath = null, array $constraints = []) + protected static function createException($value, $message, $code, $propertyPath = null, array $constraints = []) { $exceptionClass = static::$exceptionClass; @@ -2768,8 +2768,8 @@ protected static function stringify($value): string } elseif (\is_scalar($value)) { $val = (string)$value; - if (\strlen($val) > 100) { - $val = \substr($val, 0, 97).'...'; + if (\mb_strlen($val) > 100) { + $val = \mb_substr($val, 0, 97).'...'; } $result = $val; diff --git a/lib/Assert/LazyAssertion.php b/lib/Assert/LazyAssertion.php index 9301c6b4..6ccd6423 100644 --- a/lib/Assert/LazyAssertion.php +++ b/lib/Assert/LazyAssertion.php @@ -21,96 +21,96 @@ * * @author Benjamin Eberlei * - * @method $this alnum(string|callable $message = null, string $propertyPath = null) Assert that value is alphanumeric. - * @method $this base64(string|callable $message = null, string $propertyPath = null) Assert that a constant is defined. - * @method $this between(mixed $lowerLimit, mixed $upperLimit, string|callable $message = null, string $propertyPath = null) Assert that a value is greater or equal than a lower limit, and less than or equal to an upper limit. - * @method $this betweenExclusive(mixed $lowerLimit, mixed $upperLimit, string|callable $message = null, string $propertyPath = null) Assert that a value is greater than a lower limit, and less than an upper limit. - * @method $this betweenLength(int $minLength, int $maxLength, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string length is between min and max lengths. - * @method $this boolean(string|callable $message = null, string $propertyPath = null) Assert that value is php boolean. - * @method $this choice(array $choices, string|callable $message = null, string $propertyPath = null) Assert that value is in array of choices. - * @method $this choicesNotEmpty(array $choices, string|callable $message = null, string $propertyPath = null) Determines if the values array has every choice as key and that this choice has content. - * @method $this classExists(string|callable $message = null, string $propertyPath = null) Assert that the class exists. - * @method $this contains(string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string contains a sequence of chars. - * @method $this count(int $count, string|callable $message = null, string $propertyPath = null) Assert that the count of countable is equal to count. - * @method $this date(string $format, string|callable $message = null, string $propertyPath = null) Assert that date is valid and corresponds to the given format. - * @method $this defined(string|callable $message = null, string $propertyPath = null) Assert that a constant is defined. - * @method $this digit(string|callable $message = null, string $propertyPath = null) Validates if an integer or integerish is a digit. - * @method $this directory(string|callable $message = null, string $propertyPath = null) Assert that a directory exists. - * @method $this e164(string|callable $message = null, string $propertyPath = null) Assert that the given string is a valid E164 Phone Number. - * @method $this email(string|callable $message = null, string $propertyPath = null) Assert that value is an email address (using input_filter/FILTER_VALIDATE_EMAIL). - * @method $this endsWith(string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string ends with a sequence of chars. - * @method $this eq(mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that two values are equal (using ==). - * @method $this eqArraySubset(mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that the array contains the subset. - * @method $this extensionLoaded(string|callable $message = null, string $propertyPath = null) Assert that extension is loaded. - * @method $this extensionVersion(string $operator, mixed $version, string|callable $message = null, string $propertyPath = null) Assert that extension is loaded and a specific version is installed. - * @method $this false(string|callable $message = null, string $propertyPath = null) Assert that the value is boolean False. - * @method $this file(string|callable $message = null, string $propertyPath = null) Assert that a file exists. - * @method $this float(string|callable $message = null, string $propertyPath = null) Assert that value is a php float. - * @method $this greaterOrEqualThan(mixed $limit, string|callable $message = null, string $propertyPath = null) Determines if the value is greater or equal than given limit. - * @method $this greaterThan(mixed $limit, string|callable $message = null, string $propertyPath = null) Determines if the value is greater than given limit. - * @method $this implementsInterface(string $interfaceName, string|callable $message = null, string $propertyPath = null) Assert that the class implements the interface. - * @method $this inArray(array $choices, string|callable $message = null, string $propertyPath = null) Assert that value is in array of choices. This is an alias of Assertion::choice(). - * @method $this integer(string|callable $message = null, string $propertyPath = null) Assert that value is a php integer. - * @method $this integerish(string|callable $message = null, string $propertyPath = null) Assert that value is a php integer'ish. - * @method $this interfaceExists(string|callable $message = null, string $propertyPath = null) Assert that the interface exists. - * @method $this ip(int $flag = null, string|callable $message = null, string $propertyPath = null) Assert that value is an IPv4 or IPv6 address. - * @method $this ipv4(int $flag = null, string|callable $message = null, string $propertyPath = null) Assert that value is an IPv4 address. - * @method $this ipv6(int $flag = null, string|callable $message = null, string $propertyPath = null) Assert that value is an IPv6 address. - * @method $this isArray(string|callable $message = null, string $propertyPath = null) Assert that value is an array. - * @method $this isArrayAccessible(string|callable $message = null, string $propertyPath = null) Assert that value is an array or an array-accessible object. - * @method $this isCallable(string|callable $message = null, string $propertyPath = null) Determines that the provided value is callable. - * @method $this isCountable(string|callable $message = null, string $propertyPath = null) Assert that value is countable. - * @method $this isInstanceOf(string $className, string|callable $message = null, string $propertyPath = null) Assert that value is instance of given class-name. - * @method $this isJsonString(string|callable $message = null, string $propertyPath = null) Assert that the given string is a valid json string. - * @method $this isObject(string|callable $message = null, string $propertyPath = null) Determines that the provided value is an object. - * @method $this isResource(string|callable $message = null, string $propertyPath = null) Assert that value is a resource. - * @method $this isTraversable(string|callable $message = null, string $propertyPath = null) Assert that value is an array or a traversable object. - * @method $this keyExists(string|int $key, string|callable $message = null, string $propertyPath = null) Assert that key exists in an array. - * @method $this keyIsset(string|int $key, string|callable $message = null, string $propertyPath = null) Assert that key exists in an array/array-accessible object using isset(). - * @method $this keyNotExists(string|int $key, string|callable $message = null, string $propertyPath = null) Assert that key does not exist in an array. - * @method $this length(int $length, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string has a given length. - * @method $this lessOrEqualThan(mixed $limit, string|callable $message = null, string $propertyPath = null) Determines if the value is less or equal than given limit. - * @method $this lessThan(mixed $limit, string|callable $message = null, string $propertyPath = null) Determines if the value is less than given limit. - * @method $this max(mixed $maxValue, string|callable $message = null, string $propertyPath = null) Assert that a number is smaller as a given limit. - * @method $this maxCount(int $count, string|callable $message = null, string $propertyPath = null) Assert that the countable have at most $count elements. - * @method $this maxLength(int $maxLength, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string value is not longer than $maxLength chars. - * @method $this methodExists(mixed $object, string|callable $message = null, string $propertyPath = null) Determines that the named method is defined in the provided object. - * @method $this min(mixed $minValue, string|callable $message = null, string $propertyPath = null) Assert that a value is at least as big as a given limit. - * @method $this minCount(int $count, string|callable $message = null, string $propertyPath = null) Assert that the countable have at least $count elements. - * @method $this minLength(int $minLength, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that a string is at least $minLength chars long. - * @method $this noContent(string|callable $message = null, string $propertyPath = null) Assert that value is empty. - * @method $this notBlank(string|callable $message = null, string $propertyPath = null) Assert that value is not blank. - * @method $this notContains(string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string does not contains a sequence of chars. - * @method $this notEmpty(string|callable $message = null, string $propertyPath = null) Assert that value is not empty. - * @method $this notEmptyKey(string|int $key, string|callable $message = null, string $propertyPath = null) Assert that key exists in an array/array-accessible object and its value is not empty. - * @method $this notEq(mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that two values are not equal (using ==). - * @method $this notInArray(array $choices, string|callable $message = null, string $propertyPath = null) Assert that value is not in array of choices. - * @method $this notIsInstanceOf(string $className, string|callable $message = null, string $propertyPath = null) Assert that value is not instance of given class-name. - * @method $this notNull(string|callable $message = null, string $propertyPath = null) Assert that value is not null. - * @method $this notRegex(string $pattern, string|callable $message = null, string $propertyPath = null) Assert that value does not match a regex. - * @method $this notSame(mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that two values are not the same (using ===). - * @method $this null(string|callable $message = null, string $propertyPath = null) Assert that value is null. - * @method $this numeric(string|callable $message = null, string $propertyPath = null) Assert that value is numeric. - * @method $this objectOrClass(string|callable $message = null, string $propertyPath = null) Assert that the value is an object, or a class that exists. - * @method $this phpVersion(mixed $version, string|callable $message = null, string $propertyPath = null) Assert on PHP version. - * @method $this propertiesExist(array $properties, string|callable $message = null, string $propertyPath = null) Assert that the value is an object or class, and that the properties all exist. - * @method $this propertyExists(string $property, string|callable $message = null, string $propertyPath = null) Assert that the value is an object or class, and that the property exists. - * @method $this range(mixed $minValue, mixed $maxValue, string|callable $message = null, string $propertyPath = null) Assert that value is in range of numbers. - * @method $this readable(string|callable $message = null, string $propertyPath = null) Assert that the value is something readable. - * @method $this regex(string $pattern, string|callable $message = null, string $propertyPath = null) Assert that value matches a regex. - * @method $this same(mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that two values are the same (using ===). - * @method $this satisfy(callable $callback, string|callable $message = null, string $propertyPath = null) Assert that the provided value is valid according to a callback. - * @method $this scalar(string|callable $message = null, string $propertyPath = null) Assert that value is a PHP scalar. - * @method $this startsWith(string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string starts with a sequence of chars. - * @method $this string(string|callable $message = null, string $propertyPath = null) Assert that value is a string. - * @method $this subclassOf(string $className, string|callable $message = null, string $propertyPath = null) Assert that value is subclass of given class-name. - * @method $this true(string|callable $message = null, string $propertyPath = null) Assert that the value is boolean True. - * @method $this url(string|callable $message = null, string $propertyPath = null) Assert that value is an URL. - * @method $this uuid(string|callable $message = null, string $propertyPath = null) Assert that the given string is a valid UUID. - * @method $this version(string $operator, string $version2, string|callable $message = null, string $propertyPath = null) Assert comparison of two versions. - * @method $this writeable(string|callable $message = null, string $propertyPath = null) Assert that the value is something writeable. - * @method $this all() Switch chain into validation mode for an array of values. - * @method $this nullOr() Switch chain into mode allowing nulls, ignoring further assertions. + * @method LazyAssertion alnum(string|callable $message = null, string $propertyPath = null) Assert that value is alphanumeric. + * @method LazyAssertion base64(string|callable $message = null, string $propertyPath = null) Assert that a constant is defined. + * @method LazyAssertion between(mixed $lowerLimit, mixed $upperLimit, string|callable $message = null, string $propertyPath = null) Assert that a value is greater or equal than a lower limit, and less than or equal to an upper limit. + * @method LazyAssertion betweenExclusive(mixed $lowerLimit, mixed $upperLimit, string|callable $message = null, string $propertyPath = null) Assert that a value is greater than a lower limit, and less than an upper limit. + * @method LazyAssertion betweenLength(int $minLength, int $maxLength, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string length is between min and max lengths. + * @method LazyAssertion boolean(string|callable $message = null, string $propertyPath = null) Assert that value is php boolean. + * @method LazyAssertion choice(array $choices, string|callable $message = null, string $propertyPath = null) Assert that value is in array of choices. + * @method LazyAssertion choicesNotEmpty(array $choices, string|callable $message = null, string $propertyPath = null) Determines if the values array has every choice as key and that this choice has content. + * @method LazyAssertion classExists(string|callable $message = null, string $propertyPath = null) Assert that the class exists. + * @method LazyAssertion contains(string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string contains a sequence of chars. + * @method LazyAssertion count(int $count, string|callable $message = null, string $propertyPath = null) Assert that the count of countable is equal to count. + * @method LazyAssertion date(string $format, string|callable $message = null, string $propertyPath = null) Assert that date is valid and corresponds to the given format. + * @method LazyAssertion defined(string|callable $message = null, string $propertyPath = null) Assert that a constant is defined. + * @method LazyAssertion digit(string|callable $message = null, string $propertyPath = null) Validates if an integer or integerish is a digit. + * @method LazyAssertion directory(string|callable $message = null, string $propertyPath = null) Assert that a directory exists. + * @method LazyAssertion e164(string|callable $message = null, string $propertyPath = null) Assert that the given string is a valid E164 Phone Number. + * @method LazyAssertion email(string|callable $message = null, string $propertyPath = null) Assert that value is an email address (using input_filter/FILTER_VALIDATE_EMAIL). + * @method LazyAssertion endsWith(string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string ends with a sequence of chars. + * @method LazyAssertion eq(mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that two values are equal (using ==). + * @method LazyAssertion eqArraySubset(mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that the array contains the subset. + * @method LazyAssertion extensionLoaded(string|callable $message = null, string $propertyPath = null) Assert that extension is loaded. + * @method LazyAssertion extensionVersion(string $operator, mixed $version, string|callable $message = null, string $propertyPath = null) Assert that extension is loaded and a specific version is installed. + * @method LazyAssertion false(string|callable $message = null, string $propertyPath = null) Assert that the value is boolean False. + * @method LazyAssertion file(string|callable $message = null, string $propertyPath = null) Assert that a file exists. + * @method LazyAssertion float(string|callable $message = null, string $propertyPath = null) Assert that value is a php float. + * @method LazyAssertion greaterOrEqualThan(mixed $limit, string|callable $message = null, string $propertyPath = null) Determines if the value is greater or equal than given limit. + * @method LazyAssertion greaterThan(mixed $limit, string|callable $message = null, string $propertyPath = null) Determines if the value is greater than given limit. + * @method LazyAssertion implementsInterface(string $interfaceName, string|callable $message = null, string $propertyPath = null) Assert that the class implements the interface. + * @method LazyAssertion inArray(array $choices, string|callable $message = null, string $propertyPath = null) Assert that value is in array of choices. This is an alias of Assertion::choice(). + * @method LazyAssertion integer(string|callable $message = null, string $propertyPath = null) Assert that value is a php integer. + * @method LazyAssertion integerish(string|callable $message = null, string $propertyPath = null) Assert that value is a php integer'ish. + * @method LazyAssertion interfaceExists(string|callable $message = null, string $propertyPath = null) Assert that the interface exists. + * @method LazyAssertion ip(int $flag = null, string|callable $message = null, string $propertyPath = null) Assert that value is an IPv4 or IPv6 address. + * @method LazyAssertion ipv4(int $flag = null, string|callable $message = null, string $propertyPath = null) Assert that value is an IPv4 address. + * @method LazyAssertion ipv6(int $flag = null, string|callable $message = null, string $propertyPath = null) Assert that value is an IPv6 address. + * @method LazyAssertion isArray(string|callable $message = null, string $propertyPath = null) Assert that value is an array. + * @method LazyAssertion isArrayAccessible(string|callable $message = null, string $propertyPath = null) Assert that value is an array or an array-accessible object. + * @method LazyAssertion isCallable(string|callable $message = null, string $propertyPath = null) Determines that the provided value is callable. + * @method LazyAssertion isCountable(string|callable $message = null, string $propertyPath = null) Assert that value is countable. + * @method LazyAssertion isInstanceOf(string $className, string|callable $message = null, string $propertyPath = null) Assert that value is instance of given class-name. + * @method LazyAssertion isJsonString(string|callable $message = null, string $propertyPath = null) Assert that the given string is a valid json string. + * @method LazyAssertion isObject(string|callable $message = null, string $propertyPath = null) Determines that the provided value is an object. + * @method LazyAssertion isResource(string|callable $message = null, string $propertyPath = null) Assert that value is a resource. + * @method LazyAssertion isTraversable(string|callable $message = null, string $propertyPath = null) Assert that value is an array or a traversable object. + * @method LazyAssertion keyExists(string|int $key, string|callable $message = null, string $propertyPath = null) Assert that key exists in an array. + * @method LazyAssertion keyIsset(string|int $key, string|callable $message = null, string $propertyPath = null) Assert that key exists in an array/array-accessible object using isset(). + * @method LazyAssertion keyNotExists(string|int $key, string|callable $message = null, string $propertyPath = null) Assert that key does not exist in an array. + * @method LazyAssertion length(int $length, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string has a given length. + * @method LazyAssertion lessOrEqualThan(mixed $limit, string|callable $message = null, string $propertyPath = null) Determines if the value is less or equal than given limit. + * @method LazyAssertion lessThan(mixed $limit, string|callable $message = null, string $propertyPath = null) Determines if the value is less than given limit. + * @method LazyAssertion max(mixed $maxValue, string|callable $message = null, string $propertyPath = null) Assert that a number is smaller as a given limit. + * @method LazyAssertion maxCount(int $count, string|callable $message = null, string $propertyPath = null) Assert that the countable have at most $count elements. + * @method LazyAssertion maxLength(int $maxLength, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string value is not longer than $maxLength chars. + * @method LazyAssertion methodExists(mixed $object, string|callable $message = null, string $propertyPath = null) Determines that the named method is defined in the provided object. + * @method LazyAssertion min(mixed $minValue, string|callable $message = null, string $propertyPath = null) Assert that a value is at least as big as a given limit. + * @method LazyAssertion minCount(int $count, string|callable $message = null, string $propertyPath = null) Assert that the countable have at least $count elements. + * @method LazyAssertion minLength(int $minLength, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that a string is at least $minLength chars long. + * @method LazyAssertion noContent(string|callable $message = null, string $propertyPath = null) Assert that value is empty. + * @method LazyAssertion notBlank(string|callable $message = null, string $propertyPath = null) Assert that value is not blank. + * @method LazyAssertion notContains(string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string does not contains a sequence of chars. + * @method LazyAssertion notEmpty(string|callable $message = null, string $propertyPath = null) Assert that value is not empty. + * @method LazyAssertion notEmptyKey(string|int $key, string|callable $message = null, string $propertyPath = null) Assert that key exists in an array/array-accessible object and its value is not empty. + * @method LazyAssertion notEq(mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that two values are not equal (using ==). + * @method LazyAssertion notInArray(array $choices, string|callable $message = null, string $propertyPath = null) Assert that value is not in array of choices. + * @method LazyAssertion notIsInstanceOf(string $className, string|callable $message = null, string $propertyPath = null) Assert that value is not instance of given class-name. + * @method LazyAssertion notNull(string|callable $message = null, string $propertyPath = null) Assert that value is not null. + * @method LazyAssertion notRegex(string $pattern, string|callable $message = null, string $propertyPath = null) Assert that value does not match a regex. + * @method LazyAssertion notSame(mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that two values are not the same (using ===). + * @method LazyAssertion null(string|callable $message = null, string $propertyPath = null) Assert that value is null. + * @method LazyAssertion numeric(string|callable $message = null, string $propertyPath = null) Assert that value is numeric. + * @method LazyAssertion objectOrClass(string|callable $message = null, string $propertyPath = null) Assert that the value is an object, or a class that exists. + * @method LazyAssertion phpVersion(mixed $version, string|callable $message = null, string $propertyPath = null) Assert on PHP version. + * @method LazyAssertion propertiesExist(array $properties, string|callable $message = null, string $propertyPath = null) Assert that the value is an object or class, and that the properties all exist. + * @method LazyAssertion propertyExists(string $property, string|callable $message = null, string $propertyPath = null) Assert that the value is an object or class, and that the property exists. + * @method LazyAssertion range(mixed $minValue, mixed $maxValue, string|callable $message = null, string $propertyPath = null) Assert that value is in range of numbers. + * @method LazyAssertion readable(string|callable $message = null, string $propertyPath = null) Assert that the value is something readable. + * @method LazyAssertion regex(string $pattern, string|callable $message = null, string $propertyPath = null) Assert that value matches a regex. + * @method LazyAssertion same(mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that two values are the same (using ===). + * @method LazyAssertion satisfy(callable $callback, string|callable $message = null, string $propertyPath = null) Assert that the provided value is valid according to a callback. + * @method LazyAssertion scalar(string|callable $message = null, string $propertyPath = null) Assert that value is a PHP scalar. + * @method LazyAssertion startsWith(string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string starts with a sequence of chars. + * @method LazyAssertion string(string|callable $message = null, string $propertyPath = null) Assert that value is a string. + * @method LazyAssertion subclassOf(string $className, string|callable $message = null, string $propertyPath = null) Assert that value is subclass of given class-name. + * @method LazyAssertion true(string|callable $message = null, string $propertyPath = null) Assert that the value is boolean True. + * @method LazyAssertion url(string|callable $message = null, string $propertyPath = null) Assert that value is an URL. + * @method LazyAssertion uuid(string|callable $message = null, string $propertyPath = null) Assert that the given string is a valid UUID. + * @method LazyAssertion version(string $operator, string $version2, string|callable $message = null, string $propertyPath = null) Assert comparison of two versions. + * @method LazyAssertion writeable(string|callable $message = null, string $propertyPath = null) Assert that the value is something writeable. + * @method LazyAssertion all() Switch chain into validation mode for an array of values. + * @method LazyAssertion nullOr() Switch chain into mode allowing nulls, ignoring further assertions. */ class LazyAssertion { @@ -131,7 +131,7 @@ class LazyAssertion * @param string|null $propertyPath * @param string|callable|null $defaultMessage * - * @return $this + * @return static */ public function that($value, string $propertyPath = null, $defaultMessage = null) { @@ -144,7 +144,7 @@ public function that($value, string $propertyPath = null, $defaultMessage = null } /** - * @return $this + * @return static */ public function tryAll() { @@ -157,6 +157,12 @@ public function tryAll() return $this; } + /** + * @param string $method + * @param array $args + * + * @return static + */ public function __call($method, $args) { if (false === $this->alwaysTryAll @@ -193,9 +199,9 @@ public function verifyNow(): bool /** * @param string $className * - * @return $this + * @return static */ - public function setAssertClass(string $className): LazyAssertion + public function setAssertClass(string $className) { if (Assert::class !== $className && !\is_subclass_of($className, Assert::class)) { throw new LogicException($className.' is not (a subclass of) '.Assert::class); @@ -209,9 +215,9 @@ public function setAssertClass(string $className): LazyAssertion /** * @param string $className * - * @return $this + * @return static */ - public function setExceptionClass(string $className): LazyAssertion + public function setExceptionClass(string $className) { if (LazyAssertionException::class !== $className && !\is_subclass_of($className, LazyAssertionException::class)) { throw new LogicException($className.' is not (a subclass of) '.LazyAssertionException::class); diff --git a/tests/Assert/Tests/AssertTest.php b/tests/Assert/Tests/AssertTest.php index efb2a9a9..f989f0ad 100644 --- a/tests/Assert/Tests/AssertTest.php +++ b/tests/Assert/Tests/AssertTest.php @@ -14,18 +14,36 @@ namespace Assert\Tests; +use ArrayIterator; +use ArrayObject; use Assert\Assertion; -use Assert\AssertionFailedException; use Assert\Tests\Fixtures\OneCountable; -use PDO; +use BadMethodCallException; +use Countable; +use DateTime; +use Exception; +use Foo; +use InvalidArgumentException; use PHPUnit\Framework\TestCase; use ResourceBundle; use SimpleXMLElement; +use SplObserver; use stdClass; +use Traversable; +use function base64_encode; +use function curl_init; +use function extension_loaded; +use function fopen; +use function is_bool; +use function is_null; +use function json_encode; +use function range; +use function str_repeat; +use function sys_get_temp_dir; class AssertTest extends TestCase { - public static function dataInvalidFloat() + public function dataInvalidFloat(): array { return [ [1], @@ -56,7 +74,7 @@ public function testValidFloat() $this->assertTrue(Assertion::float(-1.1)); } - public static function dataInvalidInteger() + public function dataInvalidInteger(): array { return [ [1.23], @@ -65,7 +83,7 @@ public static function dataInvalidInteger() [null], ['1.23'], ['10'], - [new \DateTime()], + [new DateTime()], ]; } @@ -87,7 +105,7 @@ public function testValidInteger() $this->assertTrue(Assertion::integer(0)); } - public function dataValidIntergerish() + public function dataValidIntergerish(): array { return [ [10], @@ -117,7 +135,7 @@ public function testValidIntegerish($value) $this->assertTrue(Assertion::integerish($value)); } - public static function dataInvalidIntegerish() + public function dataInvalidIntegerish(): array { return [ 'A float' => [1.23], @@ -127,7 +145,7 @@ public static function dataInvalidIntegerish() 'A null' => [null], 'A float in a string' => ['1.23'], 'A negative float in a string' => ['-1.23'], - 'A file pointer' => [\fopen(__FILE__, 'r')], + 'A file pointer' => [fopen(__FILE__, 'r')], 'A float in a string with a leading space' => [' 1.23'], 'An integer in a string with a leading space' => [' 123'], 'A negative integer in a string with a leading space' => [' -123'], @@ -191,7 +209,7 @@ public function testValidScalar() $this->assertTrue(Assertion::scalar(false)); } - public static function dataInvalidNotEmpty() + public function dataInvalidNotEmpty(): array { return [ [''], @@ -230,7 +248,7 @@ public function testEmpty() $this->assertTrue(Assertion::noContent([])); } - public static function dataInvalidEmpty() + public function dataInvalidEmpty(): array { return [ ['foo'], @@ -253,7 +271,7 @@ public function testInvalidEmpty($value) Assertion::noContent($value); } - public static function dataInvalidNull() + public function dataInvalidNull(): array { return [ ['foo'], @@ -318,12 +336,12 @@ public function testInvalidString($invalidString) Assertion::string($invalidString); } - public static function dataInvalidString() + public function dataInvalidString(): array { return [ [1.23], [false], - [new \ArrayObject()], + [new ArrayObject()], [null], [10], [true], @@ -552,7 +570,7 @@ public function testValidNumeric() $this->assertTrue(Assertion::numeric(1.23)); } - public static function dataInvalidArray() + public function dataInvalidArray(): array { return [ [null], @@ -561,7 +579,7 @@ public static function dataInvalidArray() [1], [1.23], [new stdClass()], - [\fopen('php://memory', 'r')], + [fopen('php://memory', 'r')], ]; } @@ -612,7 +630,7 @@ public function testValidKeyNotExists() $this->assertTrue(Assertion::keyNotExists(['foo' => 'bar'], 'baz')); } - public static function dataInvalidNotBlank() + public function dataInvalidNotBlank(): array { return [ [''], @@ -654,7 +672,13 @@ public function testInvalidNotInstanceOf() public function testValidNotIsInstanceOf() { - $this->assertTrue(Assertion::notIsInstanceOf(new stdClass(), PDO::class)); + $this->assertTrue( + Assertion::notIsInstanceOf( + new stdClass(), + new class() { + } + ) + ); } /** @@ -663,7 +687,15 @@ public function testValidNotIsInstanceOf() */ public function testInvalidInstanceOf() { - Assertion::isInstanceOf(new stdClass(), PDO::class); + Assertion::isInstanceOf( + new stdClass(), + new class() { + public function __toString(): string + { + return 'Anonymous'; + } + } + ); } public function testValidInstanceOf() @@ -677,7 +709,15 @@ public function testValidInstanceOf() */ public function testInvalidSubclassOf() { - Assertion::subclassOf(new stdClass(), PDO::class); + Assertion::subclassOf( + new stdClass(), + new class() { + public function __toString(): string + { + return 'Anonymous'; + } + } + ); } public function testValidSubclassOf() @@ -729,7 +769,7 @@ public function testInvalidUrl($url) Assertion::url($url); } - public static function dataInvalidUrl() + public function dataInvalidUrl(): array { return [ ['google.com'], @@ -762,7 +802,7 @@ public function testValidUrl($url) $this->assertTrue(Assertion::url($url)); } - public static function dataValidUrl() + public function dataValidUrl(): array { return [ ['http://a.pl'], @@ -903,12 +943,12 @@ public function testInvalidFalse() */ public function testInvalidClass() { - Assertion::classExists(\Foo::class); + Assertion::classExists(Foo::class); } public function testValidClass() { - $this->assertTrue(Assertion::classExists(\Exception::class)); + $this->assertTrue(Assertion::classExists(Exception::class)); } /** @@ -967,10 +1007,10 @@ public function testNotSame() */ public function testNotInArray() { - $this->assertTrue(Assertion::notInArray(6, \range(1, 5))); - $this->assertTrue(Assertion::notInArray('a', \range('b', 'z'))); + $this->assertTrue(Assertion::notInArray(6, range(1, 5))); + $this->assertTrue(Assertion::notInArray('a', range('b', 'z'))); - Assertion::notInArray(1, \range(1, 5)); + Assertion::notInArray(1, range(1, 5)); } public function testMin() @@ -994,7 +1034,7 @@ public function testInvalidMin($value, $min) Assertion::min($value, $min); } - public function dataInvalidMin() + public function dataInvalidMin(): array { return [ [0, 1], @@ -1023,7 +1063,7 @@ public function testInvalidMax($value, $min) Assertion::max($value, $min); } - public function dataInvalidMax() + public function dataInvalidMax(): array { return [ [2, 1], @@ -1038,7 +1078,7 @@ public function testNullOr() } /** - * @expectedException \BadMethodCallException + * @expectedException BadMethodCallException * @expectedExceptionMessage Missing the first argument. */ public function testNullOrWithNoValueThrows() @@ -1052,7 +1092,7 @@ public function testLength() $this->assertTrue(Assertion::length('', 0)); } - public static function dataLengthUtf8Characters() + public function dataLengthUtf8Characters(): array { return [ ['址', 1], @@ -1145,13 +1185,13 @@ public function testReadable() */ public function testWriteable() { - $this->assertTrue(Assertion::writeable(\sys_get_temp_dir())); + $this->assertTrue(Assertion::writeable(sys_get_temp_dir())); Assertion::writeable(__DIR__.'/does-not-exist'); } /** - * @expectedException \BadMethodCallException + * @expectedException BadMethodCallException * @expectedExceptionMessage No assertion */ public function testFailedNullOrMethodCall() @@ -1165,9 +1205,9 @@ public function testFailedNullOrMethodCall() */ public function testImplementsInterface() { - $this->assertTrue(Assertion::implementsInterface(\ArrayIterator::class, \Traversable::class)); + $this->assertTrue(Assertion::implementsInterface(ArrayIterator::class, Traversable::class)); - Assertion::implementsInterface(\Exception::class, \Traversable::class); + Assertion::implementsInterface(Exception::class, Traversable::class); } /** @@ -1176,11 +1216,11 @@ public function testImplementsInterface() */ public function testImplementsInterfaceWithClassObject() { - $class = new \ArrayObject(); + $class = new ArrayObject(); - $this->assertTrue(Assertion::implementsInterface($class, \Traversable::class)); + $this->assertTrue(Assertion::implementsInterface($class, Traversable::class)); - Assertion::implementsInterface($class, \SplObserver::class); + Assertion::implementsInterface($class, SplObserver::class); } /** @@ -1190,9 +1230,9 @@ public function testImplementsInterfaceWithClassObject() */ public function testImplementsInterfaceThrowsExceptionForInvalidSubject() { - $this->assertTrue(Assertion::implementsInterface('not_a_class', \Traversable::class)); + $this->assertTrue(Assertion::implementsInterface('not_a_class', Traversable::class)); - Assertion::implementsInterface(\Exception::class, \Traversable::class); + Assertion::implementsInterface(Exception::class, Traversable::class); } /** @@ -1205,11 +1245,11 @@ public function testIsJsonString($content) $this->assertTrue(Assertion::isJsonString($content)); } - public static function isJsonStringDataprovider() + public function isJsonStringDataprovider(): array { return [ - '»null« value' => [\json_encode(null)], - '»false« value' => [\json_encode(false)], + '»null« value' => [json_encode(null)], + '»false« value' => [json_encode(false)], 'array value' => ['["false"]'], 'object value' => ['{"tux":"false"}'], ]; @@ -1227,7 +1267,7 @@ public function testIsJsonStringExpectingException($invalidString) Assertion::isJsonString($invalidString); } - public static function isJsonStringInvalidStringDataprovider() + public function isJsonStringInvalidStringDataprovider(): array { return [ 'no json string' => ['invalid json encoded string'], @@ -1257,7 +1297,7 @@ public function testInvalidUuids($uuid) Assertion::uuid($uuid); } - public static function providesValidUuids() + public function providesValidUuids(): array { return [ ['ff6f8cb0-c57d-11e1-9b21-0800200c9a66'], @@ -1270,7 +1310,7 @@ public static function providesValidUuids() ]; } - public static function providesInvalidUuids() + public function providesInvalidUuids(): array { return [ ['zf6f8cb0-c57d-11e1-9b21-0800200c9a66'], @@ -1303,7 +1343,7 @@ public function testInvalidE164s($e164) Assertion::e164($e164); } - public static function providesValidE164s() + public function providesValidE164s(): array { return [ ['+33626525690'], @@ -1312,7 +1352,7 @@ public static function providesValidE164s() ]; } - public static function providesInvalidE164s() + public function providesInvalidE164s(): array { return [ ['+3362652569e'], @@ -1368,11 +1408,17 @@ public function testAllWithComplexAssertion() */ public function testAllWithComplexAssertionThrowsExceptionOnElementThatFailsAssertion() { - Assertion::allIsInstanceOf([new stdClass(), new stdClass()], PDO::class, 'Assertion failed', 'foos'); + Assertion::allIsInstanceOf( + [new stdClass(), new stdClass()], + new class() { + }, + 'Assertion failed', + 'foos' + ); } /** - * @expectedException \BadMethodCallException + * @expectedException BadMethodCallException */ public function testAllWithNoValueThrows() { @@ -1385,12 +1431,19 @@ public function testValidCount() $this->assertTrue(Assertion::count(['Hi', 'There'], 2)); $this->assertTrue(Assertion::count(new Fixtures\OneCountable(), 1)); $this->assertTrue(Assertion::count(new SimpleXMLElement(''), 2)); + } + + /** + * @requires extension intl + */ + public function testValidCountWithIntlResourceBundle() + { // Test ResourceBundle counting using resources generated for PHP testing of ResourceBundle // https://github.com/php/php-src/commit/8f4337f2551e28d98290752e9ca99fc7f87d93b5 $this->assertTrue(Assertion::count(new ResourceBundle('en_US', __DIR__.'/_files/ResourceBundle'), 6)); } - public static function dataInvalidCount() + public function dataInvalidCount(): array { return [ [['Hi', 'There'], 3], @@ -1420,17 +1473,24 @@ public function testValidMinCount() $this->assertTrue(Assertion::minCount(['Hi', 'There'], 1)); $this->assertTrue(Assertion::minCount(new Fixtures\OneCountable(), 1)); $this->assertTrue(Assertion::minCount(new SimpleXMLElement(''), 1)); + } + + /** + * @requires extension intl + */ + public function testValidMinCountWithIntlResourceBundle() + { $this->assertTrue(Assertion::minCount(new ResourceBundle('en_US', __DIR__.'/_files/ResourceBundle'), 2)); } - public static function dataInvalidMinCount() + public function dataInvalidMinCount(): \Generator { - return [ - '2 elements while at least 3 expected' => [['Hi', 'There'], 3], - '1 countable while at least 2 expected' => [new Fixtures\OneCountable(), 2], - '2 countable while at least 3 expected' => [new SimpleXMLElement(''), 3], - '6 countable while at least 7 expected' => [new ResourceBundle('en_US', __DIR__.'/_files/ResourceBundle'), 7], - ]; + yield '2 elements while at least 3 expected' => [['Hi', 'There'], 3]; + yield '1 countable while at least 2 expected' => [new Fixtures\OneCountable(), 2]; + yield '2 countable while at least 3 expected' => [new SimpleXMLElement(''), 3]; + if (extension_loaded('intl')) { + yield '6 countable while at least 7 expected' => [new ResourceBundle('en_US', __DIR__.'/_files/ResourceBundle'), 7]; + } } /** @@ -1453,17 +1513,24 @@ public function testValidMaxCount() $this->assertTrue(Assertion::maxCount(['Hi', 'There'], 2)); $this->assertTrue(Assertion::maxCount(new Fixtures\OneCountable(), 1)); $this->assertTrue(Assertion::maxCount(new SimpleXMLElement(''), 3)); + } + + /** + * @requires extension intl + */ + public function testValidMaxCountWithIntlResourceBundle() + { $this->assertTrue(Assertion::maxCount(new ResourceBundle('en_US', __DIR__.'/_files/ResourceBundle'), 7)); } - public static function dataInvalidMaxCount() + public function dataInvalidMaxCount(): \Generator { - return [ - '2 elements while at most 1 expected' => [['Hi', 'There'], 1], - '1 countable while at most 0 expected' => [new Fixtures\OneCountable(), 0], - '2 countable while at most 1 expected' => [new SimpleXMLElement(''), 1], - '6 countable while at most 5 expected' => [new ResourceBundle('en_US', __DIR__.'/_files/ResourceBundle'), 5], - ]; + yield '2 elements while at most 1 expected' => [['Hi', 'There'], 1]; + yield '1 countable while at most 0 expected' => [new Fixtures\OneCountable(), 0]; + yield '2 countable while at most 1 expected' => [new SimpleXMLElement(''), 1]; + if (extension_loaded('intl')) { + yield '6 countable while at most 5 expected' => [new ResourceBundle('en_US', __DIR__.'/_files/ResourceBundle'), 5]; + } } /** @@ -1509,7 +1576,7 @@ public function testChoicesNotEmptyExpectingExceptionInvalidKeyIsset() Assertion::choicesNotEmpty(['tux' => ''], ['invalidChoice']); } - public function invalidChoicesProvider() + public function invalidChoicesProvider(): array { return [ 'empty values' => [[], ['tux'], Assertion::VALUE_EMPTY], @@ -1551,7 +1618,7 @@ public function testThatAssertionExceptionCanAccessValueAndSupplyConstraints() Assertion::range(0, 10, 20); $this->fail('Exception expected'); - } catch (AssertionFailedException $e) { + } catch (\Assert\AssertionFailedException $e) { $this->assertEquals(0, $e->getValue()); $this->assertEquals(['min' => 10, 'max' => 20], $e->getConstraints()); } @@ -1562,18 +1629,18 @@ public function testLessThan() $this->assertTrue(Assertion::lessThan(1, 2)); $this->assertTrue(Assertion::lessThan('aaa', 'bbb')); $this->assertTrue(Assertion::lessThan('aaa', 'aaaa')); - $this->assertTrue(Assertion::lessThan(new \DateTime('today'), new \DateTime('tomorrow'))); + $this->assertTrue(Assertion::lessThan(new DateTime('today'), new DateTime('tomorrow'))); } - public function invalidLessProvider() + public function invalidLessProvider(): array { return [ [2, 1], [2, 2], ['aaa', 'aaa'], ['aaaa', 'aaa'], - [new \DateTime('today'), new \DateTime('yesterday')], - [new \DateTime('today'), new \DateTime('today')], + [new DateTime('today'), new DateTime('yesterday')], + [new DateTime('today'), new DateTime('today')], ]; } @@ -1597,16 +1664,16 @@ public function testLessOrEqualThan() $this->assertTrue(Assertion::lessOrEqualThan('aaa', 'bbb')); $this->assertTrue(Assertion::lessOrEqualThan('aaa', 'aaaa')); $this->assertTrue(Assertion::lessOrEqualThan('aaa', 'aaa')); - $this->assertTrue(Assertion::lessOrEqualThan(new \DateTime('today'), new \DateTime('tomorrow'))); - $this->assertTrue(Assertion::lessOrEqualThan(new \DateTime('today'), new \DateTime('today'))); + $this->assertTrue(Assertion::lessOrEqualThan(new DateTime('today'), new DateTime('tomorrow'))); + $this->assertTrue(Assertion::lessOrEqualThan(new DateTime('today'), new DateTime('today'))); } - public function invalidLessOrEqualProvider() + public function invalidLessOrEqualProvider(): array { return [ [2, 1], ['aaaa', 'aaa'], - [new \DateTime('today'), new \DateTime('yesterday')], + [new DateTime('today'), new DateTime('yesterday')], ]; } @@ -1628,18 +1695,18 @@ public function testGreaterThan() $this->assertTrue(Assertion::greaterThan(2, 1)); $this->assertTrue(Assertion::greaterThan('bbb', 'aaa')); $this->assertTrue(Assertion::greaterThan('aaaa', 'aaa')); - $this->assertTrue(Assertion::greaterThan(new \DateTime('tomorrow'), new \DateTime('today'))); + $this->assertTrue(Assertion::greaterThan(new DateTime('tomorrow'), new DateTime('today'))); } - public function invalidGreaterProvider() + public function invalidGreaterProvider(): array { return [ [1, 2], [2, 2], ['aaa', 'aaa'], ['aaa', 'aaaa'], - [new \DateTime('yesterday'), new \DateTime('today')], - [new \DateTime('today'), new \DateTime('today')], + [new DateTime('yesterday'), new DateTime('today')], + [new DateTime('today'), new DateTime('today')], ]; } @@ -1654,7 +1721,7 @@ public function testValidDate($value, $format) $this->assertTrue(Assertion::date($value, $format)); } - public function validDateProvider() + public function validDateProvider(): array { return [ ['2012-03-13', 'Y-m-d'], @@ -1684,16 +1751,16 @@ public function testGreaterOrEqualThan() $this->assertTrue(Assertion::greaterOrEqualThan('bbb', 'aaa')); $this->assertTrue(Assertion::greaterOrEqualThan('aaaa', 'aaa')); $this->assertTrue(Assertion::greaterOrEqualThan('aaa', 'aaa')); - $this->assertTrue(Assertion::greaterOrEqualThan(new \DateTime('tomorrow'), new \DateTime('today'))); - $this->assertTrue(Assertion::greaterOrEqualThan(new \DateTime('today'), new \DateTime('today'))); + $this->assertTrue(Assertion::greaterOrEqualThan(new DateTime('tomorrow'), new DateTime('today'))); + $this->assertTrue(Assertion::greaterOrEqualThan(new DateTime('today'), new DateTime('today'))); } - public function invalidGreaterOrEqualProvider() + public function invalidGreaterOrEqualProvider(): array { return [ [1, 2], ['aaa', 'aaaa'], - [new \DateTime('yesterday'), new \DateTime('tomorrow')], + [new DateTime('yesterday'), new DateTime('tomorrow')], ]; } @@ -1723,7 +1790,7 @@ public function testInvalidDate($value, $format) Assertion::date($value, $format); } - public function invalidDateProvider() + public function invalidDateProvider(): array { return [ ['this is not the date', 'Y-m-d'], @@ -1734,7 +1801,7 @@ public function invalidDateProvider() public function testValidTraversable() { - $this->assertTrue(Assertion::isTraversable(new \ArrayObject())); + $this->assertTrue(Assertion::isTraversable(new ArrayObject())); } /** @@ -1749,7 +1816,7 @@ public function testInvalidTraversable() public function testValidCountable() { $this->assertTrue(Assertion::isCountable([])); - $this->assertTrue(Assertion::isCountable(new \ArrayObject())); + $this->assertTrue(Assertion::isCountable(new ArrayObject())); } /** @@ -1763,7 +1830,7 @@ public function testInvalidCountable() public function testValidArrayAccessible() { - $this->assertTrue(Assertion::isArrayAccessible(new \ArrayObject())); + $this->assertTrue(Assertion::isArrayAccessible(new ArrayObject())); } /** @@ -1805,8 +1872,8 @@ public function testInvalidSatisfy() { Assertion::satisfy( null, - function ($value) { - return !\is_null($value); + function ($value): bool { + return !is_null($value); } ); } @@ -1817,8 +1884,8 @@ public function testValidSatisfy() $this->assertTrue( Assertion::satisfy( null, - function ($value) { - return \is_null($value); + function ($value) : bool { + return is_null($value); } ) ); @@ -1827,8 +1894,11 @@ function ($value) { $this->assertTrue( Assertion::satisfy( true, + /** + * @return bool|void + */ function ($value) { - if (!\is_bool($value)) { + if (!is_bool($value)) { return false; } } @@ -1846,7 +1916,7 @@ public function testValidIp($value) $this->assertTrue(Assertion::ip($value)); } - public function validIpProvider() + public function validIpProvider(): array { return [ ['0.0.0.0'], @@ -1869,7 +1939,7 @@ public function testInvalidIp($value, $flag = null) Assertion::ip($value, $flag); } - public function invalidIpProvider() + public function invalidIpProvider(): array { return [ ['invalid ip address'], @@ -1921,7 +1991,7 @@ public function testInvalidInterfaceExists() public function testValidInterfaceExists() { - $this->assertTrue(Assertion::interfaceExists(\Countable::class)); + $this->assertTrue(Assertion::interfaceExists(Countable::class)); } /** @@ -1938,18 +2008,15 @@ public function testInvalidBetween($value, $lowerLimit, $upperLimit) Assertion::between($value, $lowerLimit, $upperLimit); } - /** - * @return array - */ - public function providerInvalidBetween() + public function providerInvalidBetween(): array { return [ [1, 2, 3], [3, 1, 2], ['aaa', 'bbb', 'ccc'], ['ddd', 'bbb', 'ccc'], - [new \DateTime('yesterday'), new \DateTime('today'), new \DateTime('tomorrow')], - [new \DateTime('tomorrow'), new \DateTime('yesterday'), new \DateTime('today')], + [new DateTime('yesterday'), new DateTime('today'), new DateTime('tomorrow')], + [new DateTime('tomorrow'), new DateTime('yesterday'), new DateTime('today')], ]; } @@ -1965,18 +2032,15 @@ public function testValidBetween($value, $lowerLimit, $upperLimit) $this->assertTrue(Assertion::between($value, $lowerLimit, $upperLimit)); } - /** - * @return array - */ - public function providerValidBetween() + public function providerValidBetween(): array { return [ [2, 1, 3], [1, 1, 1], ['bbb', 'aaa', 'ccc'], ['aaa', 'aaa', 'aaa'], - [new \DateTime('today'), new \DateTime('yesterday'), new \DateTime('tomorrow')], - [new \DateTime('today'), new \DateTime('today'), new \DateTime('today')], + [new DateTime('today'), new DateTime('yesterday'), new DateTime('tomorrow')], + [new DateTime('today'), new DateTime('today'), new DateTime('today')], ]; } @@ -1994,18 +2058,15 @@ public function testInvalidBetweenExclusive($value, $lowerLimit, $upperLimit) Assertion::betweenExclusive($value, $lowerLimit, $upperLimit); } - /** - * @return array - */ - public function providerInvalidBetweenExclusive() + public function providerInvalidBetweenExclusive(): array { return [ [1, 1, 2], [2, 1, 2], ['aaa', 'aaa', 'bbb'], ['bbb', 'aaa', 'bbb'], - [new \DateTime('today'), new \DateTime('today'), new \DateTime('tomorrow')], - [new \DateTime('tomorrow'), new \DateTime('today'), new \DateTime('tomorrow')], + [new DateTime('today'), new DateTime('today'), new DateTime('tomorrow')], + [new DateTime('tomorrow'), new DateTime('today'), new DateTime('tomorrow')], ]; } @@ -2021,15 +2082,12 @@ public function testValidBetweenExclusive($value, $lowerLimit, $upperLimit) $this->assertTrue(Assertion::betweenExclusive($value, $lowerLimit, $upperLimit)); } - /** - * @return array - */ - public function providerValidBetweenExclusive() + public function providerValidBetweenExclusive(): array { return [ [2, 1, 3], ['bbb', 'aaa', 'ccc'], - [new \DateTime('today'), new \DateTime('yesterday'), new \DateTime('tomorrow')], + [new DateTime('today'), new DateTime('yesterday'), new DateTime('tomorrow')], ]; } @@ -2040,7 +2098,19 @@ public function providerValidBetweenExclusive() */ public function testStringifyTruncatesStringValuesLongerThan100CharactersAppropriately() { - $string = \str_repeat('1234567890', 11); + $string = str_repeat('1234567890', 11); + + $this->assertTrue(Assertion::float($string)); + } + + /** + * @expectedException \Assert\AssertionFailedException + * @expectedExceptionCode \Assert\Assertion::INVALID_FLOAT + * @expectedExceptionMessage ငါကနံပါတ်မဟုတ်ဘူးငါကနံပါတ်မဟုတ်ဘူးငါကနံပါတ်မဟုတ်ဘူးငါကနံပါတ်မဟုတ်ဘူးငါကနံပါတ်မဟုတ်ဘူးငါကနံပါတ်မဟု... + */ + public function testStringifyTruncatesStringValuesLongerThan100CharactersAppropriatelyAndIsMultibyteValid() + { + $string = str_repeat('ငါကနံပါတ်မဟုတ်ဘူး', 11); $this->assertTrue(Assertion::float($string)); } @@ -2052,7 +2122,7 @@ public function testStringifyTruncatesStringValuesLongerThan100CharactersAppropr */ public function testStringifyReportsResourceType() { - $this->assertTrue(Assertion::float(\fopen('php://stdin', 'rb'))); + $this->assertTrue(Assertion::float(fopen('php://stdin', 'rb'))); } public function testExtensionLoaded() @@ -2061,7 +2131,7 @@ public function testExtensionLoaded() } /** - * @expectedException \Assert\InvalidArgumentException + * @expectedException InvalidArgumentException */ public function testExtensionNotLoaded() { @@ -2074,7 +2144,7 @@ public function testValidConstant() } /** - * @expectedException \Assert\InvalidArgumentException + * @expectedException InvalidArgumentException */ public function testInvalidConstant() { @@ -2087,7 +2157,7 @@ public function testValidVersion() } /** - * @expectedException \Assert\InvalidArgumentException + * @expectedException InvalidArgumentException */ public function testInvalidVersion() { @@ -2095,7 +2165,7 @@ public function testInvalidVersion() } /** - * @expectedException \Assert\InvalidArgumentException + * @expectedException InvalidArgumentException */ public function testInvalidVersionOperator() { @@ -2108,7 +2178,7 @@ public function testValidPhpVersion() } /** - * @expectedException \Assert\InvalidArgumentException + * @expectedException InvalidArgumentException */ public function testInvalidPhpVersion() { @@ -2121,7 +2191,7 @@ public function testValidExtensionVersion() } /** - * @expectedException \Assert\InvalidArgumentException + * @expectedException InvalidArgumentException */ public function testInvalidExtensionVersion() { @@ -2135,7 +2205,7 @@ public function testObjectOrClass() } /** - * @expectedException \Assert\InvalidArgumentException + * @expectedException InvalidArgumentException */ public function testNotObjectOrClass() { @@ -2144,24 +2214,24 @@ public function testNotObjectOrClass() public function testPropertyExists() { - self::assertTrue(Assertion::propertyExists(new \Exception(), 'message')); + self::assertTrue(Assertion::propertyExists(new Exception(), 'message')); } /** - * @expectedException \Assert\InvalidArgumentException + * @expectedException InvalidArgumentException * @expectedExceptionCode \Assert\Assertion::INVALID_PROPERTY */ public function testInvalidPropertyExists() { - Assertion::propertyExists(new \Exception(), 'invalidProperty'); + Assertion::propertyExists(new Exception(), 'invalidProperty'); } public function testPropertiesExist() { - self::assertTrue(Assertion::propertiesExist(new \Exception(), ['message', 'code', 'previous'])); + self::assertTrue(Assertion::propertiesExist(new Exception(), ['message', 'code', 'previous'])); } - public function invalidPropertiesExistProvider() + public function invalidPropertiesExistProvider(): array { return [ [['invalidProperty']], @@ -2171,23 +2241,23 @@ public function invalidPropertiesExistProvider() /** * @dataProvider invalidPropertiesExistProvider - * @expectedException \Assert\InvalidArgumentException + * @expectedException InvalidArgumentException * @expectedExceptionCode \Assert\Assertion::INVALID_PROPERTY * * @param array $properties */ public function testInvalidPropertiesExist($properties) { - Assertion::propertiesExist(new \Exception(), $properties); + Assertion::propertiesExist(new Exception(), $properties); } public function testIsResource() { - self::assertTrue(Assertion::isResource(\curl_init())); + self::assertTrue(Assertion::isResource(curl_init())); } /** - * @expectedException \Assert\InvalidArgumentException + * @expectedException InvalidArgumentException */ public function testIsNotResource() { @@ -2196,13 +2266,13 @@ public function testIsNotResource() public function testBase64() { - $base64String = \base64_encode('content'); + $base64String = base64_encode('content'); $this->assertTrue(Assertion::base64($base64String)); } /** - * @expectedException \Assert\InvalidArgumentException + * @expectedException InvalidArgumentException * @expectedExceptionCode \Assert\Assertion::INVALID_BASE64 */ public function testNotBase64() @@ -2210,7 +2280,7 @@ public function testNotBase64() Assertion::base64('wrong-content'); } - public function invalidEqArraySubsetProvider() + public function invalidEqArraySubsetProvider(): array { return [ 'firstArgumentNotArray' => ['notArray', []], @@ -2243,7 +2313,7 @@ public function testEqArraySubsetValid() /** * @dataProvider invalidEqArraySubsetProvider * - * @expectedException \Assert\InvalidArgumentException + * @expectedException InvalidArgumentException * @expectedExceptionCode \Assert\Assertion::INVALID_ARRAY */ public function testEqArraySubsetInvalid($value, $value2) @@ -2254,7 +2324,7 @@ public function testEqArraySubsetInvalid($value, $value2) /** * @dataProvider invalidEqArraySubsetProvider * - * @expectedException \Assert\InvalidArgumentException + * @expectedException InvalidArgumentException * @expectedExceptionCode \Assert\Assertion::INVALID_EQ */ public function testEqArraySubsetMismatchingSubset()