From 8a4c4e9687911ba94e4d985e67662cb0cdab9848 Mon Sep 17 00:00:00 2001 From: Richard Quadling Date: Wed, 9 Oct 2019 16:57:35 +0100 Subject: [PATCH 01/13] Remove ext-intl as a required extension, making it a suggested extension for use with Assertion::count(), Assertion::isCountable(), Assertion::minCount(), and Assertion::maxCount() to operate on ResourceBundles. --- composer.json | 35 +-- tests/Assert/Tests/AssertTest.php | 341 +++++++++++++++++------------- 2 files changed, 218 insertions(+), 158 deletions(-) diff --git a/composer.json b/composer.json index 21e27cb6..a9df304d 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,30 @@ "tests/Assert/Tests/Fixtures/functions.php" ] }, + "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" + }, "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/tests/Assert/Tests/AssertTest.php b/tests/Assert/Tests/AssertTest.php index efb2a9a9..5f7504e8 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,18 @@ 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)); - // Test ResourceBundle counting using resources generated for PHP testing of ResourceBundle + } + + /** + * @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 +1472,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 +1512,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 +1575,7 @@ public function testChoicesNotEmptyExpectingExceptionInvalidKeyIsset() Assertion::choicesNotEmpty(['tux' => ''], ['invalidChoice']); } - public function invalidChoicesProvider() + public function invalidChoicesProvider(): array { return [ 'empty values' => [[], ['tux'], Assertion::VALUE_EMPTY], @@ -1551,7 +1617,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 +1628,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 +1663,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 +1694,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 +1720,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 +1750,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 +1789,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 +1800,7 @@ public function invalidDateProvider() public function testValidTraversable() { - $this->assertTrue(Assertion::isTraversable(new \ArrayObject())); + $this->assertTrue(Assertion::isTraversable(new ArrayObject())); } /** @@ -1749,7 +1815,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 +1829,7 @@ public function testInvalidCountable() public function testValidArrayAccessible() { - $this->assertTrue(Assertion::isArrayAccessible(new \ArrayObject())); + $this->assertTrue(Assertion::isArrayAccessible(new ArrayObject())); } /** @@ -1805,8 +1871,8 @@ public function testInvalidSatisfy() { Assertion::satisfy( null, - function ($value) { - return !\is_null($value); + function ($value): bool { + return !is_null($value); } ); } @@ -1817,8 +1883,8 @@ public function testValidSatisfy() $this->assertTrue( Assertion::satisfy( null, - function ($value) { - return \is_null($value); + function ($value) : bool { + return is_null($value); } ) ); @@ -1827,8 +1893,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 +1915,7 @@ public function testValidIp($value) $this->assertTrue(Assertion::ip($value)); } - public function validIpProvider() + public function validIpProvider(): array { return [ ['0.0.0.0'], @@ -1869,7 +1938,7 @@ public function testInvalidIp($value, $flag = null) Assertion::ip($value, $flag); } - public function invalidIpProvider() + public function invalidIpProvider(): array { return [ ['invalid ip address'], @@ -1921,7 +1990,7 @@ public function testInvalidInterfaceExists() public function testValidInterfaceExists() { - $this->assertTrue(Assertion::interfaceExists(\Countable::class)); + $this->assertTrue(Assertion::interfaceExists(Countable::class)); } /** @@ -1938,18 +2007,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 +2031,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 +2057,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 +2081,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 +2097,7 @@ public function providerValidBetweenExclusive() */ public function testStringifyTruncatesStringValuesLongerThan100CharactersAppropriately() { - $string = \str_repeat('1234567890', 11); + $string = str_repeat('1234567890', 11); $this->assertTrue(Assertion::float($string)); } @@ -2052,7 +2109,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 +2118,7 @@ public function testExtensionLoaded() } /** - * @expectedException \Assert\InvalidArgumentException + * @expectedException InvalidArgumentException */ public function testExtensionNotLoaded() { @@ -2074,7 +2131,7 @@ public function testValidConstant() } /** - * @expectedException \Assert\InvalidArgumentException + * @expectedException InvalidArgumentException */ public function testInvalidConstant() { @@ -2087,7 +2144,7 @@ public function testValidVersion() } /** - * @expectedException \Assert\InvalidArgumentException + * @expectedException InvalidArgumentException */ public function testInvalidVersion() { @@ -2095,7 +2152,7 @@ public function testInvalidVersion() } /** - * @expectedException \Assert\InvalidArgumentException + * @expectedException InvalidArgumentException */ public function testInvalidVersionOperator() { @@ -2108,7 +2165,7 @@ public function testValidPhpVersion() } /** - * @expectedException \Assert\InvalidArgumentException + * @expectedException InvalidArgumentException */ public function testInvalidPhpVersion() { @@ -2121,7 +2178,7 @@ public function testValidExtensionVersion() } /** - * @expectedException \Assert\InvalidArgumentException + * @expectedException InvalidArgumentException */ public function testInvalidExtensionVersion() { @@ -2135,7 +2192,7 @@ public function testObjectOrClass() } /** - * @expectedException \Assert\InvalidArgumentException + * @expectedException InvalidArgumentException */ public function testNotObjectOrClass() { @@ -2144,24 +2201,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 +2228,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 +2253,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 +2267,7 @@ public function testNotBase64() Assertion::base64('wrong-content'); } - public function invalidEqArraySubsetProvider() + public function invalidEqArraySubsetProvider(): array { return [ 'firstArgumentNotArray' => ['notArray', []], @@ -2243,7 +2300,7 @@ public function testEqArraySubsetValid() /** * @dataProvider invalidEqArraySubsetProvider * - * @expectedException \Assert\InvalidArgumentException + * @expectedException InvalidArgumentException * @expectedExceptionCode \Assert\Assertion::INVALID_ARRAY */ public function testEqArraySubsetInvalid($value, $value2) @@ -2254,7 +2311,7 @@ public function testEqArraySubsetInvalid($value, $value2) /** * @dataProvider invalidEqArraySubsetProvider * - * @expectedException \Assert\InvalidArgumentException + * @expectedException InvalidArgumentException * @expectedExceptionCode \Assert\Assertion::INVALID_EQ */ public function testEqArraySubsetMismatchingSubset() From 38f5ca80c48e6d04ce71dc22f23d2f69b79495f0 Mon Sep 17 00:00:00 2001 From: Richard Quadling Date: Wed, 9 Oct 2019 16:59:36 +0100 Subject: [PATCH 02/13] Correct @method return typehint for LazyAssertion chaining --- bin/MethodDocGenerator.php | 4 +- lib/Assert/LazyAssertion.php | 198 ++++++++++++++++++----------------- 2 files changed, 104 insertions(+), 98 deletions(-) diff --git a/bin/MethodDocGenerator.php b/bin/MethodDocGenerator.php index 1e666458..77d6de65 100644 --- a/bin/MethodDocGenerator.php +++ b/bin/MethodDocGenerator.php @@ -197,8 +197,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 static static %s(%s) %s.', $skipParameterTest), + $this->generateMethodDocs($this->gatherAssertionChainSwitches(), ' * @method static static %s(%s) %s.', false) ); $this->generateFile($phpFile, $docs, 'class'); diff --git a/lib/Assert/LazyAssertion.php b/lib/Assert/LazyAssertion.php index 9301c6b4..0afd34cb 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 static static alnum(string|callable $message = null, string $propertyPath = null) Assert that value is alphanumeric. + * @method static static base64(string|callable $message = null, string $propertyPath = null) Assert that a constant is defined. + * @method static static 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 static static 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 static static 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 static static boolean(string|callable $message = null, string $propertyPath = null) Assert that value is php boolean. + * @method static static choice(array $choices, string|callable $message = null, string $propertyPath = null) Assert that value is in array of choices. + * @method static static 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 static static classExists(string|callable $message = null, string $propertyPath = null) Assert that the class exists. + * @method static static contains(string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string contains a sequence of chars. + * @method static static count(int $count, string|callable $message = null, string $propertyPath = null) Assert that the count of countable is equal to count. + * @method static static date(string $format, string|callable $message = null, string $propertyPath = null) Assert that date is valid and corresponds to the given format. + * @method static static defined(string|callable $message = null, string $propertyPath = null) Assert that a constant is defined. + * @method static static digit(string|callable $message = null, string $propertyPath = null) Validates if an integer or integerish is a digit. + * @method static static directory(string|callable $message = null, string $propertyPath = null) Assert that a directory exists. + * @method static static e164(string|callable $message = null, string $propertyPath = null) Assert that the given string is a valid E164 Phone Number. + * @method static static email(string|callable $message = null, string $propertyPath = null) Assert that value is an email address (using input_filter/FILTER_VALIDATE_EMAIL). + * @method static static endsWith(string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string ends with a sequence of chars. + * @method static static eq(mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that two values are equal (using ==). + * @method static static eqArraySubset(mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that the array contains the subset. + * @method static static extensionLoaded(string|callable $message = null, string $propertyPath = null) Assert that extension is loaded. + * @method static static extensionVersion(string $operator, mixed $version, string|callable $message = null, string $propertyPath = null) Assert that extension is loaded and a specific version is installed. + * @method static static false(string|callable $message = null, string $propertyPath = null) Assert that the value is boolean False. + * @method static static file(string|callable $message = null, string $propertyPath = null) Assert that a file exists. + * @method static static float(string|callable $message = null, string $propertyPath = null) Assert that value is a php float. + * @method static static greaterOrEqualThan(mixed $limit, string|callable $message = null, string $propertyPath = null) Determines if the value is greater or equal than given limit. + * @method static static greaterThan(mixed $limit, string|callable $message = null, string $propertyPath = null) Determines if the value is greater than given limit. + * @method static static implementsInterface(string $interfaceName, string|callable $message = null, string $propertyPath = null) Assert that the class implements the interface. + * @method static static 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 static static integer(string|callable $message = null, string $propertyPath = null) Assert that value is a php integer. + * @method static static integerish(string|callable $message = null, string $propertyPath = null) Assert that value is a php integer'ish. + * @method static static interfaceExists(string|callable $message = null, string $propertyPath = null) Assert that the interface exists. + * @method static static ip(int $flag = null, string|callable $message = null, string $propertyPath = null) Assert that value is an IPv4 or IPv6 address. + * @method static static ipv4(int $flag = null, string|callable $message = null, string $propertyPath = null) Assert that value is an IPv4 address. + * @method static static ipv6(int $flag = null, string|callable $message = null, string $propertyPath = null) Assert that value is an IPv6 address. + * @method static static isArray(string|callable $message = null, string $propertyPath = null) Assert that value is an array. + * @method static static isArrayAccessible(string|callable $message = null, string $propertyPath = null) Assert that value is an array or an array-accessible object. + * @method static static isCallable(string|callable $message = null, string $propertyPath = null) Determines that the provided value is callable. + * @method static static isCountable(string|callable $message = null, string $propertyPath = null) Assert that value is countable. + * @method static static isInstanceOf(string $className, string|callable $message = null, string $propertyPath = null) Assert that value is instance of given class-name. + * @method static static isJsonString(string|callable $message = null, string $propertyPath = null) Assert that the given string is a valid json string. + * @method static static isObject(string|callable $message = null, string $propertyPath = null) Determines that the provided value is an object. + * @method static static isResource(string|callable $message = null, string $propertyPath = null) Assert that value is a resource. + * @method static static isTraversable(string|callable $message = null, string $propertyPath = null) Assert that value is an array or a traversable object. + * @method static static keyExists(string|int $key, string|callable $message = null, string $propertyPath = null) Assert that key exists in an array. + * @method static static keyIsset(string|int $key, string|callable $message = null, string $propertyPath = null) Assert that key exists in an array/array-accessible object using isset(). + * @method static static keyNotExists(string|int $key, string|callable $message = null, string $propertyPath = null) Assert that key does not exist in an array. + * @method static static length(int $length, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string has a given length. + * @method static static lessOrEqualThan(mixed $limit, string|callable $message = null, string $propertyPath = null) Determines if the value is less or equal than given limit. + * @method static static lessThan(mixed $limit, string|callable $message = null, string $propertyPath = null) Determines if the value is less than given limit. + * @method static static max(mixed $maxValue, string|callable $message = null, string $propertyPath = null) Assert that a number is smaller as a given limit. + * @method static static maxCount(int $count, string|callable $message = null, string $propertyPath = null) Assert that the countable have at most $count elements. + * @method static static maxLength(int $maxLength, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string value is not longer than $maxLength chars. + * @method static static methodExists(mixed $object, string|callable $message = null, string $propertyPath = null) Determines that the named method is defined in the provided object. + * @method static static min(mixed $minValue, string|callable $message = null, string $propertyPath = null) Assert that a value is at least as big as a given limit. + * @method static static minCount(int $count, string|callable $message = null, string $propertyPath = null) Assert that the countable have at least $count elements. + * @method static static minLength(int $minLength, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that a string is at least $minLength chars long. + * @method static static noContent(string|callable $message = null, string $propertyPath = null) Assert that value is empty. + * @method static static notBlank(string|callable $message = null, string $propertyPath = null) Assert that value is not blank. + * @method static static notContains(string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string does not contains a sequence of chars. + * @method static static notEmpty(string|callable $message = null, string $propertyPath = null) Assert that value is not empty. + * @method static static 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 static static notEq(mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that two values are not equal (using ==). + * @method static static notInArray(array $choices, string|callable $message = null, string $propertyPath = null) Assert that value is not in array of choices. + * @method static static notIsInstanceOf(string $className, string|callable $message = null, string $propertyPath = null) Assert that value is not instance of given class-name. + * @method static static notNull(string|callable $message = null, string $propertyPath = null) Assert that value is not null. + * @method static static notRegex(string $pattern, string|callable $message = null, string $propertyPath = null) Assert that value does not match a regex. + * @method static static notSame(mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that two values are not the same (using ===). + * @method static static null(string|callable $message = null, string $propertyPath = null) Assert that value is null. + * @method static static numeric(string|callable $message = null, string $propertyPath = null) Assert that value is numeric. + * @method static static objectOrClass(string|callable $message = null, string $propertyPath = null) Assert that the value is an object, or a class that exists. + * @method static static phpVersion(mixed $version, string|callable $message = null, string $propertyPath = null) Assert on PHP version. + * @method static static 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 static static 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 static static range(mixed $minValue, mixed $maxValue, string|callable $message = null, string $propertyPath = null) Assert that value is in range of numbers. + * @method static static readable(string|callable $message = null, string $propertyPath = null) Assert that the value is something readable. + * @method static static regex(string $pattern, string|callable $message = null, string $propertyPath = null) Assert that value matches a regex. + * @method static static same(mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that two values are the same (using ===). + * @method static static satisfy(callable $callback, string|callable $message = null, string $propertyPath = null) Assert that the provided value is valid according to a callback. + * @method static static scalar(string|callable $message = null, string $propertyPath = null) Assert that value is a PHP scalar. + * @method static static startsWith(string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string starts with a sequence of chars. + * @method static static string(string|callable $message = null, string $propertyPath = null) Assert that value is a string. + * @method static static subclassOf(string $className, string|callable $message = null, string $propertyPath = null) Assert that value is subclass of given class-name. + * @method static static true(string|callable $message = null, string $propertyPath = null) Assert that the value is boolean True. + * @method static static url(string|callable $message = null, string $propertyPath = null) Assert that value is an URL. + * @method static static uuid(string|callable $message = null, string $propertyPath = null) Assert that the given string is a valid UUID. + * @method static static version(string $operator, string $version2, string|callable $message = null, string $propertyPath = null) Assert comparison of two versions. + * @method static static writeable(string|callable $message = null, string $propertyPath = null) Assert that the value is something writeable. + * @method static static all() Switch chain into validation mode for an array of values. + * @method static static 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 $method + * @param $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); From 6ae055f2281502aaa7951dd32d805c87ed8914e1 Mon Sep 17 00:00:00 2001 From: Richard Quadling Date: Thu, 10 Oct 2019 10:42:18 +0100 Subject: [PATCH 03/13] Restored `\Assert\Assertion::createException()` signature to 3.2.2. Sincerely apologies to the BC break. --- lib/Assert/Assertion.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Assert/Assertion.php b/lib/Assert/Assertion.php index 6f5b3c2d..4104e4a8 100644 --- a/lib/Assert/Assertion.php +++ b/lib/Assert/Assertion.php @@ -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; From c6031a75e4a0a9dfe7692a8e5b17b45a23afb2ba Mon Sep 17 00:00:00 2001 From: Richard Quadling Date: Thu, 10 Oct 2019 10:42:37 +0100 Subject: [PATCH 04/13] Fix docblock typehint --- lib/Assert/LazyAssertion.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Assert/LazyAssertion.php b/lib/Assert/LazyAssertion.php index 0afd34cb..c032911a 100644 --- a/lib/Assert/LazyAssertion.php +++ b/lib/Assert/LazyAssertion.php @@ -158,8 +158,8 @@ public function tryAll() } /** - * @param $method - * @param $args + * @param string $method + * @param array $args * * @return static */ From 200ecc8b56aba9ee4a35c857d8c0d2ebe2e6e70d Mon Sep 17 00:00:00 2001 From: Richard Quadling Date: Thu, 10 Oct 2019 10:56:40 +0100 Subject: [PATCH 05/13] Prepare v3.2.4 --- CHANGELOG.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0f6e614..a64b736d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,26 @@ # Change Log All notable changes to this project will be documented in this file. +## 3.2.4 - 2019-10-09 - 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 From d4207ed8e3fb8f3fadff3084a1203b1805ca1c6d Mon Sep 17 00:00:00 2001 From: Jakub Zalas Date: Thu, 10 Oct 2019 11:17:51 +0100 Subject: [PATCH 06/13] Remove a hard dependency on the intl extension (#289) Fixes #288. While #268 and #269 updated count() and isCountable() to now work with intl resources, #286 made that the whole beberlei/assert package now requires the intl extension to be installed. However, the intl extension dependency is a soft dependency. The package does not need intl for most of its features and can safely work without it. --- composer.json | 1 - tests/Assert/Tests/AssertTest.php | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index a9df304d..e1187047 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,6 @@ }, "require": { "php": "^7", - "ext-intl": "*", "ext-simplexml": "*", "ext-mbstring": "*", "ext-ctype": "*", diff --git a/tests/Assert/Tests/AssertTest.php b/tests/Assert/Tests/AssertTest.php index 5f7504e8..fd397c0d 100644 --- a/tests/Assert/Tests/AssertTest.php +++ b/tests/Assert/Tests/AssertTest.php @@ -1437,7 +1437,8 @@ public function testValidCount() * @requires extension intl */ public function testValidCountWithIntlResourceBundle() - { // Test ResourceBundle counting using resources generated for PHP testing of ResourceBundle + { + // 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)); } From 4fd15cd95f8659407bc5afb5d8248a3458318cc6 Mon Sep 17 00:00:00 2001 From: Richard Quadling Date: Thu, 10 Oct 2019 11:21:41 +0100 Subject: [PATCH 07/13] Fix docblocks for `all` to show that they are expected to receive an array of things --- bin/MethodDocGenerator.php | 4 + lib/Assert/Assertion.php | 176 ++++++++++++++++++------------------- 2 files changed, 92 insertions(+), 88 deletions(-) diff --git a/bin/MethodDocGenerator.php b/bin/MethodDocGenerator.php index 77d6de65..fc42a894 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'; } diff --git a/lib/Assert/Assertion.php b/lib/Assert/Assertion.php index 4104e4a8..8eed11bd 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. From 448bc4f6d9a47baac563be9663e7f7d5be8b03f0 Mon Sep 17 00:00:00 2001 From: Richard Quadling Date: Thu, 10 Oct 2019 11:22:53 +0100 Subject: [PATCH 08/13] Preapare v3.2.5 --- CHANGELOG.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a64b736d..7c0b3342 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,17 @@ # Change Log All notable changes to this project will be documented in this file. -## 3.2.4 - 2019-10-09 - Fix the broken things release. +## 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. From 263ae9d02e0640c6c673832a3de3e2283ccf57a3 Mon Sep 17 00:00:00 2001 From: Richard Quadling Date: Thu, 10 Oct 2019 11:30:07 +0100 Subject: [PATCH 09/13] Make `Assert\Assertion::stringify()` UTF-8 safe. --- lib/Assert/Assertion.php | 4 ++-- tests/Assert/Tests/AssertTest.php | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/Assert/Assertion.php b/lib/Assert/Assertion.php index 8eed11bd..a8b04e52 100644 --- a/lib/Assert/Assertion.php +++ b/lib/Assert/Assertion.php @@ -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/tests/Assert/Tests/AssertTest.php b/tests/Assert/Tests/AssertTest.php index fd397c0d..f989f0ad 100644 --- a/tests/Assert/Tests/AssertTest.php +++ b/tests/Assert/Tests/AssertTest.php @@ -2103,6 +2103,18 @@ public function testStringifyTruncatesStringValuesLongerThan100CharactersAppropr $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)); + } + /** * @expectedException \Assert\AssertionFailedException * @expectedExceptionCode \Assert\Assertion::INVALID_FLOAT From 99508be011753690fe108ded450f5caaae180cfa Mon Sep 17 00:00:00 2001 From: Richard Quadling Date: Thu, 10 Oct 2019 11:33:57 +0100 Subject: [PATCH 10/13] Prepare v3.2.6 --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c0b3342..8fd187f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # Change Log All notable changes to this project will be documented in this file. +## 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 From acd461e93123bcb4e840793257cfa09b318bae85 Mon Sep 17 00:00:00 2001 From: Richard Quadling Date: Thu, 19 Dec 2019 17:40:38 +0000 Subject: [PATCH 11/13] Reinstate LazyAssertion docblock --- bin/MethodDocGenerator.php | 4 +- lib/Assert/LazyAssertion.php | 180 +++++++++++++++++------------------ 2 files changed, 92 insertions(+), 92 deletions(-) diff --git a/bin/MethodDocGenerator.php b/bin/MethodDocGenerator.php index fc42a894..8e36e61b 100644 --- a/bin/MethodDocGenerator.php +++ b/bin/MethodDocGenerator.php @@ -201,8 +201,8 @@ public function generateLazyAssertionDocs() }; $docs = array_merge( - $this->generateMethodDocs($this->gatherAssertions(), ' * @method static static %s(%s) %s.', $skipParameterTest), - $this->generateMethodDocs($this->gatherAssertionChainSwitches(), ' * @method static static %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/lib/Assert/LazyAssertion.php b/lib/Assert/LazyAssertion.php index c032911a..6ccd6423 100644 --- a/lib/Assert/LazyAssertion.php +++ b/lib/Assert/LazyAssertion.php @@ -21,96 +21,96 @@ * * @author Benjamin Eberlei * - * @method static static alnum(string|callable $message = null, string $propertyPath = null) Assert that value is alphanumeric. - * @method static static base64(string|callable $message = null, string $propertyPath = null) Assert that a constant is defined. - * @method static static 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 static static 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 static static 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 static static boolean(string|callable $message = null, string $propertyPath = null) Assert that value is php boolean. - * @method static static choice(array $choices, string|callable $message = null, string $propertyPath = null) Assert that value is in array of choices. - * @method static static 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 static static classExists(string|callable $message = null, string $propertyPath = null) Assert that the class exists. - * @method static static contains(string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string contains a sequence of chars. - * @method static static count(int $count, string|callable $message = null, string $propertyPath = null) Assert that the count of countable is equal to count. - * @method static static date(string $format, string|callable $message = null, string $propertyPath = null) Assert that date is valid and corresponds to the given format. - * @method static static defined(string|callable $message = null, string $propertyPath = null) Assert that a constant is defined. - * @method static static digit(string|callable $message = null, string $propertyPath = null) Validates if an integer or integerish is a digit. - * @method static static directory(string|callable $message = null, string $propertyPath = null) Assert that a directory exists. - * @method static static e164(string|callable $message = null, string $propertyPath = null) Assert that the given string is a valid E164 Phone Number. - * @method static static email(string|callable $message = null, string $propertyPath = null) Assert that value is an email address (using input_filter/FILTER_VALIDATE_EMAIL). - * @method static static endsWith(string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string ends with a sequence of chars. - * @method static static eq(mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that two values are equal (using ==). - * @method static static eqArraySubset(mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that the array contains the subset. - * @method static static extensionLoaded(string|callable $message = null, string $propertyPath = null) Assert that extension is loaded. - * @method static static extensionVersion(string $operator, mixed $version, string|callable $message = null, string $propertyPath = null) Assert that extension is loaded and a specific version is installed. - * @method static static false(string|callable $message = null, string $propertyPath = null) Assert that the value is boolean False. - * @method static static file(string|callable $message = null, string $propertyPath = null) Assert that a file exists. - * @method static static float(string|callable $message = null, string $propertyPath = null) Assert that value is a php float. - * @method static static greaterOrEqualThan(mixed $limit, string|callable $message = null, string $propertyPath = null) Determines if the value is greater or equal than given limit. - * @method static static greaterThan(mixed $limit, string|callable $message = null, string $propertyPath = null) Determines if the value is greater than given limit. - * @method static static implementsInterface(string $interfaceName, string|callable $message = null, string $propertyPath = null) Assert that the class implements the interface. - * @method static static 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 static static integer(string|callable $message = null, string $propertyPath = null) Assert that value is a php integer. - * @method static static integerish(string|callable $message = null, string $propertyPath = null) Assert that value is a php integer'ish. - * @method static static interfaceExists(string|callable $message = null, string $propertyPath = null) Assert that the interface exists. - * @method static static ip(int $flag = null, string|callable $message = null, string $propertyPath = null) Assert that value is an IPv4 or IPv6 address. - * @method static static ipv4(int $flag = null, string|callable $message = null, string $propertyPath = null) Assert that value is an IPv4 address. - * @method static static ipv6(int $flag = null, string|callable $message = null, string $propertyPath = null) Assert that value is an IPv6 address. - * @method static static isArray(string|callable $message = null, string $propertyPath = null) Assert that value is an array. - * @method static static isArrayAccessible(string|callable $message = null, string $propertyPath = null) Assert that value is an array or an array-accessible object. - * @method static static isCallable(string|callable $message = null, string $propertyPath = null) Determines that the provided value is callable. - * @method static static isCountable(string|callable $message = null, string $propertyPath = null) Assert that value is countable. - * @method static static isInstanceOf(string $className, string|callable $message = null, string $propertyPath = null) Assert that value is instance of given class-name. - * @method static static isJsonString(string|callable $message = null, string $propertyPath = null) Assert that the given string is a valid json string. - * @method static static isObject(string|callable $message = null, string $propertyPath = null) Determines that the provided value is an object. - * @method static static isResource(string|callable $message = null, string $propertyPath = null) Assert that value is a resource. - * @method static static isTraversable(string|callable $message = null, string $propertyPath = null) Assert that value is an array or a traversable object. - * @method static static keyExists(string|int $key, string|callable $message = null, string $propertyPath = null) Assert that key exists in an array. - * @method static static keyIsset(string|int $key, string|callable $message = null, string $propertyPath = null) Assert that key exists in an array/array-accessible object using isset(). - * @method static static keyNotExists(string|int $key, string|callable $message = null, string $propertyPath = null) Assert that key does not exist in an array. - * @method static static length(int $length, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string has a given length. - * @method static static lessOrEqualThan(mixed $limit, string|callable $message = null, string $propertyPath = null) Determines if the value is less or equal than given limit. - * @method static static lessThan(mixed $limit, string|callable $message = null, string $propertyPath = null) Determines if the value is less than given limit. - * @method static static max(mixed $maxValue, string|callable $message = null, string $propertyPath = null) Assert that a number is smaller as a given limit. - * @method static static maxCount(int $count, string|callable $message = null, string $propertyPath = null) Assert that the countable have at most $count elements. - * @method static static maxLength(int $maxLength, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string value is not longer than $maxLength chars. - * @method static static methodExists(mixed $object, string|callable $message = null, string $propertyPath = null) Determines that the named method is defined in the provided object. - * @method static static min(mixed $minValue, string|callable $message = null, string $propertyPath = null) Assert that a value is at least as big as a given limit. - * @method static static minCount(int $count, string|callable $message = null, string $propertyPath = null) Assert that the countable have at least $count elements. - * @method static static minLength(int $minLength, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that a string is at least $minLength chars long. - * @method static static noContent(string|callable $message = null, string $propertyPath = null) Assert that value is empty. - * @method static static notBlank(string|callable $message = null, string $propertyPath = null) Assert that value is not blank. - * @method static static notContains(string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string does not contains a sequence of chars. - * @method static static notEmpty(string|callable $message = null, string $propertyPath = null) Assert that value is not empty. - * @method static static 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 static static notEq(mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that two values are not equal (using ==). - * @method static static notInArray(array $choices, string|callable $message = null, string $propertyPath = null) Assert that value is not in array of choices. - * @method static static notIsInstanceOf(string $className, string|callable $message = null, string $propertyPath = null) Assert that value is not instance of given class-name. - * @method static static notNull(string|callable $message = null, string $propertyPath = null) Assert that value is not null. - * @method static static notRegex(string $pattern, string|callable $message = null, string $propertyPath = null) Assert that value does not match a regex. - * @method static static notSame(mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that two values are not the same (using ===). - * @method static static null(string|callable $message = null, string $propertyPath = null) Assert that value is null. - * @method static static numeric(string|callable $message = null, string $propertyPath = null) Assert that value is numeric. - * @method static static objectOrClass(string|callable $message = null, string $propertyPath = null) Assert that the value is an object, or a class that exists. - * @method static static phpVersion(mixed $version, string|callable $message = null, string $propertyPath = null) Assert on PHP version. - * @method static static 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 static static 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 static static range(mixed $minValue, mixed $maxValue, string|callable $message = null, string $propertyPath = null) Assert that value is in range of numbers. - * @method static static readable(string|callable $message = null, string $propertyPath = null) Assert that the value is something readable. - * @method static static regex(string $pattern, string|callable $message = null, string $propertyPath = null) Assert that value matches a regex. - * @method static static same(mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that two values are the same (using ===). - * @method static static satisfy(callable $callback, string|callable $message = null, string $propertyPath = null) Assert that the provided value is valid according to a callback. - * @method static static scalar(string|callable $message = null, string $propertyPath = null) Assert that value is a PHP scalar. - * @method static static startsWith(string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string starts with a sequence of chars. - * @method static static string(string|callable $message = null, string $propertyPath = null) Assert that value is a string. - * @method static static subclassOf(string $className, string|callable $message = null, string $propertyPath = null) Assert that value is subclass of given class-name. - * @method static static true(string|callable $message = null, string $propertyPath = null) Assert that the value is boolean True. - * @method static static url(string|callable $message = null, string $propertyPath = null) Assert that value is an URL. - * @method static static uuid(string|callable $message = null, string $propertyPath = null) Assert that the given string is a valid UUID. - * @method static static version(string $operator, string $version2, string|callable $message = null, string $propertyPath = null) Assert comparison of two versions. - * @method static static writeable(string|callable $message = null, string $propertyPath = null) Assert that the value is something writeable. - * @method static static all() Switch chain into validation mode for an array of values. - * @method static static 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 { From d63a6943fc4fd1a2aedb65994e3548715105abcf Mon Sep 17 00:00:00 2001 From: Richard Quadling Date: Thu, 19 Dec 2019 17:51:41 +0000 Subject: [PATCH 12/13] ## 3.2.7 - 2019-12-19 ### Fixes - Reinstated the `@method` return type for `Assert\LazyAssertion` methods to show that the return type is `LazyAssertion`. --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8fd187f2..05570ce1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # 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 From 98cb7e9c48a52c066750afbef0b6427999931670 Mon Sep 17 00:00:00 2001 From: Alessandro Ronchi Date: Fri, 20 Nov 2020 14:44:47 +0100 Subject: [PATCH 13/13] Add new assertion Assert\Assertion::ulid() --- CHANGELOG.md | 5 + README.md | 1 + lib/Assert/Assert.php | 11 - lib/Assert/Assertion.php | 295 ++---------------- lib/Assert/AssertionChain.php | 8 +- lib/Assert/AssertionFailedException.php | 3 - lib/Assert/InvalidArgumentException.php | 2 - lib/Assert/LazyAssertion.php | 8 +- lib/Assert/LazyAssertionException.php | 2 - lib/Assert/functions.php | 8 - tests/Assert/Tests/AssertTest.php | 130 +++++--- .../Tests/AssertionFailedExceptionTest.php | 2 - 12 files changed, 115 insertions(+), 360 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 05570ce1..a933b8b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # Change Log All notable changes to this project will be documented in this file. +## 3.3 - 2020-11-20 + +### Added assertions +- `Assert\Assertion::ulid()` + ## 3.2.7 - 2019-12-19 ### Fixes diff --git a/README.md b/README.md index 2b934c67..504836ea 100644 --- a/README.md +++ b/README.md @@ -265,6 +265,7 @@ Assertion::startsWith(mixed $string, string $needle); Assertion::string(mixed $value); Assertion::subclassOf(mixed $value, string $className); Assertion::true(mixed $value); +Assertion::ulid(string $value); Assertion::url(mixed $value); Assertion::uuid(string $value); Assertion::version(string $version1, string $operator, string $version2); diff --git a/lib/Assert/Assert.php b/lib/Assert/Assert.php index 6910258d..3614b345 100644 --- a/lib/Assert/Assert.php +++ b/lib/Assert/Assert.php @@ -33,9 +33,6 @@ abstract class Assert * * @param mixed $value * @param string|callable|null $defaultMessage - * @param string|null $defaultPropertyPath - * - * @return AssertionChain * * @example * @@ -57,9 +54,6 @@ public static function that($value, $defaultMessage = null, string $defaultPrope * * @param mixed $values * @param string|callable|null $defaultMessage - * @param string|null $defaultPropertyPath - * - * @return AssertionChain */ public static function thatAll($values, $defaultMessage = null, string $defaultPropertyPath = null): AssertionChain { @@ -71,9 +65,6 @@ public static function thatAll($values, $defaultMessage = null, string $defaultP * * @param mixed $value * @param string|callable|null $defaultMessage - * @param string|null $defaultPropertyPath - * - * @return AssertionChain */ public static function thatNullOr($value, $defaultMessage = null, string $defaultPropertyPath = null): AssertionChain { @@ -82,8 +73,6 @@ public static function thatNullOr($value, $defaultMessage = null, string $defaul /** * Create a lazy assertion object. - * - * @return LazyAssertion */ public static function lazy(): LazyAssertion { diff --git a/lib/Assert/Assertion.php b/lib/Assert/Assertion.php index a8b04e52..b0fffa38 100644 --- a/lib/Assert/Assertion.php +++ b/lib/Assert/Assertion.php @@ -114,6 +114,7 @@ * @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 allUlid(string[] $value, string|callable $message = null, string $propertyPath = null) Assert that the given string is a valid ULID 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. @@ -202,6 +203,7 @@ * @method static bool nullOrString(mixed|null $value, string|callable $message = null, string $propertyPath = null) Assert that value is a string or that the value is null. * @method static bool nullOrSubclassOf(mixed|null $value, string $className, string|callable $message = null, string $propertyPath = null) Assert that value is subclass of given class-name or that the value is null. * @method static bool nullOrTrue(mixed|null $value, string|callable $message = null, string $propertyPath = null) Assert that the value is boolean True or that the value is null. + * @method static bool nullOrUlid(string|null $value, string|callable $message = null, string $propertyPath = null) Assert that the given string is a valid ULID or that the value is null. * @method static bool nullOrUrl(mixed|null $value, string|callable $message = null, string $propertyPath = null) Assert that value is an URL or that the value is null. * @method static bool nullOrUuid(string|null $value, string|callable $message = null, string $propertyPath = null) Assert that the given string is a valid UUID or that the value is null. * @method static bool nullOrVersion(string|null $version1, string $operator, string $version2, string|callable $message = null, string $propertyPath = null) Assert comparison of two versions or that the value is null. @@ -287,6 +289,7 @@ class Assertion const INVALID_MIN_COUNT = 227; const INVALID_MAX_COUNT = 228; const INVALID_STRING_NOT_CONTAINS = 229; + const INVALID_ULID = 230; /** * Exception to throw when an assertion failed. @@ -301,9 +304,6 @@ class Assertion * @param mixed $value * @param mixed $value2 * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -328,9 +328,6 @@ public static function eq($value, $value2, $message = null, string $propertyPath * @param mixed $value * @param mixed $value2 * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -351,9 +348,6 @@ public static function eqArraySubset($value, $value2, $message = null, string $p * @param mixed $value * @param mixed $value2 * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -378,9 +372,6 @@ public static function same($value, $value2, $message = null, string $propertyPa * @param mixed $value1 * @param mixed $value2 * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -404,9 +395,6 @@ public static function notEq($value1, $value2, $message = null, string $property * @param mixed $value1 * @param mixed $value2 * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -428,11 +416,7 @@ public static function notSame($value1, $value2, $message = null, string $proper * Assert that value is not in array of choices. * * @param mixed $value - * @param array $choices * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -455,9 +439,6 @@ public static function notInArray($value, array $choices, $message = null, strin * * @param mixed $value * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -480,9 +461,6 @@ public static function integer($value, $message = null, string $propertyPath = n * * @param mixed $value * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -505,9 +483,6 @@ public static function float($value, $message = null, string $propertyPath = nul * * @param mixed $value * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -530,9 +505,6 @@ public static function digit($value, $message = null, string $propertyPath = nul * * @param mixed $value * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -568,9 +540,6 @@ public static function integerish($value, $message = null, string $propertyPath * * @param mixed $value * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -593,9 +562,6 @@ public static function boolean($value, $message = null, string $propertyPath = n * * @param mixed $value * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -618,9 +584,6 @@ public static function scalar($value, $message = null, string $propertyPath = nu * * @param mixed $value * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -643,9 +606,6 @@ public static function notEmpty($value, $message = null, string $propertyPath = * * @param mixed $value * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -668,9 +628,6 @@ public static function noContent($value, $message = null, string $propertyPath = * * @param mixed $value * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool */ public static function null($value, $message = null, string $propertyPath = null): bool { @@ -691,9 +648,6 @@ public static function null($value, $message = null, string $propertyPath = null * * @param mixed $value * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -716,7 +670,6 @@ public static function notNull($value, $message = null, string $propertyPath = n * * @param mixed $value * @param string|callable|null $message - * @param string|null $propertyPath * * @return bool * @@ -743,9 +696,6 @@ public static function string($value, $message = null, string $propertyPath = nu * @param mixed $value * @param string $pattern * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -771,9 +721,6 @@ public static function regex($value, $pattern, $message = null, string $property * @param mixed $value * @param string $pattern * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -799,11 +746,8 @@ public static function notRegex($value, $pattern, $message = null, string $prope * @param mixed $value * @param int $length * @param string|callable|null $message - * @param string|null $propertyPath * @param string $encoding * - * @return bool - * * @throws AssertionFailedException */ public static function length($value, $length, $message = null, string $propertyPath = null, $encoding = 'utf8'): bool @@ -830,11 +774,8 @@ public static function length($value, $length, $message = null, string $property * @param mixed $value * @param int $minLength * @param string|callable|null $message - * @param string|null $propertyPath * @param string $encoding * - * @return bool - * * @throws AssertionFailedException */ public static function minLength($value, $minLength, $message = null, string $propertyPath = null, $encoding = 'utf8'): bool @@ -861,11 +802,8 @@ public static function minLength($value, $minLength, $message = null, string $pr * @param mixed $value * @param int $maxLength * @param string|callable|null $message - * @param string|null $propertyPath * @param string $encoding * - * @return bool - * * @throws AssertionFailedException */ public static function maxLength($value, $maxLength, $message = null, string $propertyPath = null, $encoding = 'utf8'): bool @@ -893,11 +831,8 @@ public static function maxLength($value, $maxLength, $message = null, string $pr * @param int $minLength * @param int $maxLength * @param string|callable|null $message - * @param string|null $propertyPath * @param string $encoding * - * @return bool - * * @throws AssertionFailedException */ public static function betweenLength($value, $minLength, $maxLength, $message = null, string $propertyPath = null, $encoding = 'utf8'): bool @@ -915,11 +850,8 @@ public static function betweenLength($value, $minLength, $maxLength, $message = * @param mixed $string * @param string $needle * @param string|callable|null $message - * @param string|null $propertyPath * @param string $encoding * - * @return bool - * * @throws AssertionFailedException */ public static function startsWith($string, $needle, $message = null, string $propertyPath = null, $encoding = 'utf8'): bool @@ -945,11 +877,8 @@ public static function startsWith($string, $needle, $message = null, string $pro * @param mixed $string * @param string $needle * @param string|callable|null $message - * @param string|null $propertyPath * @param string $encoding * - * @return bool - * * @throws AssertionFailedException */ public static function endsWith($string, $needle, $message = null, string $propertyPath = null, $encoding = 'utf8'): bool @@ -977,11 +906,8 @@ public static function endsWith($string, $needle, $message = null, string $prope * @param mixed $string * @param string $needle * @param string|callable|null $message - * @param string|null $propertyPath * @param string $encoding * - * @return bool - * * @throws AssertionFailedException */ public static function contains($string, $needle, $message = null, string $propertyPath = null, $encoding = 'utf8'): bool @@ -1007,11 +933,8 @@ public static function contains($string, $needle, $message = null, string $prope * @param mixed $string * @param string $needle * @param string|callable|null $message - * @param string|null $propertyPath * @param string $encoding * - * @return bool - * * @throws AssertionFailedException */ public static function notContains($string, $needle, $message = null, string $propertyPath = null, $encoding = 'utf8'): bool @@ -1035,11 +958,7 @@ public static function notContains($string, $needle, $message = null, string $pr * Assert that value is in array of choices. * * @param mixed $value - * @param array $choices * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -1064,11 +983,7 @@ public static function choice($value, array $choices, $message = null, string $p * This is an alias of {@see choice()}. * * @param mixed $value - * @param array $choices * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -1082,9 +997,6 @@ public static function inArray($value, array $choices, $message = null, string $ * * @param mixed $value * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -1107,9 +1019,6 @@ public static function numeric($value, $message = null, string $propertyPath = n * * @param mixed $value * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool */ public static function isResource($value, $message = null, string $propertyPath = null): bool { @@ -1130,9 +1039,6 @@ public static function isResource($value, $message = null, string $propertyPath * * @param mixed $value * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -1155,9 +1061,6 @@ public static function isArray($value, $message = null, string $propertyPath = n * * @param mixed $value * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -1180,9 +1083,6 @@ public static function isTraversable($value, $message = null, string $propertyPa * * @param mixed $value * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -1205,9 +1105,6 @@ public static function isArrayAccessible($value, $message = null, string $proper * * @param array|Countable|ResourceBundle|SimpleXMLElement $value * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -1237,9 +1134,6 @@ public static function isCountable($value, $message = null, string $propertyPath * @param mixed $value * @param string|int $key * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -1265,9 +1159,6 @@ public static function keyExists($value, $key, $message = null, string $property * @param mixed $value * @param string|int $key * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -1293,9 +1184,6 @@ public static function keyNotExists($value, $key, $message = null, string $prope * @param mixed $value * @param string|int $key * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -1321,9 +1209,6 @@ public static function keyIsset($value, $key, $message = null, string $propertyP * @param mixed $value * @param string|int $key * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -1340,9 +1225,6 @@ public static function notEmptyKey($value, $key, $message = null, string $proper * * @param mixed $value * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -1366,9 +1248,6 @@ public static function notBlank($value, $message = null, string $propertyPath = * @param mixed $value * @param string $className * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -1393,9 +1272,6 @@ public static function isInstanceOf($value, $className, $message = null, string * @param mixed $value * @param string $className * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -1420,9 +1296,6 @@ public static function notIsInstanceOf($value, $className, $message = null, stri * @param mixed $value * @param string $className * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -1448,9 +1321,6 @@ public static function subclassOf($value, $className, $message = null, string $p * @param mixed $minValue * @param mixed $maxValue * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -1478,9 +1348,6 @@ public static function range($value, $minValue, $maxValue, $message = null, stri * @param mixed $value * @param mixed $minValue * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -1507,9 +1374,6 @@ public static function min($value, $minValue, $message = null, string $propertyP * @param mixed $value * @param mixed $maxValue * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -1535,9 +1399,6 @@ public static function max($value, $maxValue, $message = null, string $propertyP * * @param string $value * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -1563,9 +1424,6 @@ public static function file($value, $message = null, string $propertyPath = null * * @param string $value * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -1590,9 +1448,6 @@ public static function directory($value, $message = null, string $propertyPath = * * @param string $value * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -1617,9 +1472,6 @@ public static function readable($value, $message = null, string $propertyPath = * * @param string $value * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -1644,9 +1496,6 @@ public static function writeable($value, $message = null, string $propertyPath = * * @param mixed $value * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -1673,9 +1522,6 @@ public static function email($value, $message = null, string $propertyPath = nul * * @param mixed $value * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException * @@ -1725,9 +1571,6 @@ public static function url($value, $message = null, string $propertyPath = null) * * @param mixed $value * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -1752,9 +1595,6 @@ public static function alnum($value, $message = null, string $propertyPath = nul * * @param mixed $value * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -1777,9 +1617,6 @@ public static function true($value, $message = null, string $propertyPath = null * * @param mixed $value * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -1802,9 +1639,6 @@ public static function false($value, $message = null, string $propertyPath = nul * * @param mixed $value * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -1827,9 +1661,6 @@ public static function classExists($value, $message = null, string $propertyPath * * @param mixed $value * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -1853,9 +1684,6 @@ public static function interfaceExists($value, $message = null, string $property * @param mixed $class * @param string $interfaceName * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -1894,9 +1722,6 @@ public static function implementsInterface($class, $interfaceName, $message = nu * * @param mixed $value * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -1914,6 +1739,27 @@ public static function isJsonString($value, $message = null, string $propertyPat return true; } + /** + * Assert that the given string is a valid ULID. + * + * @param string|callable|null $message + * + * @throws AssertionFailedException + */ + public static function ulid(string $value, $message = null, string $propertyPath = null): bool + { + if (!\preg_match('/^[0123456789ABCDEFGHJKMNPQRSTVWXYZabcdefghjkmnpqrstvwxyz]{26}$/', $value)) { + $message = \sprintf( + static::generateMessage($message ?: 'Value "%s" is not a valid ULID.'), + static::stringify($value) + ); + + throw static::createException($value, $message, static::INVALID_ULID, $propertyPath); + } + + return true; + } + /** * Assert that the given string is a valid UUID. * @@ -1921,9 +1767,6 @@ public static function isJsonString($value, $message = null, string $propertyPat * * @param string $value * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -1954,9 +1797,6 @@ public static function uuid($value, $message = null, string $propertyPath = null * * @param string $value * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -1980,9 +1820,6 @@ public static function e164($value, $message = null, string $propertyPath = null * @param array|Countable|ResourceBundle|SimpleXMLElement $countable * @param int $count * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -2007,9 +1844,6 @@ public static function count($countable, $count, $message = null, string $proper * @param array|Countable|ResourceBundle|SimpleXMLElement $countable * @param int $count * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -2034,9 +1868,6 @@ public static function minCount($countable, $count, $message = null, string $pro * @param array|Countable|ResourceBundle|SimpleXMLElement $countable * @param int $count * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -2107,12 +1938,7 @@ public static function __callStatic($method, $args) /** * Determines if the values array has every choice as key and that this choice has content. * - * @param array $values - * @param array $choices * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -2133,9 +1959,6 @@ public static function choicesNotEmpty(array $values, array $choices, $message = * @param string $value * @param mixed $object * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -2160,9 +1983,6 @@ public static function methodExists($value, $object, $message = null, string $pr * * @param mixed $value * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -2186,9 +2006,6 @@ public static function isObject($value, $message = null, string $propertyPath = * @param mixed $value * @param mixed $limit * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -2213,9 +2030,6 @@ public static function lessThan($value, $limit, $message = null, string $propert * @param mixed $value * @param mixed $limit * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -2240,9 +2054,6 @@ public static function lessOrEqualThan($value, $limit, $message = null, string $ * @param mixed $value * @param mixed $limit * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -2267,9 +2078,6 @@ public static function greaterThan($value, $limit, $message = null, string $prop * @param mixed $value * @param mixed $limit * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -2297,8 +2105,6 @@ public static function greaterOrEqualThan($value, $limit, $message = null, strin * @param string|callable|null $message * @param string $propertyPath * - * @return bool - * * @throws AssertionFailedException */ public static function between($value, $lowerLimit, $upperLimit, $message = null, string $propertyPath = null): bool @@ -2326,8 +2132,6 @@ public static function between($value, $lowerLimit, $upperLimit, $message = null * @param string|callable|null $message * @param string $propertyPath * - * @return bool - * * @throws AssertionFailedException */ public static function betweenExclusive($value, $lowerLimit, $upperLimit, $message = null, string $propertyPath = null): bool @@ -2351,9 +2155,6 @@ public static function betweenExclusive($value, $lowerLimit, $upperLimit, $messa * * @param mixed $value * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -2378,9 +2179,6 @@ public static function extensionLoaded($value, $message = null, string $property * @param string $format supports all of the options date(), except for the following: * N, w, W, t, L, o, B, a, A, g, h, I, O, P, Z, c, r * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException * @@ -2411,9 +2209,6 @@ public static function date($value, $format, $message = null, string $propertyPa * * @param mixed $value * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -2432,9 +2227,6 @@ public static function objectOrClass($value, $message = null, string $propertyPa * @param mixed $value * @param string $property * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -2459,11 +2251,7 @@ public static function propertyExists($value, $property, $message = null, string * Assert that the value is an object or class, and that the properties all exist. * * @param mixed $value - * @param array $properties * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -2499,9 +2287,6 @@ public static function propertiesExist($value, array $properties, $message = nul * @param string $operator * @param string $version2 * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -2529,9 +2314,6 @@ public static function version($version1, $operator, $version2, $message = null, * @param string $operator * @param mixed $version * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -2549,9 +2331,6 @@ public static function phpVersion($operator, $version, $message = null, string $ * @param string $operator * @param mixed $version * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -2567,9 +2346,6 @@ public static function extensionVersion($extension, $operator, $version, $messag * * @param mixed $value * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -2595,9 +2371,6 @@ public static function isCallable($value, $message = null, string $propertyPath * @param mixed $value * @param callable $callback * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -2624,9 +2397,6 @@ public static function satisfy($value, $callback, $message = null, string $prope * @param string $value * @param int|null $flag * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException * @@ -2653,9 +2423,6 @@ public static function ip($value, $flag = null, $message = null, string $propert * @param string $value * @param int|null $flag * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException * @@ -2675,9 +2442,6 @@ public static function ipv4($value, $flag = null, $message = null, string $prope * @param string $value * @param int|null $flag * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException * @@ -2695,9 +2459,6 @@ public static function ipv6($value, $flag = null, $message = null, string $prope * * @param mixed $constant * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool */ public static function defined($constant, $message = null, string $propertyPath = null): bool { @@ -2715,9 +2476,6 @@ public static function defined($constant, $message = null, string $propertyPath * * @param string $value * @param string|callable|null $message - * @param string|null $propertyPath - * - * @return bool * * @throws AssertionFailedException */ @@ -2741,7 +2499,6 @@ public static function base64($value, $message = null, string $propertyPath = nu * @param string|callable|null $message * @param int $code * @param string|null $propertyPath - * @param array $constraints * * @return mixed */ @@ -2756,8 +2513,6 @@ protected static function createException($value, $message, $code, $propertyPath * Make a string version of a value. * * @param mixed $value - * - * @return string */ protected static function stringify($value): string { @@ -2790,8 +2545,6 @@ protected static function stringify($value): string * Generate the message. * * @param string|callable|null $message - * - * @return string */ protected static function generateMessage($message): string { diff --git a/lib/Assert/AssertionChain.php b/lib/Assert/AssertionChain.php index dbb6e839..2c884b78 100644 --- a/lib/Assert/AssertionChain.php +++ b/lib/Assert/AssertionChain.php @@ -106,6 +106,7 @@ * @method AssertionChain string(string|callable $message = null, string $propertyPath = null) Assert that value is a string. * @method AssertionChain subclassOf(string $className, string|callable $message = null, string $propertyPath = null) Assert that value is subclass of given class-name. * @method AssertionChain true(string|callable $message = null, string $propertyPath = null) Assert that the value is boolean True. + * @method AssertionChain ulid(string|callable $message = null, string $propertyPath = null) Assert that the given string is a valid ULID. * @method AssertionChain url(string|callable $message = null, string $propertyPath = null) Assert that value is an URL. * @method AssertionChain uuid(string|callable $message = null, string $propertyPath = null) Assert that the given string is a valid UUID. * @method AssertionChain version(string $operator, string $version2, string|callable $message = null, string $propertyPath = null) Assert comparison of two versions. @@ -150,7 +151,6 @@ class AssertionChain * * @param mixed $value * @param string|callable|null $defaultMessage - * @param string|null $defaultPropertyPath */ public function __construct($value, $defaultMessage = null, string $defaultPropertyPath = null) { @@ -164,8 +164,6 @@ public function __construct($value, $defaultMessage = null, string $defaultPrope * * @param string $methodName * @param array $args - * - * @return AssertionChain */ public function __call($methodName, $args): AssertionChain { @@ -208,8 +206,6 @@ public function __call($methodName, $args): AssertionChain /** * Switch chain into validation mode for an array of values. - * - * @return AssertionChain */ public function all(): AssertionChain { @@ -220,8 +216,6 @@ public function all(): AssertionChain /** * Switch chain into mode allowing nulls, ignoring further assertions. - * - * @return AssertionChain */ public function nullOr(): AssertionChain { diff --git a/lib/Assert/AssertionFailedException.php b/lib/Assert/AssertionFailedException.php index c1848388..7e0b2ec3 100644 --- a/lib/Assert/AssertionFailedException.php +++ b/lib/Assert/AssertionFailedException.php @@ -28,8 +28,5 @@ public function getPropertyPath(); */ public function getValue(); - /** - * @return array - */ public function getConstraints(): array; } diff --git a/lib/Assert/InvalidArgumentException.php b/lib/Assert/InvalidArgumentException.php index acd96654..9516e077 100644 --- a/lib/Assert/InvalidArgumentException.php +++ b/lib/Assert/InvalidArgumentException.php @@ -66,8 +66,6 @@ public function getValue() /** * Get the constraints that applied to the failed assertion. - * - * @return array */ public function getConstraints(): array { diff --git a/lib/Assert/LazyAssertion.php b/lib/Assert/LazyAssertion.php index 6ccd6423..1d5fbd2a 100644 --- a/lib/Assert/LazyAssertion.php +++ b/lib/Assert/LazyAssertion.php @@ -105,6 +105,7 @@ * @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 ulid(string|callable $message = null, string $propertyPath = null) Assert that the given string is a valid ULID. * @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. @@ -128,7 +129,6 @@ class LazyAssertion /** * @param mixed $value - * @param string|null $propertyPath * @param string|callable|null $defaultMessage * * @return static @@ -183,8 +183,6 @@ public function __call($method, $args) } /** - * @return bool - * * @throws LazyAssertionException */ public function verifyNow(): bool @@ -197,8 +195,6 @@ public function verifyNow(): bool } /** - * @param string $className - * * @return static */ public function setAssertClass(string $className) @@ -213,8 +209,6 @@ public function setAssertClass(string $className) } /** - * @param string $className - * * @return static */ public function setExceptionClass(string $className) diff --git a/lib/Assert/LazyAssertionException.php b/lib/Assert/LazyAssertionException.php index f76ecc69..2ba59dd7 100644 --- a/lib/Assert/LazyAssertionException.php +++ b/lib/Assert/LazyAssertionException.php @@ -23,8 +23,6 @@ class LazyAssertionException extends InvalidArgumentException /** * @param InvalidArgumentException[] $errors - * - * @return self */ public static function fromErrors(array $errors): self { diff --git a/lib/Assert/functions.php b/lib/Assert/functions.php index e0ccbd7d..1a4e84d9 100644 --- a/lib/Assert/functions.php +++ b/lib/Assert/functions.php @@ -24,8 +24,6 @@ * @param string|callable|null $defaultMessage * @param string $defaultPropertyPath * - * @return AssertionChain - * * @example * * \Assert\that($value)->notEmpty()->integer(); @@ -45,8 +43,6 @@ function that($value, $defaultMessage = null, string $defaultPropertyPath = null * @param mixed $values * @param string|callable|null $defaultMessage * @param string $defaultPropertyPath - * - * @return AssertionChain */ function thatAll($values, $defaultMessage = null, string $defaultPropertyPath = null): AssertionChain { @@ -60,8 +56,6 @@ function thatAll($values, $defaultMessage = null, string $defaultPropertyPath = * @param string|callable|null $defaultMessage * @param string $defaultPropertyPath * - * @return AssertionChain - * * @deprecated In favour of Assert::thatNullOr($value, $defaultMessage = null, $defaultPropertyPath = null) */ function thatNullOr($value, $defaultMessage = null, string $defaultPropertyPath = null): AssertionChain @@ -71,8 +65,6 @@ function thatNullOr($value, $defaultMessage = null, string $defaultPropertyPath /** * Create a lazy assertion object. - * - * @return LazyAssertion */ function lazy(): LazyAssertion { diff --git a/tests/Assert/Tests/AssertTest.php b/tests/Assert/Tests/AssertTest.php index f989f0ad..da987f8a 100644 --- a/tests/Assert/Tests/AssertTest.php +++ b/tests/Assert/Tests/AssertTest.php @@ -18,28 +18,17 @@ use ArrayObject; use Assert\Assertion; use Assert\Tests\Fixtures\OneCountable; -use BadMethodCallException; use Countable; use DateTime; use Exception; use Foo; -use InvalidArgumentException; use PHPUnit\Framework\TestCase; +use function range; 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 { @@ -145,7 +134,7 @@ public function dataInvalidIntegerish(): array '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'], @@ -579,7 +568,7 @@ public function dataInvalidArray(): array [1], [1.23], [new stdClass()], - [fopen('php://memory', 'r')], + [\fopen('php://memory', 'r')], ]; } @@ -1007,10 +996,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() @@ -1078,7 +1067,7 @@ public function testNullOr() } /** - * @expectedException BadMethodCallException + * @expectedException \BadMethodCallException * @expectedExceptionMessage Missing the first argument. */ public function testNullOrWithNoValueThrows() @@ -1185,13 +1174,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() @@ -1248,8 +1237,8 @@ public function testIsJsonString($content) 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"}'], ]; @@ -1275,6 +1264,53 @@ public function isJsonStringInvalidStringDataprovider(): array ]; } + /** + * @dataProvider providesValidUlids + * + * @param string $ulid + */ + public function testValidUlids($ulid) + { + $this->assertTrue(Assertion::ulid($ulid)); + } + + /** + * @dataProvider providesInvalidUlids + * @expectedException \Assert\AssertionFailedException + * @expectedExceptionCode \Assert\Assertion::INVALID_ULID + * + * @param string $ulid + */ + public function testInvalidUlids($ulid) + { + Assertion::ulid($ulid); + } + + public function providesValidUlids(): array + { + return [ + ['01BX5ZZKBKACTAV9WEVGEMMVRY'], + ['01BX5ZZKBKACTAV9WEVGEMMVRZ'], + ['01BX5ZZKBKACTAV9WEVGEMMVS0'], + ['01BX5ZZKBKACTAV9WEVGEMMVS1'], + ['01BX5ZZKBKZZZZZZZZZZZZZZZX'], + ['01BX5ZZKBKZZZZZZZZZZZZZZZY'], + ['01BX5ZZKBKZZZZZZZZZZZZZZZZ'], + ]; + } + + public function providesInvalidUlids(): array + { + return [ + 'uuid' => ['ff6f8cb0-c57d-11e1-9b21-0800200c9a66'], + 'too long' => ['0123456789ABCDEFGHJKMNPQRSTVWXYZ'], + 'contains unallowed I' => ['01BX5ZZKBKICTAV9WEVGEMMVRY'], + 'contains unallowed L' => ['01BX5ZZKBKLCTAV9WEVGEMMVRY'], + 'contains unallowed O' => ['01BX5ZZKBKOCTAV9WEVGEMMVRY'], + 'contains unallowed U' => ['01BX5ZZKBKUCTAV9WEVGEMMVRY'], + ]; + } + /** * @dataProvider providesValidUuids * @@ -1418,7 +1454,7 @@ public function testAllWithComplexAssertionThrowsExceptionOnElementThatFailsAsse } /** - * @expectedException BadMethodCallException + * @expectedException \BadMethodCallException */ public function testAllWithNoValueThrows() { @@ -1488,7 +1524,7 @@ public function dataInvalidMinCount(): \Generator 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')) { + if (\extension_loaded('intl')) { yield '6 countable while at least 7 expected' => [new ResourceBundle('en_US', __DIR__.'/_files/ResourceBundle'), 7]; } } @@ -1528,7 +1564,7 @@ public function dataInvalidMaxCount(): \Generator 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')) { + if (\extension_loaded('intl')) { yield '6 countable while at most 5 expected' => [new ResourceBundle('en_US', __DIR__.'/_files/ResourceBundle'), 5]; } } @@ -1873,7 +1909,7 @@ public function testInvalidSatisfy() Assertion::satisfy( null, function ($value): bool { - return !is_null($value); + return !\is_null($value); } ); } @@ -1884,8 +1920,8 @@ public function testValidSatisfy() $this->assertTrue( Assertion::satisfy( null, - function ($value) : bool { - return is_null($value); + function ($value): bool { + return \is_null($value); } ) ); @@ -1898,7 +1934,7 @@ function ($value) : bool { * @return bool|void */ function ($value) { - if (!is_bool($value)) { + if (!\is_bool($value)) { return false; } } @@ -2098,7 +2134,7 @@ public function providerValidBetweenExclusive(): array */ public function testStringifyTruncatesStringValuesLongerThan100CharactersAppropriately() { - $string = str_repeat('1234567890', 11); + $string = \str_repeat('1234567890', 11); $this->assertTrue(Assertion::float($string)); } @@ -2110,7 +2146,7 @@ public function testStringifyTruncatesStringValuesLongerThan100CharactersAppropr */ public function testStringifyTruncatesStringValuesLongerThan100CharactersAppropriatelyAndIsMultibyteValid() { - $string = str_repeat('ငါကနံပါတ်မဟုတ်ဘူး', 11); + $string = \str_repeat('ငါကနံပါတ်မဟုတ်ဘူး', 11); $this->assertTrue(Assertion::float($string)); } @@ -2122,7 +2158,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() @@ -2131,7 +2167,7 @@ public function testExtensionLoaded() } /** - * @expectedException InvalidArgumentException + * @expectedException \InvalidArgumentException */ public function testExtensionNotLoaded() { @@ -2144,7 +2180,7 @@ public function testValidConstant() } /** - * @expectedException InvalidArgumentException + * @expectedException \InvalidArgumentException */ public function testInvalidConstant() { @@ -2157,7 +2193,7 @@ public function testValidVersion() } /** - * @expectedException InvalidArgumentException + * @expectedException \InvalidArgumentException */ public function testInvalidVersion() { @@ -2165,7 +2201,7 @@ public function testInvalidVersion() } /** - * @expectedException InvalidArgumentException + * @expectedException \InvalidArgumentException */ public function testInvalidVersionOperator() { @@ -2178,7 +2214,7 @@ public function testValidPhpVersion() } /** - * @expectedException InvalidArgumentException + * @expectedException \InvalidArgumentException */ public function testInvalidPhpVersion() { @@ -2191,7 +2227,7 @@ public function testValidExtensionVersion() } /** - * @expectedException InvalidArgumentException + * @expectedException \InvalidArgumentException */ public function testInvalidExtensionVersion() { @@ -2205,7 +2241,7 @@ public function testObjectOrClass() } /** - * @expectedException InvalidArgumentException + * @expectedException \InvalidArgumentException */ public function testNotObjectOrClass() { @@ -2218,7 +2254,7 @@ public function testPropertyExists() } /** - * @expectedException InvalidArgumentException + * @expectedException \InvalidArgumentException * @expectedExceptionCode \Assert\Assertion::INVALID_PROPERTY */ public function testInvalidPropertyExists() @@ -2241,7 +2277,7 @@ public function invalidPropertiesExistProvider(): array /** * @dataProvider invalidPropertiesExistProvider - * @expectedException InvalidArgumentException + * @expectedException \InvalidArgumentException * @expectedExceptionCode \Assert\Assertion::INVALID_PROPERTY * * @param array $properties @@ -2253,11 +2289,11 @@ public function testInvalidPropertiesExist($properties) public function testIsResource() { - self::assertTrue(Assertion::isResource(curl_init())); + self::assertTrue(Assertion::isResource(\curl_init())); } /** - * @expectedException InvalidArgumentException + * @expectedException \InvalidArgumentException */ public function testIsNotResource() { @@ -2266,13 +2302,13 @@ public function testIsNotResource() public function testBase64() { - $base64String = base64_encode('content'); + $base64String = \base64_encode('content'); $this->assertTrue(Assertion::base64($base64String)); } /** - * @expectedException InvalidArgumentException + * @expectedException \InvalidArgumentException * @expectedExceptionCode \Assert\Assertion::INVALID_BASE64 */ public function testNotBase64() @@ -2313,7 +2349,7 @@ public function testEqArraySubsetValid() /** * @dataProvider invalidEqArraySubsetProvider * - * @expectedException InvalidArgumentException + * @expectedException \InvalidArgumentException * @expectedExceptionCode \Assert\Assertion::INVALID_ARRAY */ public function testEqArraySubsetInvalid($value, $value2) @@ -2324,7 +2360,7 @@ public function testEqArraySubsetInvalid($value, $value2) /** * @dataProvider invalidEqArraySubsetProvider * - * @expectedException InvalidArgumentException + * @expectedException \InvalidArgumentException * @expectedExceptionCode \Assert\Assertion::INVALID_EQ */ public function testEqArraySubsetMismatchingSubset() diff --git a/tests/Assert/Tests/AssertionFailedExceptionTest.php b/tests/Assert/Tests/AssertionFailedExceptionTest.php index c5d9c25e..6c650b95 100644 --- a/tests/Assert/Tests/AssertionFailedExceptionTest.php +++ b/tests/Assert/Tests/AssertionFailedExceptionTest.php @@ -25,8 +25,6 @@ class AssertionFailedExceptionTest extends TestCase { /** - * @param string $exceptionClass - * * @dataProvider provideExceptionClasses */ public function testFailedExceptionIsAValidThrowable(string $exceptionClass)