diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 336acada1..e71b2d011 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -19,9 +19,9 @@ jobs: strategy: matrix: php-version: - - "8.0" - "8.1" - "8.2" + - "8.3" steps: - name: Checkout @@ -62,7 +62,7 @@ jobs: - name: Install PHP uses: shivammathur/setup-php@v2 with: - php-version: 8.0 + php-version: 8.1 coverage: pcov extensions: uopz tools: pecl @@ -96,7 +96,7 @@ jobs: - name: Install PHP uses: shivammathur/setup-php@v2 with: - php-version: 8.0 + php-version: 8.3 coverage: none - name: Install dependencies diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d082d4fa..2401151f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ Versioning Changes: - - Dropped support for PHP 7.4. + - Dropped support for PHP 8.0 and below. - Updated dev dependencies Deprecations: @@ -15,6 +15,9 @@ Deprecations: Fixes: - `KeySet` now reports which extra keys are causing the rule to fail. + - Ensure empty strings are never a valid currency code + - Do not hide messages on EachException + - Dot not throw exception when validating an uninitialized property Changes: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0cb5c2f87..a760063c4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -157,7 +157,7 @@ final class HelloWorldTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new HelloWorld(); @@ -169,7 +169,7 @@ final class HelloWorldTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new HelloWorld(); diff --git a/composer.json b/composer.json index ebbeaaef4..a22c8339f 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ } }, "require": { - "php": "^8.0 || ^8.1 || ^8.2", + "php": "^8.1 || ^8.2", "respect/stringifier": "^0.2.0", "symfony/polyfill-mbstring": "^1.2" }, @@ -32,7 +32,7 @@ "phpstan/phpstan-phpunit": "^1.3", "phpunit/phpunit": "^9.6", "psr/http-message": "^1.0", - "respect/coding-standard": "^3.0", + "respect/coding-standard": "^4.0", "squizlabs/php_codesniffer": "^3.7" }, "suggest": { @@ -51,7 +51,10 @@ "psr-4": { "Respect\\Validation\\": "tests/unit/", "Respect\\Validation\\Test\\": "tests/library/" - } + }, + "files": [ + "tests/integration/lib/helpers.php" + ] }, "scripts": { "docheader": "vendor/bin/docheader check library/ tests/", diff --git a/data/domain/public-suffix/MUSEUM.php b/data/domain/public-suffix/MUSEUM.php deleted file mode 100644 index 6d225b42a..000000000 --- a/data/domain/public-suffix/MUSEUM.php +++ /dev/null @@ -1,551 +0,0 @@ - [ - self::STANDARD => '{{name}} must exists', + self::STANDARD => '{{name}} must exist', ], self::MODE_NEGATIVE => [ - self::STANDARD => '{{name}} must not exists', + self::STANDARD => '{{name}} must not exist', ], ]; } diff --git a/library/Exceptions/FalseValException.php b/library/Exceptions/FalseValException.php index 988df2912..37a78cc5c 100644 --- a/library/Exceptions/FalseValException.php +++ b/library/Exceptions/FalseValException.php @@ -20,10 +20,10 @@ final class FalseValException extends ValidationException */ protected $defaultTemplates = [ self::MODE_DEFAULT => [ - self::STANDARD => '{{name}} is not considered as "False"', + self::STANDARD => '{{name}} must evaluate to `false`', ], self::MODE_NEGATIVE => [ - self::STANDARD => '{{name}} is considered as "False"', + self::STANDARD => '{{name}} must not evaluate to `false`', ], ]; } diff --git a/library/Exceptions/NoException.php b/library/Exceptions/NoException.php index b29b24144..227b5a93e 100644 --- a/library/Exceptions/NoException.php +++ b/library/Exceptions/NoException.php @@ -19,10 +19,10 @@ final class NoException extends ValidationException */ protected $defaultTemplates = [ self::MODE_DEFAULT => [ - self::STANDARD => '{{name}} is not considered as "No"', + self::STANDARD => '{{name}} must be similar to "No"', ], self::MODE_NEGATIVE => [ - self::STANDARD => '{{name}} is considered as "No"', + self::STANDARD => '{{name}} must not be similar to "No"', ], ]; } diff --git a/library/Exceptions/TrueValException.php b/library/Exceptions/TrueValException.php index 4e186caeb..f0a4fe2a1 100644 --- a/library/Exceptions/TrueValException.php +++ b/library/Exceptions/TrueValException.php @@ -22,10 +22,10 @@ final class TrueValException extends ValidationException */ protected $defaultTemplates = [ self::MODE_DEFAULT => [ - self::STANDARD => '{{name}} is not considered as "True"', + self::STANDARD => '{{name}} must evaluate to `true`', ], self::MODE_NEGATIVE => [ - self::STANDARD => '{{name}} is considered as "True"', + self::STANDARD => '{{name}} must not evaluate to `true`', ], ]; } diff --git a/library/Exceptions/YesException.php b/library/Exceptions/YesException.php index 132e178b7..7df71f097 100644 --- a/library/Exceptions/YesException.php +++ b/library/Exceptions/YesException.php @@ -20,10 +20,10 @@ final class YesException extends ValidationException */ protected $defaultTemplates = [ self::MODE_DEFAULT => [ - self::STANDARD => '{{name}} is not considered as "Yes"', + self::STANDARD => '{{name}} must be similar to "Yes"', ], self::MODE_NEGATIVE => [ - self::STANDARD => '{{name}} is considered as "Yes"', + self::STANDARD => '{{name}} must not be similar to "Yes"', ], ]; } diff --git a/library/Rules/Attribute.php b/library/Rules/Attribute.php index e1873f13a..05518277b 100644 --- a/library/Rules/Attribute.php +++ b/library/Rules/Attribute.php @@ -17,7 +17,7 @@ use function property_exists; /** - * Validates an object attribute, event private ones. + * Validates an object attribute, even private ones. * * @author Alexandre Gomes Gaigalas * @author Emmerson Siqueira @@ -38,7 +38,9 @@ public function __construct(string $reference, ?Validatable $rule = null, bool $ public function getReferenceValue($input) { $propertyMirror = new ReflectionProperty($input, (string) $this->getReference()); - $propertyMirror->setAccessible(true); + if ($propertyMirror->isInitialized($input) === false) { + return null; + } return $propertyMirror->getValue($input); } diff --git a/library/Rules/CurrencyCode.php b/library/Rules/CurrencyCode.php index 4c3ab8954..c0f91d31a 100644 --- a/library/Rules/CurrencyCode.php +++ b/library/Rules/CurrencyCode.php @@ -23,6 +23,8 @@ final class CurrencyCode extends AbstractSearcher * @see http://www.currency-iso.org/en/home/tables/table-a1.html * * {@inheritDoc} + * + * @return string[] */ protected function getDataSource($input = null): array { diff --git a/library/Rules/Json.php b/library/Rules/Json.php index 5ce14fc04..64b263f5c 100644 --- a/library/Rules/Json.php +++ b/library/Rules/Json.php @@ -13,6 +13,7 @@ use function is_string; use function json_decode; use function json_last_error; +use function json_validate; use const JSON_ERROR_NONE; diff --git a/library/Rules/Tld.php b/library/Rules/Tld.php index 3e2e44009..42ce87e83 100644 --- a/library/Rules/Tld.php +++ b/library/Rules/Tld.php @@ -27,25 +27,25 @@ final class Tld extends AbstractRule * List extracted from https://data.iana.org/TLD/tlds-alpha-by-domain.txt */ private const TLD_LIST = [ - 'AAA', 'AARP', 'ABARTH', 'ABB', 'ABBOTT', 'ABBVIE', 'ABC', 'ABLE', - 'ABOGADO', 'ABUDHABI', 'AC', 'ACADEMY', 'ACCENTURE', 'ACCOUNTANT', - 'ACCOUNTANTS', 'ACO', 'ACTOR', 'AD', 'ADS', 'ADULT', 'AE', 'AEG', - 'AERO', 'AETNA', 'AF', 'AFL', 'AFRICA', 'AG', 'AGAKHAN', 'AGENCY', - 'AI', 'AIG', 'AIRBUS', 'AIRFORCE', 'AIRTEL', 'AKDN', 'AL', 'ALFAROMEO', - 'ALIBABA', 'ALIPAY', 'ALLFINANZ', 'ALLSTATE', 'ALLY', 'ALSACE', - 'ALSTOM', 'AM', 'AMAZON', 'AMERICANEXPRESS', 'AMERICANFAMILY', 'AMEX', - 'AMFAM', 'AMICA', 'AMSTERDAM', 'ANALYTICS', 'ANDROID', 'ANQUAN', 'ANZ', - 'AO', 'AOL', 'APARTMENTS', 'APP', 'APPLE', 'AQ', 'AQUARELLE', 'AR', - 'ARAB', 'ARAMCO', 'ARCHI', 'ARMY', 'ARPA', 'ART', 'ARTE', 'AS', 'ASDA', - 'ASIA', 'ASSOCIATES', 'AT', 'ATHLETA', 'ATTORNEY', 'AU', 'AUCTION', - 'AUDI', 'AUDIBLE', 'AUDIO', 'AUSPOST', 'AUTHOR', 'AUTO', 'AUTOS', - 'AVIANCA', 'AW', 'AWS', 'AX', 'AXA', 'AZ', 'AZURE', 'BA', 'BABY', - 'BAIDU', 'BANAMEX', 'BANANAREPUBLIC', 'BAND', 'BANK', 'BAR', - 'BARCELONA', 'BARCLAYCARD', 'BARCLAYS', 'BAREFOOT', 'BARGAINS', - 'BASEBALL', 'BASKETBALL', 'BAUHAUS', 'BAYERN', 'BB', 'BBC', 'BBT', - 'BBVA', 'BCG', 'BCN', 'BD', 'BE', 'BEATS', 'BEAUTY', 'BEER', 'BENTLEY', - 'BERLIN', 'BEST', 'BESTBUY', 'BET', 'BF', 'BG', 'BH', 'BHARTI', 'BI', - 'BIBLE', 'BID', 'BIKE', 'BING', 'BINGO', 'BIO', 'BIZ', 'BJ', 'BLACK', + 'AAA', 'AARP', 'ABB', 'ABBOTT', 'ABBVIE', 'ABC', 'ABLE', 'ABOGADO', + 'ABUDHABI', 'AC', 'ACADEMY', 'ACCENTURE', 'ACCOUNTANT', 'ACCOUNTANTS', + 'ACO', 'ACTOR', 'AD', 'ADS', 'ADULT', 'AE', 'AEG', 'AERO', 'AETNA', + 'AF', 'AFL', 'AFRICA', 'AG', 'AGAKHAN', 'AGENCY', 'AI', 'AIG', + 'AIRBUS', 'AIRFORCE', 'AIRTEL', 'AKDN', 'AL', 'ALIBABA', 'ALIPAY', + 'ALLFINANZ', 'ALLSTATE', 'ALLY', 'ALSACE', 'ALSTOM', 'AM', 'AMAZON', + 'AMERICANEXPRESS', 'AMERICANFAMILY', 'AMEX', 'AMFAM', 'AMICA', + 'AMSTERDAM', 'ANALYTICS', 'ANDROID', 'ANQUAN', 'ANZ', 'AO', 'AOL', + 'APARTMENTS', 'APP', 'APPLE', 'AQ', 'AQUARELLE', 'AR', 'ARAB', + 'ARAMCO', 'ARCHI', 'ARMY', 'ARPA', 'ART', 'ARTE', 'AS', 'ASDA', 'ASIA', + 'ASSOCIATES', 'AT', 'ATHLETA', 'ATTORNEY', 'AU', 'AUCTION', 'AUDI', + 'AUDIBLE', 'AUDIO', 'AUSPOST', 'AUTHOR', 'AUTO', 'AUTOS', 'AVIANCA', + 'AW', 'AWS', 'AX', 'AXA', 'AZ', 'AZURE', 'BA', 'BABY', 'BAIDU', + 'BANAMEX', 'BANANAREPUBLIC', 'BAND', 'BANK', 'BAR', 'BARCELONA', + 'BARCLAYCARD', 'BARCLAYS', 'BAREFOOT', 'BARGAINS', 'BASEBALL', + 'BASKETBALL', 'BAUHAUS', 'BAYERN', 'BB', 'BBC', 'BBT', 'BBVA', 'BCG', + 'BCN', 'BD', 'BE', 'BEATS', 'BEAUTY', 'BEER', 'BENTLEY', 'BERLIN', + 'BEST', 'BESTBUY', 'BET', 'BF', 'BG', 'BH', 'BHARTI', 'BI', 'BIBLE', + 'BID', 'BIKE', 'BING', 'BINGO', 'BIO', 'BIZ', 'BJ', 'BLACK', 'BLACKFRIDAY', 'BLOCKBUSTER', 'BLOG', 'BLOOMBERG', 'BLUE', 'BM', 'BMS', 'BMW', 'BN', 'BNPPARIBAS', 'BO', 'BOATS', 'BOEHRINGER', 'BOFA', 'BOM', 'BOND', 'BOO', 'BOOK', 'BOOKING', 'BOSCH', 'BOSTIK', 'BOSTON', 'BOT', @@ -82,11 +82,11 @@ final class Tld extends AbstractRule 'EUROVISION', 'EUS', 'EVENTS', 'EXCHANGE', 'EXPERT', 'EXPOSED', 'EXPRESS', 'EXTRASPACE', 'FAGE', 'FAIL', 'FAIRWINDS', 'FAITH', 'FAMILY', 'FAN', 'FANS', 'FARM', 'FARMERS', 'FASHION', 'FAST', 'FEDEX', - 'FEEDBACK', 'FERRARI', 'FERRERO', 'FI', 'FIAT', 'FIDELITY', 'FIDO', - 'FILM', 'FINAL', 'FINANCE', 'FINANCIAL', 'FIRE', 'FIRESTONE', - 'FIRMDALE', 'FISH', 'FISHING', 'FIT', 'FITNESS', 'FJ', 'FK', 'FLICKR', - 'FLIGHTS', 'FLIR', 'FLORIST', 'FLOWERS', 'FLY', 'FM', 'FO', 'FOO', - 'FOOD', 'FOODNETWORK', 'FOOTBALL', 'FORD', 'FOREX', 'FORSALE', 'FORUM', + 'FEEDBACK', 'FERRARI', 'FERRERO', 'FI', 'FIDELITY', 'FIDO', 'FILM', + 'FINAL', 'FINANCE', 'FINANCIAL', 'FIRE', 'FIRESTONE', 'FIRMDALE', + 'FISH', 'FISHING', 'FIT', 'FITNESS', 'FJ', 'FK', 'FLICKR', 'FLIGHTS', + 'FLIR', 'FLORIST', 'FLOWERS', 'FLY', 'FM', 'FO', 'FOO', 'FOOD', + 'FOODNETWORK', 'FOOTBALL', 'FORD', 'FOREX', 'FORSALE', 'FORUM', 'FOUNDATION', 'FOX', 'FR', 'FREE', 'FRESENIUS', 'FRL', 'FROGANS', 'FRONTDOOR', 'FRONTIER', 'FTR', 'FUJITSU', 'FUN', 'FUND', 'FURNITURE', 'FUTBOL', 'FYI', 'GA', 'GAL', 'GALLERY', 'GALLO', 'GALLUP', 'GAME', @@ -117,18 +117,17 @@ final class Tld extends AbstractRule 'KINDER', 'KINDLE', 'KITCHEN', 'KIWI', 'KM', 'KN', 'KOELN', 'KOMATSU', 'KOSHER', 'KP', 'KPMG', 'KPN', 'KR', 'KRD', 'KRED', 'KUOKGROUP', 'KW', 'KY', 'KYOTO', 'KZ', 'LA', 'LACAIXA', 'LAMBORGHINI', 'LAMER', - 'LANCASTER', 'LANCIA', 'LAND', 'LANDROVER', 'LANXESS', 'LASALLE', - 'LAT', 'LATINO', 'LATROBE', 'LAW', 'LAWYER', 'LB', 'LC', 'LDS', - 'LEASE', 'LECLERC', 'LEFRAK', 'LEGAL', 'LEGO', 'LEXUS', 'LGBT', 'LI', - 'LIDL', 'LIFE', 'LIFEINSURANCE', 'LIFESTYLE', 'LIGHTING', 'LIKE', - 'LILLY', 'LIMITED', 'LIMO', 'LINCOLN', 'LINDE', 'LINK', 'LIPSY', - 'LIVE', 'LIVING', 'LK', 'LLC', 'LLP', 'LOAN', 'LOANS', 'LOCKER', - 'LOCUS', 'LOL', 'LONDON', 'LOTTE', 'LOTTO', 'LOVE', 'LPL', - 'LPLFINANCIAL', 'LR', 'LS', 'LT', 'LTD', 'LTDA', 'LU', 'LUNDBECK', - 'LUXE', 'LUXURY', 'LV', 'LY', 'MA', 'MACYS', 'MADRID', 'MAIF', - 'MAISON', 'MAKEUP', 'MAN', 'MANAGEMENT', 'MANGO', 'MAP', 'MARKET', - 'MARKETING', 'MARKETS', 'MARRIOTT', 'MARSHALLS', 'MASERATI', 'MATTEL', - 'MBA', 'MC', 'MCKINSEY', 'MD', 'ME', 'MED', 'MEDIA', 'MEET', + 'LANCASTER', 'LAND', 'LANDROVER', 'LANXESS', 'LASALLE', 'LAT', + 'LATINO', 'LATROBE', 'LAW', 'LAWYER', 'LB', 'LC', 'LDS', 'LEASE', + 'LECLERC', 'LEFRAK', 'LEGAL', 'LEGO', 'LEXUS', 'LGBT', 'LI', 'LIDL', + 'LIFE', 'LIFEINSURANCE', 'LIFESTYLE', 'LIGHTING', 'LIKE', 'LILLY', + 'LIMITED', 'LIMO', 'LINCOLN', 'LINK', 'LIPSY', 'LIVE', 'LIVING', 'LK', + 'LLC', 'LLP', 'LOAN', 'LOANS', 'LOCKER', 'LOCUS', 'LOL', 'LONDON', + 'LOTTE', 'LOTTO', 'LOVE', 'LPL', 'LPLFINANCIAL', 'LR', 'LS', 'LT', + 'LTD', 'LTDA', 'LU', 'LUNDBECK', 'LUXE', 'LUXURY', 'LV', 'LY', 'MA', + 'MADRID', 'MAIF', 'MAISON', 'MAKEUP', 'MAN', 'MANAGEMENT', 'MANGO', + 'MAP', 'MARKET', 'MARKETING', 'MARKETS', 'MARRIOTT', 'MARSHALLS', + 'MATTEL', 'MBA', 'MC', 'MCKINSEY', 'MD', 'ME', 'MED', 'MEDIA', 'MEET', 'MELBOURNE', 'MEME', 'MEMORIAL', 'MEN', 'MENU', 'MERCKMSD', 'MG', 'MH', 'MIAMI', 'MICROSOFT', 'MIL', 'MINI', 'MINT', 'MIT', 'MITSUBISHI', 'MK', 'ML', 'MLB', 'MLS', 'MM', 'MMA', 'MN', 'MO', 'MOBI', 'MOBILE', 'MODA', diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 15934dc39..1ef752f92 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -14,5 +14,14 @@ library/ tests/ - + + + + + + + + + + diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 106a482a6..1fc2e5c1d 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -25,7 +25,14 @@ parameters: # Why: StaticValidator is a stub interface that types __callStatic message: '/Call to static method PHPUnit\\Framework\\Assert::assertSame\(\) with Respect\\Validation\\Validator and Respect\\Validation\\ChainedValidator will always evaluate to false./' path: tests/unit/ValidatorTest.php + + - + # Why: I don't want to make changes to the code just to make phpstan happy + message: '/Parameter #2 \$values of function vsprintf expects array, array\|bool\|float\|int\|string> given./' + path: library/Rules/AbstractAge.php level: 8 paths: - library/ - tests/ + excludePaths: + - tests/integration/ diff --git a/tests/integration/assert-with-attributes.phpt b/tests/integration/assert-with-attributes.phpt index 5180ddcab..57f62feb0 100644 --- a/tests/integration/assert-with-attributes.phpt +++ b/tests/integration/assert-with-attributes.phpt @@ -8,10 +8,9 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { +exceptionFullMessage(static function () { $array = [ 'mysql' => [ 'host' => 42, @@ -48,9 +47,7 @@ try { ) ->setName('the given data') ->assert($object); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +}); ?> --EXPECT-- - All of the required rules must pass for the given data diff --git a/tests/integration/assert-with-keys.phpt b/tests/integration/assert-with-keys.phpt index 3b5a5f2fa..895f1b1e2 100644 --- a/tests/integration/assert-with-keys.phpt +++ b/tests/integration/assert-with-keys.phpt @@ -7,10 +7,9 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { +exceptionFullMessage(static function () { v::create() ->key( 'mysql', @@ -41,9 +40,7 @@ try { 'password' => 42, ], ]); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +}); ?> --EXPECT-- - All of the required rules must pass for the given data diff --git a/tests/integration/get_full_message_should_include_all_validation_messages_in_a_chain.phpt b/tests/integration/get_full_message_should_include_all_validation_messages_in_a_chain.phpt index 00fd39b1b..80132a265 100644 --- a/tests/integration/get_full_message_should_include_all_validation_messages_in_a_chain.phpt +++ b/tests/integration/get_full_message_should_include_all_validation_messages_in_a_chain.phpt @@ -9,14 +9,9 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator; -try { - Validator::stringType()->length(2, 15)->assert(0); -} catch (NestedValidationException $e) { - echo $e->getFullMessage(); -} +exceptionFullMessage(static fn() => Validator::stringType()->length(2, 15)->assert(0)); ?> --EXPECT-- - All of the required rules must pass for 0 diff --git a/tests/integration/get_messages.phpt b/tests/integration/get_messages.phpt index 9510c9e57..8a629fd03 100644 --- a/tests/integration/get_messages.phpt +++ b/tests/integration/get_messages.phpt @@ -7,10 +7,9 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { +exceptionMessages(static function () { v::create() ->key( 'mysql', @@ -40,9 +39,7 @@ try { 'password' => 42, ], ]); -} catch (NestedValidationException $exception) { - print_r($exception->getMessages()); -} +}); ?> --EXPECT-- Array diff --git a/tests/integration/get_messages_should_include_all_validation_messages_in_a_chain.phpt b/tests/integration/get_messages_should_include_all_validation_messages_in_a_chain.phpt index 438f9b431..7d70803ee 100644 --- a/tests/integration/get_messages_should_include_all_validation_messages_in_a_chain.phpt +++ b/tests/integration/get_messages_should_include_all_validation_messages_in_a_chain.phpt @@ -11,10 +11,9 @@ date_default_timezone_set('UTC'); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator; -try { +exceptionMessages(static function () { $input = [ 'username' => 'u', 'birthdate' => 'Not a date', @@ -27,9 +26,7 @@ try { ->key('password', Validator::notEmpty()) ->key('email', Validator::email()) ->assert($input); -} catch (NestedValidationException $e) { - print_r($e->getMessages()); -} +}); ?> --EXPECT-- Array diff --git a/tests/integration/get_messages_with_replacements.phpt b/tests/integration/get_messages_with_replacements.phpt index 4a2ac31d1..e0e8e11f5 100644 --- a/tests/integration/get_messages_with_replacements.phpt +++ b/tests/integration/get_messages_with_replacements.phpt @@ -8,41 +8,41 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::create() - ->key( - 'mysql', - v::create() - ->key('host', v::stringType(), true) - ->key('user', v::stringType(), true) - ->key('password', v::stringType(), true) - ->key('schema', v::stringType(), true), - true - ) - ->key( - 'postgresql', - v::create() - ->key('host', v::stringType(), true) - ->key('user', v::stringType(), true) - ->key('password', v::stringType(), true) - ->key('schema', v::stringType(), true), - true - ) - ->assert([ - 'mysql' => [ - 'host' => 42, - 'schema' => 42, - ], - 'postgresql' => [ - 'user' => 42, - 'password' => 42, - ], - ]); -} catch (NestedValidationException $exception) { - print_r($exception->getMessages([ +exceptionMessages( + static function () { + v::create() + ->key( + 'mysql', + v::create() + ->key('host', v::stringType(), true) + ->key('user', v::stringType(), true) + ->key('password', v::stringType(), true) + ->key('schema', v::stringType(), true), + true + ) + ->key( + 'postgresql', + v::create() + ->key('host', v::stringType(), true) + ->key('user', v::stringType(), true) + ->key('password', v::stringType(), true) + ->key('schema', v::stringType(), true), + true + ) + ->assert([ + 'mysql' => [ + 'host' => 42, + 'schema' => 42, + ], + 'postgresql' => [ + 'user' => 42, + 'password' => 42, + ], + ]); + }, + [ 'mysql' => [ 'user' => 'Value should be a MySQL username', 'host' => '{{input}} should be a MySQL host', @@ -50,8 +50,8 @@ try { 'postgresql' => [ 'schema' => 'You must provide a valid PostgreSQL schema', ], - ])); -} + ] +); ?> --EXPECT-- Array diff --git a/tests/integration/issue-1033.phpt b/tests/integration/issue-1033.phpt index 430cb1bd1..d47bde25c 100644 --- a/tests/integration/issue-1033.phpt +++ b/tests/integration/issue-1033.phpt @@ -15,14 +15,9 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\AllOfException; use Respect\Validation\Validator as v; -try { - v::each(v::equals(1))->assert(['A', 'B', 'B']); -} catch (AllOfException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionFullMessage(static fn() => v::each(v::equals(1))->assert(['A', 'B', 'B'])); ?> --EXPECT-- - Each item in `{ "A", "B", "B" }` must be valid diff --git a/tests/integration/issue-1244.phpt b/tests/integration/issue-1244.phpt index f3409ff6b..6bc6bf299 100644 --- a/tests/integration/issue-1244.phpt +++ b/tests/integration/issue-1244.phpt @@ -5,15 +5,9 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::key('firstname', v::notBlank()->setName('First Name'))->assert([]); -} catch (NestedValidationException $e) { - print_r($e->getMessages()); -} - +exceptionMessages(static fn () => v::key('firstname', v::notBlank()->setName('First Name'))->assert([])); ?> --EXPECTF-- Array diff --git a/tests/integration/issue-1289.phpt b/tests/integration/issue-1289.phpt index 55716ab02..bae2c8aa1 100644 --- a/tests/integration/issue-1289.phpt +++ b/tests/integration/issue-1289.phpt @@ -10,8 +10,6 @@ default must be of type string declare(strict_types=1); -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\ValidationException; use Respect\Validation\Rules\ArrayType; use Respect\Validation\Rules\BoolType; use Respect\Validation\Rules\Each; @@ -55,17 +53,8 @@ $input = [ 'children' => ['nope'], ], ]; -try { - $validator->check($input); -} catch (ValidationException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - $validator->assert($input); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage(); -} +exceptionMessage(static fn() => $validator->check($input)); +exceptionFullMessage(static fn() => $validator->assert($input)); ?> --EXPECT-- default must be of type string diff --git a/tests/integration/issue-1348.phpt b/tests/integration/issue-1348.phpt index 62f41a447..e4d7956ab 100644 --- a/tests/integration/issue-1348.phpt +++ b/tests/integration/issue-1348.phpt @@ -7,17 +7,16 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator; $cars = [ ['manufacturer' => 'Honda', 'model' => 'Accord'], ['manufacturer' => 'Toyota', 'model' => 'Rav4'], - ['manufacturer' => 'Ford', 'model' => 'notarealcar'], + ['manufacturer' => 'Ford', 'model' => 'not real'], ['manufacturer' => 'Honda', 'model' => 'not valid'], ]; -try { +exceptionMessages(static function () use ($cars) { Validator::arrayType()->each( Validator::oneOf( Validator::key('manufacturer', Validator::equals('Honda')) @@ -28,19 +27,15 @@ try { ->key('model', Validator::in(['F150', 'Bronco'])) ) )->assert($cars); -} catch (NestedValidationException $e) { - var_dump($e->getMessages()); -} - - +}); ?> --EXPECT-- -array(1) { - ["each"]=> - array(2) { - ["validator.0"]=> - string(92) "All of the required rules must pass for `{ "manufacturer": "Ford", "model": "notarealcar" }`" - ["validator.1"]=> - string(91) "All of the required rules must pass for `{ "manufacturer": "Honda", "model": "not valid" }`" - } -} +Array +( + [each] => Array + ( + [validator.0] => All of the required rules must pass for `{ "manufacturer": "Ford", "model": "not real" }` + [validator.1] => All of the required rules must pass for `{ "manufacturer": "Honda", "model": "not valid" }` + ) + +) diff --git a/tests/integration/issue-179.phpt b/tests/integration/issue-179.phpt index 1fc73a0c5..46987a1e7 100644 --- a/tests/integration/issue-179.phpt +++ b/tests/integration/issue-179.phpt @@ -7,7 +7,6 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\AllOfException; use Respect\Validation\Validator as v; $config = [ @@ -23,11 +22,7 @@ $validator->key('user', v::stringType()); $validator->key('password', v::stringType()); $validator->key('schema', v::stringType()); -try { - $validator->assert($config); -} catch (AllOfException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionFullMessage(static fn() => $validator->assert($config)); ?> --EXPECT-- - These rules must pass for Settings diff --git a/tests/integration/issue-425.phpt b/tests/integration/issue-425.phpt index c9e7ef73d..ffe760861 100644 --- a/tests/integration/issue-425.phpt +++ b/tests/integration/issue-425.phpt @@ -7,26 +7,14 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\AllOfException; use Respect\Validation\Validator as v; $validator = v::create() ->key('age', v::intType()->notEmpty()->noneOf(v::stringType())) ->key('reference', v::stringType()->notEmpty()->length(1, 50)); -try { - $validator->assert(['age' => 1]); -} catch (AllOfException $e) { - echo $e->getFullMessage(); -} - -echo PHP_EOL; - -try { - $validator->assert(['reference' => 'QSF1234']); -} catch (AllOfException $e) { - echo $e->getFullMessage(); -} +exceptionFullMessage(static fn() => $validator->assert(['age' => 1])); +exceptionFullMessage(static fn() => $validator->assert(['reference' => 'QSF1234'])); ?> --EXPECT-- - These rules must pass for `{ "age": 1 }` diff --git a/tests/integration/issue-446.phpt b/tests/integration/issue-446.phpt index 6ed9e123c..72518bf7c 100644 --- a/tests/integration/issue-446.phpt +++ b/tests/integration/issue-446.phpt @@ -7,7 +7,6 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; $arr = [ @@ -15,14 +14,12 @@ $arr = [ 'email' => 'hello@hello.com', ]; -try { +exceptionMessages(static function () use ($arr) { v::create() ->key('name', v::length(2, 32)) ->key('email', v::email()) ->assert($arr); -} catch (NestedValidationException $e) { - print_r($e->getMessages()); -} +}); ?> --EXPECT-- Array diff --git a/tests/integration/issue-619.phpt b/tests/integration/issue-619.phpt index 977c21dfb..a8daa05d7 100644 --- a/tests/integration/issue-619.phpt +++ b/tests/integration/issue-619.phpt @@ -8,14 +8,11 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\ValidationException; use Respect\Validation\Rules\Instance; -try { +exceptionMessage(static function () { (new Instance('stdClass'))->setTemplate('invalid object')->assert('test'); -} catch (ValidationException $exception) { - print_r($exception->getMessage()); -} +}); ?> --EXPECT-- invalid object diff --git a/tests/integration/issue-727.phpt b/tests/integration/issue-727.phpt index 91b7721c9..e468578a4 100644 --- a/tests/integration/issue-727.phpt +++ b/tests/integration/issue-727.phpt @@ -7,7 +7,6 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\PhoneException; use Respect\Validation\Validator as v; $work = new stdClass(); @@ -26,7 +25,7 @@ $phoneNumbers->work = $work; $validateThis = ['phoneNumbers' => $phoneNumbers]; -try { +exceptionMessage(static function () use ($validateThis) { v::create() ->keyNested('phoneNumbers.personal.country', v::intType(), false) ->keyNested('phoneNumbers.personal.number', v::phone(), false) @@ -35,9 +34,7 @@ try { ->keyNested('phoneNumbers.work.number', v::phone(), false) ->keyNested('phoneNumbers.work.primary', v::boolType(), false) ->check($validateThis); -} catch (PhoneException $exception) { - echo $exception->getMessage(); -} +}); ?> --EXPECT-- phoneNumbers.personal.number must be a valid telephone number diff --git a/tests/integration/issue-739.phpt b/tests/integration/issue-739.phpt index d0f1c93bf..c135ed77a 100644 --- a/tests/integration/issue-739.phpt +++ b/tests/integration/issue-739.phpt @@ -7,14 +7,9 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\ValidationException; use Respect\Validation\Validator as v; -try { - v::when(v::alwaysInvalid(), v::alwaysValid())->check('foo'); -} catch (ValidationException $exception) { - echo $exception->getMessage(); -} +exceptionMessage(static fn() => v::when(v::alwaysInvalid(), v::alwaysValid())->check('foo')); ?> --EXPECT-- "foo" is not valid diff --git a/tests/integration/issue-796.phpt b/tests/integration/issue-796.phpt index e4e894746..f25ff38a9 100644 --- a/tests/integration/issue-796.phpt +++ b/tests/integration/issue-796.phpt @@ -8,10 +8,9 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { +exceptionFullMessage(static function () { v::create() ->key( 'mysql', @@ -46,9 +45,7 @@ try { 'schema' => 'schema', ], ]); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +}); ?> --EXPECT-- - All of the required rules must pass for the given data diff --git a/tests/integration/issue-799.phpt b/tests/integration/issue-799.phpt index 4e0752ef5..c0a3e40a0 100644 --- a/tests/integration/issue-799.phpt +++ b/tests/integration/issue-799.phpt @@ -7,24 +7,21 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\AllOfException; use Respect\Validation\Test\Stubs\CountableStub; use Respect\Validation\Validator as v; $input = 'http://www.google.com/search?q=respect.github.com'; -try { +exceptionMessage(static function () use ($input) { v::create() ->call( [new CountableStub(1), 'count'], v::arrayVal()->key('scheme', v::startsWith('https')) ) ->assert($input); -} catch (AllOfException $exception) { - echo $exception->getMessage() . PHP_EOL; -} +}); -try { +exceptionMessage(static function () use ($input) { v::create() ->call( static function ($url) { @@ -33,9 +30,7 @@ try { v::arrayVal()->key('scheme', v::startsWith('https')) ) ->assert($input); -} catch (AllOfException $exception) { - echo $exception->getMessage() . PHP_EOL; -} +}); ?> --EXPECT-- All of the required rules must pass for "http://www.google.com/search?q=respect.github.com" diff --git a/tests/integration/issue-805.phpt b/tests/integration/issue-805.phpt index e15f70699..ddded8737 100644 --- a/tests/integration/issue-805.phpt +++ b/tests/integration/issue-805.phpt @@ -8,14 +8,11 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { +exceptionMessages(static function () { v::key('email', v::email()->setTemplate('WRONG EMAIL!!!!!!'))->assert(['email' => 'qwe']); -} catch (NestedValidationException $exception) { - print_r($exception->getMessages()); -} +}); ?> --EXPECT-- Array diff --git a/tests/integration/keys_as_validator_names.phpt b/tests/integration/keys_as_validator_names.phpt index d8866dade..340143816 100644 --- a/tests/integration/keys_as_validator_names.phpt +++ b/tests/integration/keys_as_validator_names.phpt @@ -11,18 +11,15 @@ date_default_timezone_set('UTC'); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator; -try { +exceptionFullMessage(static function () { Validator::create() ->key('username', Validator::length(2, 32)) ->key('birthdate', Validator::dateTime()) ->setName('User Subscription Form') ->assert(['username' => '0', 'birthdate' => 'Whatever']); -} catch (NestedValidationException $e) { - echo $e->getFullMessage(); -} +}); ?> --EXPECT-- - All of the required rules must pass for User Subscription Form diff --git a/tests/integration/lib/helpers.php b/tests/integration/lib/helpers.php new file mode 100644 index 000000000..d00724de9 --- /dev/null +++ b/tests/integration/lib/helpers.php @@ -0,0 +1,41 @@ + + * SPDX-License-Identifier: MIT + */ + +declare(strict_types=1); + +use Respect\Validation\Exceptions\NestedValidationException; +use Respect\Validation\Exceptions\ValidationException; + +function exceptionMessage(callable $callable): void +{ + try { + $callable(); + } catch (ValidationException $exception) { + echo $exception->getMessage() . PHP_EOL; + } +} + +/** + * @param array> $templates + */ +function exceptionMessages(callable $callable, array $templates = []): void +{ + try { + $callable(); + } catch (NestedValidationException $exception) { + print_r($exception->getMessages($templates)); + } +} + +function exceptionFullMessage(callable $callable): void +{ + try { + $callable(); + } catch (NestedValidationException $exception) { + echo $exception->getFullMessage() . PHP_EOL; + } +} diff --git a/tests/integration/not_with_recursion.phpt b/tests/integration/not_with_recursion.phpt index 7b6cf0fc4..35a2a3a54 100644 --- a/tests/integration/not_with_recursion.phpt +++ b/tests/integration/not_with_recursion.phpt @@ -7,8 +7,6 @@ Henrique Moody require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\ValidationException; use Respect\Validation\Validator as v; $validator = v::not( @@ -23,17 +21,8 @@ $validator = v::not( ) ); -try { - $validator->check(2); -} catch (ValidationException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - $validator->assert(2); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => $validator->check(2)); +exceptionFullMessage(static fn() => $validator->assert(2)); ?> --EXPECT-- 2 must not be positive diff --git a/tests/integration/not_without_recursion.phpt b/tests/integration/not_without_recursion.phpt index f9b077b34..a2d7187a0 100644 --- a/tests/integration/not_without_recursion.phpt +++ b/tests/integration/not_without_recursion.phpt @@ -9,17 +9,14 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\ValidationException; use Respect\Validation\Validator; -try { +exceptionMessage(static function () { $validator = Validator::not( Validator::intVal()->positive() ); $validator->check(2); -} catch (ValidationException $exception) { - echo $exception->getMessage() . PHP_EOL; -} +}); ?> --EXPECT-- 2 must not be positive diff --git a/tests/integration/rules/allOf.phpt b/tests/integration/rules/allOf.phpt index d61d5b203..9326e3906 100644 --- a/tests/integration/rules/allOf.phpt +++ b/tests/integration/rules/allOf.phpt @@ -8,34 +8,14 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\AllOfException; -use Respect\Validation\Exceptions\ConsonantException; -use Respect\Validation\Exceptions\IntTypeException; use Respect\Validation\Validator as v; -try { - v::not(v::allOf(v::intType(), v::positive()))->check(42); -} catch (IntTypeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::allOf(v::stringType(), v::consonant())->check('Luke i\'m your father'); -} catch (ConsonantException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::allOf(v::stringType(), v::consonant())->assert(42); -} catch (AllOfException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { +exceptionMessage(static fn() => v::not(v::allOf(v::intType(), v::positive()))->check(42)); +exceptionMessage(static fn() => v::allOf(v::stringType(), v::consonant())->check('Luke i\'m your father')); +exceptionFullMessage(static fn() => v::allOf(v::stringType(), v::consonant())->assert(42)); +exceptionFullMessage(static function () { v::not(v::allOf(v::stringType(), v::length(10)))->assert('Frank Zappa is fantastic'); -} catch (AllOfException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +}); ?> --EXPECT-- 42 must not be of type integer diff --git a/tests/integration/rules/alnum.phpt b/tests/integration/rules/alnum.phpt index d72196052..7fd3d8ef9 100644 --- a/tests/integration/rules/alnum.phpt +++ b/tests/integration/rules/alnum.phpt @@ -7,57 +7,16 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\AlnumException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::alnum()->check('abc%1'); -} catch (AlnumException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::alnum(' ')->check('abc%2'); -} catch (AlnumException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::alnum())->check('abcd3'); -} catch (AlnumException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::alnum('% '))->check('abc%4'); -} catch (AlnumException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::alnum()->assert('abc^1'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::alnum())->assert('abcd2'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::alnum('* &%')->assert('abc^3'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::alnum('^'))->assert('abc^4'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::alnum()->check('abc%1')); +exceptionMessage(static fn() => v::alnum(' ')->check('abc%2')); +exceptionMessage(static fn() => v::not(v::alnum())->check('abcd3')); +exceptionMessage(static fn() => v::not(v::alnum('% '))->check('abc%4')); +exceptionFullMessage(static fn() => v::alnum()->assert('abc^1')); +exceptionFullMessage(static fn() => v::not(v::alnum())->assert('abcd2')); +exceptionFullMessage(static fn() => v::alnum('* &%')->assert('abc^3')); +exceptionFullMessage(static fn() => v::not(v::alnum('^'))->assert('abc^4')); ?> --EXPECT-- "abc%1" must contain only letters (a-z) and digits (0-9) diff --git a/tests/integration/rules/alpha.phpt b/tests/integration/rules/alpha.phpt index 1497a99f5..0da204440 100644 --- a/tests/integration/rules/alpha.phpt +++ b/tests/integration/rules/alpha.phpt @@ -7,57 +7,16 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\AlphaException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::alpha()->check('aaa%a'); -} catch (AlphaException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::alpha(' ')->check('bbb%b'); -} catch (AlphaException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::alpha())->check('ccccc'); -} catch (AlphaException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::alpha('% '))->check('ddd%d'); -} catch (AlphaException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::alpha()->assert('eee^e'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::alpha())->assert('fffff'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::alpha('* &%')->assert('ggg^g'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::alpha('^'))->assert('hhh^h'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::alpha()->check('aaa%a')); +exceptionMessage(static fn() => v::alpha(' ')->check('bbb%b')); +exceptionMessage(static fn() => v::not(v::alpha())->check('ccccc')); +exceptionMessage(static fn() => v::not(v::alpha('% '))->check('ddd%d')); +exceptionFullMessage(static fn() => v::alpha()->assert('eee^e')); +exceptionFullMessage(static fn() => v::not(v::alpha())->assert('fffff')); +exceptionFullMessage(static fn() => v::alpha('* &%')->assert('ggg^g')); +exceptionFullMessage(static fn() => v::not(v::alpha('^'))->assert('hhh^h')); ?> --EXPECT-- "aaa%a" must contain only letters (a-z) diff --git a/tests/integration/rules/alwaysInvalid.phpt b/tests/integration/rules/alwaysInvalid.phpt index 393b72398..525068934 100644 --- a/tests/integration/rules/alwaysInvalid.phpt +++ b/tests/integration/rules/alwaysInvalid.phpt @@ -7,21 +7,10 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\AlwaysInvalidException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::alwaysInvalid()->check('whatever'); -} catch (AlwaysInvalidException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::alwaysInvalid()->assert(''); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::alwaysInvalid()->check('whatever')); +exceptionFullMessage(static fn() => v::alwaysInvalid()->assert('')); ?> --EXPECT-- "whatever" is always invalid diff --git a/tests/integration/rules/alwaysValid.phpt b/tests/integration/rules/alwaysValid.phpt index f9f2bde10..584c9ea0b 100644 --- a/tests/integration/rules/alwaysValid.phpt +++ b/tests/integration/rules/alwaysValid.phpt @@ -7,22 +7,10 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\AlwaysValidException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::not(v::alwaysValid())->check(true); -} catch (AlwaysValidException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::alwaysValid())->assert(true); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - +exceptionMessage(static fn() => v::not(v::alwaysValid())->check(true)); +exceptionFullMessage(static fn() => v::not(v::alwaysValid())->assert(true)); ?> --EXPECT-- `TRUE` is always invalid diff --git a/tests/integration/rules/arrayType.phpt b/tests/integration/rules/arrayType.phpt index 305a39763..559c30351 100644 --- a/tests/integration/rules/arrayType.phpt +++ b/tests/integration/rules/arrayType.phpt @@ -8,33 +8,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\ArrayTypeException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::arrayType()->check('teste'); -} catch (ArrayTypeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::arrayType())->check([]); -} catch (ArrayTypeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::arrayType()->assert(new ArrayObject()); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::arrayType())->assert([1, 2, 3]); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::arrayType()->check('teste')); +exceptionMessage(static fn() => v::not(v::arrayType())->check([])); +exceptionFullMessage(static fn() => v::arrayType()->assert(new ArrayObject())); +exceptionFullMessage(static fn() => v::not(v::arrayType())->assert([1, 2, 3])); ?> --EXPECT-- "teste" must be of type array diff --git a/tests/integration/rules/arrayVal.phpt b/tests/integration/rules/arrayVal.phpt index 1926aede5..653650b16 100644 --- a/tests/integration/rules/arrayVal.phpt +++ b/tests/integration/rules/arrayVal.phpt @@ -8,33 +8,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\ArrayValException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::arrayVal()->check('Bla %123'); -} catch (ArrayValException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::arrayVal())->check([42]); -} catch (ArrayValException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::arrayVal()->assert(new stdClass()); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::arrayVal())->assert(new ArrayObject([2, 3])); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::arrayVal()->check('Bla %123')); +exceptionMessage(static fn() => v::not(v::arrayVal())->check([42])); +exceptionFullMessage(static fn() => v::arrayVal()->assert(new stdClass())); +exceptionFullMessage(static fn() => v::not(v::arrayVal())->assert(new ArrayObject([2, 3]))); ?> --EXPECT-- "Bla %123" must be an array value diff --git a/tests/integration/rules/base.phpt b/tests/integration/rules/base.phpt index a9eb2d33a..c4773a72d 100644 --- a/tests/integration/rules/base.phpt +++ b/tests/integration/rules/base.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\BaseException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::base(61)->check('Z01xSsg5675hic20dj'); -} catch (BaseException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::base(2)->assert(''); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::base(2))->check('011010001'); -} catch (BaseException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::base(2))->assert('011010001'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::base(61)->check('Z01xSsg5675hic20dj')); +exceptionFullMessage(static fn() => v::base(2)->assert('')); +exceptionMessage(static fn() => v::not(v::base(2))->check('011010001')); +exceptionFullMessage(static fn() => v::not(v::base(2))->assert('011010001')); ?> --EXPECT-- "Z01xSsg5675hic20dj" must be a number in the base 61 diff --git a/tests/integration/rules/base64.phpt b/tests/integration/rules/base64.phpt index 0f461e78d..ae4224a34 100644 --- a/tests/integration/rules/base64.phpt +++ b/tests/integration/rules/base64.phpt @@ -9,33 +9,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\Base64Exception; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::base64()->check('=c3VyZS4'); -} catch (Base64Exception $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::base64())->check('c3VyZS4='); -} catch (Base64Exception $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::base64()->assert('=c3VyZS4'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::base64())->assert('c3VyZS4='); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::base64()->check('=c3VyZS4')); +exceptionMessage(static fn() => v::not(v::base64())->check('c3VyZS4=')); +exceptionFullMessage(static fn() => v::base64()->assert('=c3VyZS4')); +exceptionFullMessage(static fn() => v::not(v::base64())->assert('c3VyZS4=')); ?> --EXPECT-- "=c3VyZS4" must be Base64-encoded diff --git a/tests/integration/rules/beetwen.phpt b/tests/integration/rules/beetwen.phpt index 1f18fde96..b6e3d42e2 100644 --- a/tests/integration/rules/beetwen.phpt +++ b/tests/integration/rules/beetwen.phpt @@ -7,34 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\BetweenException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::between(1, 2)->check(0); -} catch (BetweenException $e) { - echo $e->getMessage() . PHP_EOL; -} - -try { - v::not(v::between('yesterday', 'tomorrow'))->check('today'); -} catch (BetweenException $e) { - echo $e->getMessage() . PHP_EOL; -} - -try { - v::between('a', 'c')->assert('d'); -} catch (NestedValidationException $e) { - echo $e->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::between(-INF, INF))->assert(0); -} catch (NestedValidationException $e) { - echo $e->getFullMessage() . PHP_EOL; -} - +exceptionMessage(static fn() => v::between(1, 2)->check(0)); +exceptionMessage(static fn() => v::not(v::between('yesterday', 'tomorrow'))->check('today')); +exceptionFullMessage(static fn() => v::between('a', 'c')->assert('d')); +exceptionFullMessage(static fn() => v::not(v::between(-INF, INF))->assert(0)); ?> --EXPECT-- 0 must be between 1 and 2 diff --git a/tests/integration/rules/beetwen_5.phpt b/tests/integration/rules/beetwen_5.phpt index e813dec65..108ede5a7 100644 --- a/tests/integration/rules/beetwen_5.phpt +++ b/tests/integration/rules/beetwen_5.phpt @@ -8,14 +8,9 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\AllOfException; use Respect\Validation\Validator as v; -try { - v::not(v::between('a', 'b'))->assert('a'); -} catch (AllOfException $e) { - echo $e->getFullMessage(); -} +exceptionFullMessage(static fn() => v::not(v::between('a', 'b'))->assert('a')); ?> --EXPECT-- - "a" must not be between "a" and "b" diff --git a/tests/integration/rules/beetwen_6.phpt b/tests/integration/rules/beetwen_6.phpt index f42d08397..8360df19f 100644 --- a/tests/integration/rules/beetwen_6.phpt +++ b/tests/integration/rules/beetwen_6.phpt @@ -8,14 +8,9 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\AllOfException; use Respect\Validation\Validator as v; -try { - v::not(v::intType()->between(1, 42))->assert(41); -} catch (AllOfException $e) { - echo $e->getFullMessage(); -} +exceptionFullMessage(static fn() => v::not(v::intType()->between(1, 42))->assert(41)); ?> --EXPECT-- - 41 must not be between 1 and 42 diff --git a/tests/integration/rules/boolType.phpt b/tests/integration/rules/boolType.phpt index 5bbc2a88f..0e585fba9 100644 --- a/tests/integration/rules/boolType.phpt +++ b/tests/integration/rules/boolType.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\BoolTypeException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::boolType()->check('teste'); -} catch (BoolTypeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::boolType())->check(true); -} catch (BoolTypeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::boolType()->assert([]); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::boolType())->assert(false); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::boolType()->check('teste')); +exceptionMessage(static fn() => v::not(v::boolType())->check(true)); +exceptionFullMessage(static fn() => v::boolType()->assert([])); +exceptionFullMessage(static fn() => v::not(v::boolType())->assert(false)); ?> --EXPECT-- "teste" must be of type boolean diff --git a/tests/integration/rules/boolVal.phpt b/tests/integration/rules/boolVal.phpt index 2e6d1f73d..48b803b69 100644 --- a/tests/integration/rules/boolVal.phpt +++ b/tests/integration/rules/boolVal.phpt @@ -9,33 +9,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\BoolValException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::boolVal()->check('ok'); -} catch (BoolValException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::boolVal())->check('yes'); -} catch (BoolValException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::boolVal()->assert('yep'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::boolVal())->assert('on'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::boolVal()->check('ok')); +exceptionMessage(static fn() => v::not(v::boolVal())->check('yes')); +exceptionFullMessage(static fn() => v::boolVal()->assert('yep')); +exceptionFullMessage(static fn() => v::not(v::boolVal())->assert('on')); ?> --EXPECT-- "ok" must be a boolean value diff --git a/tests/integration/rules/bsn.phpt b/tests/integration/rules/bsn.phpt index b3b140eaa..0f5cf0c35 100644 --- a/tests/integration/rules/bsn.phpt +++ b/tests/integration/rules/bsn.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\BsnException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::bsn()->check('acb'); -} catch (BsnException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::bsn())->check('612890053'); -} catch (BsnException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::bsn()->assert('abc'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::bsn())->assert('612890053'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::bsn()->check('acb')); +exceptionMessage(static fn() => v::not(v::bsn())->check('612890053')); +exceptionFullMessage(static fn() => v::bsn()->assert('abc')); +exceptionFullMessage(static fn() => v::not(v::bsn())->assert('612890053')); ?> --EXPECT-- "acb" must be a BSN diff --git a/tests/integration/rules/call.phpt b/tests/integration/rules/call.phpt index fe7eeb22a..229583bb7 100644 --- a/tests/integration/rules/call.phpt +++ b/tests/integration/rules/call.phpt @@ -7,46 +7,14 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\CallException; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\ValidationException; use Respect\Validation\Validator as v; -try { - v::call('trim', v::noWhitespace())->check(' two words '); -} catch (ValidationException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::call('trim', v::stringType()))->check(' something '); -} catch (CallException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::call('trim', v::alwaysValid())->check([]); -} catch (ValidationException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::call('strval', v::intType())->assert(1234); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::call('is_float', v::boolType()))->assert(1.2); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::call('array_walk', v::alwaysValid())->assert(INF); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::call('trim', v::noWhitespace())->check(' two words ')); +exceptionMessage(static fn() => v::not(v::call('trim', v::stringType()))->check(' something ')); +exceptionMessage(static fn() => v::call('trim', v::alwaysValid())->check([])); +exceptionFullMessage(static fn() => v::call('strval', v::intType())->assert(1234)); +exceptionFullMessage(static fn() => v::not(v::call('is_float', v::boolType()))->assert(1.2)); +exceptionFullMessage(static fn() => v::call('array_walk', v::alwaysValid())->assert(INF)); ?> --EXPECT-- "two words" must not contain whitespace diff --git a/tests/integration/rules/callableType.phpt b/tests/integration/rules/callableType.phpt index 316f0a58e..a71d9e49c 100644 --- a/tests/integration/rules/callableType.phpt +++ b/tests/integration/rules/callableType.phpt @@ -7,28 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\CallableTypeException; use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::callableType()->check([]); -} catch (CallableTypeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::callableType())->check('trim'); -} catch (CallableTypeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::callableType()->assert(true); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - +exceptionMessage(static fn() => v::callableType()->check([])); +exceptionMessage(static fn() => v::not(v::callableType())->check('trim')); +exceptionFullMessage(static fn() => v::callableType()->assert(true)); try { v::not(v::callableType())->assert(static function (): void { }); diff --git a/tests/integration/rules/callback.phpt b/tests/integration/rules/callback.phpt index 275535309..103f74023 100644 --- a/tests/integration/rules/callback.phpt +++ b/tests/integration/rules/callback.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\CallbackException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::callback('is_string')->check([]); -} catch (CallbackException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::callback('is_string'))->check('foo'); -} catch (CallbackException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::callback('is_string')->assert(true); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::callback('is_string'))->assert('foo'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::callback('is_string')->check([])); +exceptionMessage(static fn() => v::not(v::callback('is_string'))->check('foo')); +exceptionFullMessage(static fn() => v::callback('is_string')->assert(true)); +exceptionFullMessage(static fn() => v::not(v::callback('is_string'))->assert('foo')); ?> --EXPECT-- `{ }` must be valid diff --git a/tests/integration/rules/charset.phpt b/tests/integration/rules/charset.phpt index b244929ae..525c9051c 100644 --- a/tests/integration/rules/charset.phpt +++ b/tests/integration/rules/charset.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\CharsetException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::charset('ASCII')->check('açaí'); -} catch (CharsetException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::charset('UTF-8'))->check('açaí'); -} catch (CharsetException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::charset('ASCII')->assert('açaí'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::charset('UTF-8'))->assert('açaí'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::charset('ASCII')->check('açaí')); +exceptionMessage(static fn() => v::not(v::charset('UTF-8'))->check('açaí')); +exceptionFullMessage(static fn() => v::charset('ASCII')->assert('açaí')); +exceptionFullMessage(static fn() => v::not(v::charset('UTF-8'))->assert('açaí')); ?> --EXPECT-- "açaí" must be in the `{ "ASCII" }` charset diff --git a/tests/integration/rules/cnh.phpt b/tests/integration/rules/cnh.phpt index c60a8f8cb..fa3b40d64 100644 --- a/tests/integration/rules/cnh.phpt +++ b/tests/integration/rules/cnh.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\CnhException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::cnh()->check('batman'); -} catch (CnhException $e) { - echo $e->getMessage() . PHP_EOL; -} - -try { - v::not(v::cnh())->check('02650306461'); -} catch (CnhException $e) { - echo $e->getMessage() . PHP_EOL; -} - -try { - v::cnh()->assert('bruce wayne'); -} catch (NestedValidationException $e) { - echo $e->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::cnh())->assert('02650306461'); -} catch (NestedValidationException $e) { - echo $e->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::cnh()->check('batman')); +exceptionMessage(static fn() => v::not(v::cnh())->check('02650306461')); +exceptionFullMessage(static fn() => v::cnh()->assert('bruce wayne')); +exceptionFullMessage(static fn() => v::not(v::cnh())->assert('02650306461')); ?> --EXPECT-- "batman" must be a valid CNH number diff --git a/tests/integration/rules/cnpj.phpt b/tests/integration/rules/cnpj.phpt index 7005be141..55c93531c 100644 --- a/tests/integration/rules/cnpj.phpt +++ b/tests/integration/rules/cnpj.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require_once 'vendor/autoload.php'; -use Respect\Validation\Exceptions\CnpjException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::cnpj()->check('não cnpj'); -} catch (CnpjException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::cnpj())->check('65.150.175/0001-20'); -} catch (CnpjException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::cnpj()->assert('test'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::cnpj())->assert('65.150.175/0001-20'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::cnpj()->check('não cnpj')); +exceptionMessage(static fn() => v::not(v::cnpj())->check('65.150.175/0001-20')); +exceptionFullMessage(static fn() => v::cnpj()->assert('test')); +exceptionFullMessage(static fn() => v::not(v::cnpj())->assert('65.150.175/0001-20')); ?> --EXPECT-- "não cnpj" must be a valid CNPJ number diff --git a/tests/integration/rules/cntrl.phpt b/tests/integration/rules/cntrl.phpt index fc2c44467..344f47b00 100644 --- a/tests/integration/rules/cntrl.phpt +++ b/tests/integration/rules/cntrl.phpt @@ -7,58 +7,16 @@ declare(strict_types=1); require_once 'vendor/autoload.php'; -use Respect\Validation\Exceptions\ControlException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::control()->check('16-50'); -} catch (ControlException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::control('16')->check('16-50'); -} catch (ControlException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::control())->check("\n"); -} catch (ControlException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::control('16'))->check("16\n"); -} catch (ControlException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::control()->assert('Foo'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::control('Bar')->assert('Foo'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::control())->assert("\n"); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::control('Bar'))->assert("Bar\n"); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - +exceptionMessage(static fn() => v::control()->check('16-50')); +exceptionMessage(static fn() => v::control('16')->check('16-50')); +exceptionMessage(static fn() => v::not(v::control())->check("\n")); +exceptionMessage(static fn() => v::not(v::control('16'))->check("16\n")); +exceptionFullMessage(static fn() => v::control()->assert('Foo')); +exceptionFullMessage(static fn() => v::control('Bar')->assert('Foo')); +exceptionFullMessage(static fn() => v::not(v::control())->assert("\n")); +exceptionFullMessage(static fn() => v::not(v::control('Bar'))->assert("Bar\n")); ?> --EXPECT-- "16-50" must contain only control characters diff --git a/tests/integration/rules/consonant.phpt b/tests/integration/rules/consonant.phpt index 725fbefef..f15438626 100644 --- a/tests/integration/rules/consonant.phpt +++ b/tests/integration/rules/consonant.phpt @@ -9,58 +9,16 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\ConsonantException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::consonant()->check('aeiou'); -} catch (ConsonantException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::consonant('d')->check('daeiou'); -} catch (ConsonantException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::consonant())->check('bcd'); -} catch (ConsonantException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::consonant('a'))->check('abcd'); -} catch (ConsonantException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::consonant()->assert('aeiou'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::consonant('d')->assert('daeiou'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::consonant())->assert('bcd'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::consonant('a'))->assert('abcd'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - +exceptionMessage(static fn() => v::consonant()->check('aeiou')); +exceptionMessage(static fn() => v::consonant('d')->check('daeiou')); +exceptionMessage(static fn() => v::not(v::consonant())->check('bcd')); +exceptionMessage(static fn() => v::not(v::consonant('a'))->check('abcd')); +exceptionFullMessage(static fn() => v::consonant()->assert('aeiou')); +exceptionFullMessage(static fn() => v::consonant('d')->assert('daeiou')); +exceptionFullMessage(static fn() => v::not(v::consonant())->assert('bcd')); +exceptionFullMessage(static fn() => v::not(v::consonant('a'))->assert('abcd')); ?> --EXPECT-- "aeiou" must contain only consonants diff --git a/tests/integration/rules/contains.phpt b/tests/integration/rules/contains.phpt index 67ae720bd..bb7ae519f 100644 --- a/tests/integration/rules/contains.phpt +++ b/tests/integration/rules/contains.phpt @@ -7,34 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\ContainsException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::contains('foo')->check('bar'); -} catch (ContainsException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::contains('foo'))->check('fool'); -} catch (ContainsException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::contains('foo')->assert(['bar']); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::contains('foo', true))->assert(['bar', 'foo']); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - +exceptionMessage(static fn() => v::contains('foo')->check('bar')); +exceptionMessage(static fn() => v::not(v::contains('foo'))->check('fool')); +exceptionFullMessage(static fn() => v::contains('foo')->assert(['bar'])); +exceptionFullMessage(static fn() => v::not(v::contains('foo', true))->assert(['bar', 'foo'])); ?> --EXPECT-- "bar" must contain the value "foo" diff --git a/tests/integration/rules/containsAny.phpt b/tests/integration/rules/containsAny.phpt index a81eb82b0..3f90261bc 100644 --- a/tests/integration/rules/containsAny.phpt +++ b/tests/integration/rules/containsAny.phpt @@ -7,34 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\ContainsAnyException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::containsAny(['foo', 'bar'])->check('baz'); -} catch (ContainsAnyException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::containsAny(['foo', 'bar']))->check('fool'); -} catch (ContainsAnyException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::containsAny(['foo', 'bar'])->assert(['baz']); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::containsAny(['foo', 'bar'], true))->assert(['bar', 'foo']); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - +exceptionMessage(static fn() => v::containsAny(['foo', 'bar'])->check('baz')); +exceptionMessage(static fn() => v::not(v::containsAny(['foo', 'bar']))->check('fool')); +exceptionFullMessage(static fn() => v::containsAny(['foo', 'bar'])->assert(['baz'])); +exceptionFullMessage(static fn() => v::not(v::containsAny(['foo', 'bar'], true))->assert(['bar', 'foo'])); ?> --EXPECT-- "baz" must contain at least one of the values `{ "foo", "bar" }` diff --git a/tests/integration/rules/countable.phpt b/tests/integration/rules/countable.phpt index 0478c3c5b..fa95cc0a8 100644 --- a/tests/integration/rules/countable.phpt +++ b/tests/integration/rules/countable.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\CountableException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::countable()->check(1.0); -} catch (CountableException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::countable())->check([]); -} catch (CountableException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::countable()->assert('Not countable!'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::countable())->assert(new ArrayObject()); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::countable()->check(1.0)); +exceptionMessage(static fn() => v::not(v::countable())->check([])); +exceptionFullMessage(static fn() => v::countable()->assert('Not countable!')); +exceptionFullMessage(static fn() => v::not(v::countable())->assert(new ArrayObject())); ?> --EXPECT-- 1.0 must be countable diff --git a/tests/integration/rules/countryCode.phpt b/tests/integration/rules/countryCode.phpt index 2d941e21b..45620ed3f 100644 --- a/tests/integration/rules/countryCode.phpt +++ b/tests/integration/rules/countryCode.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\CountryCodeException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::countryCode()->check('1'); -} catch (CountryCodeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::countryCode())->check('BR'); -} catch (CountryCodeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::countryCode()->assert('1'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::countryCode())->assert('BR'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::countryCode()->check('1')); +exceptionMessage(static fn() => v::not(v::countryCode())->check('BR')); +exceptionFullMessage(static fn() => v::countryCode()->assert('1')); +exceptionFullMessage(static fn() => v::not(v::countryCode())->assert('BR')); ?> --EXPECT-- "1" must be a valid country diff --git a/tests/integration/rules/cpf.phpt b/tests/integration/rules/cpf.phpt index ea741d4bd..0ee77211a 100644 --- a/tests/integration/rules/cpf.phpt +++ b/tests/integration/rules/cpf.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\CpfException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::cpf()->check('this thing'); -} catch (CpfException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::cpf())->check('276.865.775-11'); -} catch (CpfException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::cpf()->assert('your mother'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::cpf())->assert('61836182848'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::cpf()->check('this thing')); +exceptionMessage(static fn() => v::not(v::cpf())->check('276.865.775-11')); +exceptionFullMessage(static fn() => v::cpf()->assert('your mother')); +exceptionFullMessage(static fn() => v::not(v::cpf())->assert('61836182848')); ?> --EXPECT-- "this thing" must be a valid CPF number diff --git a/tests/integration/rules/creditCard.phpt b/tests/integration/rules/creditCard.phpt index 2327b6c01..46503d07a 100644 --- a/tests/integration/rules/creditCard.phpt +++ b/tests/integration/rules/creditCard.phpt @@ -7,34 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\CreditCardException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::creditCard('Discover')->check(3566002020360505); -} catch (CreditCardException $e) { - echo $e->getMessage() . PHP_EOL; -} - -try { - v::not(v::creditCard('Visa'))->check(4024007153361885); -} catch (CreditCardException $e) { - echo $e->getMessage() . PHP_EOL; -} - -try { - v::creditCard('MasterCard')->assert(3566002020360505); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::creditCard())->assert(5555444433331111); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - +exceptionMessage(static fn() => v::creditCard('Discover')->check(3566002020360505)); +exceptionMessage(static fn() => v::not(v::creditCard('Visa'))->check(4024007153361885)); +exceptionFullMessage(static fn() => v::creditCard('MasterCard')->assert(3566002020360505)); +exceptionFullMessage(static fn() => v::not(v::creditCard())->assert(5555444433331111)); ?> --EXPECT-- 3566002020360505 must be a valid "Discover" Credit Card number diff --git a/tests/integration/rules/currencyCode.phpt b/tests/integration/rules/currencyCode.phpt index de824127a..afd1853a9 100644 --- a/tests/integration/rules/currencyCode.phpt +++ b/tests/integration/rules/currencyCode.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\CurrencyCodeException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::currencyCode()->check('batman'); -} catch (CurrencyCodeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::currencyCode())->check('BRL'); -} catch (CurrencyCodeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::currencyCode()->assert('ppz'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::currencyCode())->assert('GBP'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::currencyCode()->check('batman')); +exceptionMessage(static fn() => v::not(v::currencyCode())->check('BRL')); +exceptionFullMessage(static fn() => v::currencyCode()->assert('ppz')); +exceptionFullMessage(static fn() => v::not(v::currencyCode())->assert('GBP')); ?> --EXPECT-- "batman" must be a valid currency diff --git a/tests/integration/rules/date.phpt b/tests/integration/rules/date.phpt index 69b6b6224..8a2e87cf2 100644 --- a/tests/integration/rules/date.phpt +++ b/tests/integration/rules/date.phpt @@ -7,35 +7,14 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\DateException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; date_default_timezone_set('UTC'); -try { - v::date()->check('2018-01-29T08:32:54+00:00'); -} catch (DateException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::date())->check('2018-01-29'); -} catch (DateException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::date()->assert('2018-01-29T08:32:54+00:00'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::date('d/m/Y'))->assert('29/01/2018'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::date()->check('2018-01-29T08:32:54+00:00')); +exceptionMessage(static fn() => v::not(v::date())->check('2018-01-29')); +exceptionFullMessage(static fn() => v::date()->assert('2018-01-29T08:32:54+00:00')); +exceptionFullMessage(static fn() => v::not(v::date('d/m/Y'))->assert('29/01/2018')); ?> --EXPECT-- "2018-01-29T08:32:54+00:00" must be a valid date in the format "2005-12-30" diff --git a/tests/integration/rules/dateTime.phpt b/tests/integration/rules/dateTime.phpt index 201207cf0..e5b0643d3 100644 --- a/tests/integration/rules/dateTime.phpt +++ b/tests/integration/rules/dateTime.phpt @@ -7,60 +7,18 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\DateTimeException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; date_default_timezone_set('UTC'); -try { - v::dateTime()->check('FooBarBazz'); -} catch (DateTimeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::dateTime('c')->check('06-12-1995'); -} catch (DateTimeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::dateTime()->assert('QuxQuuxx'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::dateTime('r')->assert(2018013030); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::dateTime())->check('4 days ago'); -} catch (DateTimeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::dateTime('Y-m-d'))->check('1988-09-09'); -} catch (DateTimeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::dateTime())->assert('+3 weeks'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::dateTime('d/m/y'))->assert('23/07/99'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - +exceptionMessage(static fn() => v::dateTime()->check('FooBarBazz')); +exceptionMessage(static fn() => v::dateTime('c')->check('06-12-1995')); +exceptionFullMessage(static fn() => v::dateTime()->assert('QuxQuuxx')); +exceptionFullMessage(static fn() => v::dateTime('r')->assert(2018013030)); +exceptionMessage(static fn() => v::not(v::dateTime())->check('4 days ago')); +exceptionMessage(static fn() => v::not(v::dateTime('Y-m-d'))->check('1988-09-09')); +exceptionFullMessage(static fn() => v::not(v::dateTime())->assert('+3 weeks')); +exceptionFullMessage(static fn() => v::not(v::dateTime('d/m/y'))->assert('23/07/99')); ?> --EXPECT-- "FooBarBazz" must be a valid date/time diff --git a/tests/integration/rules/decimal.phpt b/tests/integration/rules/decimal.phpt index 8117aefb4..2c078d4cb 100644 --- a/tests/integration/rules/decimal.phpt +++ b/tests/integration/rules/decimal.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\DecimalException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::decimal(3)->check(0.1234); -} catch (DecimalException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::decimal(2)->assert(0.123); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::decimal(5))->check(0.12345); -} catch (DecimalException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::decimal(2))->assert(0.34); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::decimal(3)->check(0.1234)); +exceptionFullMessage(static fn() => v::decimal(2)->assert(0.123)); +exceptionMessage(static fn() => v::not(v::decimal(5))->check(0.12345)); +exceptionFullMessage(static fn() => v::not(v::decimal(2))->assert(0.34)); ?> --EXPECT-- 0.1234 must have 3 decimals diff --git a/tests/integration/rules/digit.phpt b/tests/integration/rules/digit.phpt index ac99f33b6..3d83d3d97 100644 --- a/tests/integration/rules/digit.phpt +++ b/tests/integration/rules/digit.phpt @@ -7,57 +7,16 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\DigitException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::digit()->check('abc'); -} catch (DigitException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::digit('-')->check('a-b'); -} catch (DigitException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::digit())->check('123'); -} catch (DigitException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::digit('-'))->check('1-3'); -} catch (DigitException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::digit()->assert('abc'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::digit('-')->assert('a-b'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::digit())->assert('123'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::digit('-'))->assert('1-3'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::digit()->check('abc')); +exceptionMessage(static fn() => v::digit('-')->check('a-b')); +exceptionMessage(static fn() => v::not(v::digit())->check('123')); +exceptionMessage(static fn() => v::not(v::digit('-'))->check('1-3')); +exceptionFullMessage(static fn() => v::digit()->assert('abc')); +exceptionFullMessage(static fn() => v::digit('-')->assert('a-b')); +exceptionFullMessage(static fn() => v::not(v::digit())->assert('123')); +exceptionFullMessage(static fn() => v::not(v::digit('-'))->assert('1-3')); ?> --EXPECT-- "abc" must contain only digits (0-9) diff --git a/tests/integration/rules/directory.phpt b/tests/integration/rules/directory.phpt index b10d99bb4..15ba8a276 100644 --- a/tests/integration/rules/directory.phpt +++ b/tests/integration/rules/directory.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\DirectoryException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::directory()->check('batman'); -} catch (DirectoryException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::directory())->check(dirname('/etc/')); -} catch (DirectoryException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::directory()->assert('ppz'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::directory())->assert(dirname('/etc/')); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::directory()->check('batman')); +exceptionMessage(static fn() => v::not(v::directory())->check(dirname('/etc/'))); +exceptionFullMessage(static fn() => v::directory()->assert('ppz')); +exceptionFullMessage(static fn() => v::not(v::directory())->assert(dirname('/etc/'))); ?> --EXPECT-- "batman" must be a directory diff --git a/tests/integration/rules/domain.phpt b/tests/integration/rules/domain.phpt index a5ea53e2d..ef733e254 100644 --- a/tests/integration/rules/domain.phpt +++ b/tests/integration/rules/domain.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\ValidationException; use Respect\Validation\Validator as v; -try { - v::domain()->check('batman'); -} catch (ValidationException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::domain())->check('r--w.com'); -} catch (ValidationException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::domain()->assert('p-éz-.kk'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::domain())->assert('github.com'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::domain()->check('batman')); +exceptionMessage(static fn() => v::not(v::domain())->check('r--w.com')); +exceptionFullMessage(static fn() => v::domain()->assert('p-éz-.kk')); +exceptionFullMessage(static fn() => v::not(v::domain())->assert('github.com')); ?> --EXPECT-- "batman" must contain the value "." diff --git a/tests/integration/rules/each.phpt b/tests/integration/rules/each.phpt index 6cf4f1ccd..93ff86793 100644 --- a/tests/integration/rules/each.phpt +++ b/tests/integration/rules/each.phpt @@ -7,34 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\EachException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::each(v::dateTime())->check(null); -} catch (EachException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::each(v::dateTime()))->check(['2018-10-10']); -} catch (EachException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::each(v::dateTime())->assert(null); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::each(v::dateTime()))->assert(['2018-10-10']); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - +exceptionMessage(static fn() => v::each(v::dateTime())->check(null)); +exceptionMessage(static fn() => v::not(v::each(v::dateTime()))->check(['2018-10-10'])); +exceptionFullMessage(static fn() => v::each(v::dateTime())->assert(null)); +exceptionFullMessage(static fn() => v::not(v::each(v::dateTime()))->assert(['2018-10-10'])); ?> --EXPECT-- Each item in `NULL` must be valid diff --git a/tests/integration/rules/email.phpt b/tests/integration/rules/email.phpt index cd422c1ab..28c6214df 100644 --- a/tests/integration/rules/email.phpt +++ b/tests/integration/rules/email.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\EmailException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::email()->check('batman'); -} catch (EmailException $e) { - echo $e->getMessage() . PHP_EOL; -} - -try { - v::not(v::email())->check('bruce.wayne@gothancity.com'); -} catch (EmailException $e) { - echo $e->getMessage() . PHP_EOL; -} - -try { - v::email()->assert('bruce wayne'); -} catch (NestedValidationException $e) { - echo $e->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::email())->assert('iambatman@gothancity.com'); -} catch (NestedValidationException $e) { - echo $e->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::email()->check('batman')); +exceptionMessage(static fn() => v::not(v::email())->check('bruce.wayne@gothancity.com')); +exceptionFullMessage(static fn() => v::email()->assert('bruce wayne')); +exceptionFullMessage(static fn() => v::not(v::email())->assert('iambatman@gothancity.com')); ?> --EXPECT-- "batman" must be valid email diff --git a/tests/integration/rules/endsWith.phpt b/tests/integration/rules/endsWith.phpt index 111429515..1141190b0 100644 --- a/tests/integration/rules/endsWith.phpt +++ b/tests/integration/rules/endsWith.phpt @@ -7,34 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\EndsWithException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::endsWith('foo')->check('bar'); -} catch (EndsWithException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::endsWith('foo'))->check(['bar', 'foo']); -} catch (EndsWithException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::endsWith('foo')->assert(''); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::endsWith('foo'))->assert(['bar', 'foo']); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - +exceptionMessage(static fn() => v::endsWith('foo')->check('bar')); +exceptionMessage(static fn() => v::not(v::endsWith('foo'))->check(['bar', 'foo'])); +exceptionFullMessage(static fn() => v::endsWith('foo')->assert('')); +exceptionFullMessage(static fn() => v::not(v::endsWith('foo'))->assert(['bar', 'foo'])); ?> --EXPECT-- "bar" must end with "foo" diff --git a/tests/integration/rules/equals.phpt b/tests/integration/rules/equals.phpt index 97d7617d3..d8142795f 100644 --- a/tests/integration/rules/equals.phpt +++ b/tests/integration/rules/equals.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\EqualsException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::equals(123)->check(321); -} catch (EqualsException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::equals(321))->check(321); -} catch (EqualsException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::equals(123)->assert(321); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::equals(321))->assert(321); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::equals(123)->check(321)); +exceptionMessage(static fn() => v::not(v::equals(321))->check(321)); +exceptionFullMessage(static fn() => v::equals(123)->assert(321)); +exceptionFullMessage(static fn() => v::not(v::equals(321))->assert(321)); ?> --EXPECT-- 321 must equal 123 diff --git a/tests/integration/rules/equivalent.phpt b/tests/integration/rules/equivalent.phpt index fc0459493..ee49292e7 100644 --- a/tests/integration/rules/equivalent.phpt +++ b/tests/integration/rules/equivalent.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\EquivalentException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::equivalent(true)->check(false); -} catch (EquivalentException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::equivalent('Something'))->check('someThing'); -} catch (EquivalentException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::equivalent(123)->assert('true'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::equivalent(true))->assert(1); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::equivalent(true)->check(false)); +exceptionMessage(static fn() => v::not(v::equivalent('Something'))->check('someThing')); +exceptionFullMessage(static fn() => v::equivalent(123)->assert('true')); +exceptionFullMessage(static fn() => v::not(v::equivalent(true))->assert(1)); ?> --EXPECT-- `FALSE` must be equivalent to `TRUE` diff --git a/tests/integration/rules/even.phpt b/tests/integration/rules/even.phpt index 0957a979c..9dd7fed93 100644 --- a/tests/integration/rules/even.phpt +++ b/tests/integration/rules/even.phpt @@ -7,34 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\EvenException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::even()->check(-1); -} catch (EvenException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::even()->assert(5); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::even())->check(6); -} catch (EvenException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::even())->assert(8); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - +exceptionMessage(static fn() => v::even()->check(-1)); +exceptionFullMessage(static fn() => v::even()->assert(5)); +exceptionMessage(static fn() => v::not(v::even())->check(6)); +exceptionFullMessage(static fn() => v::not(v::even())->assert(8)); ?> --EXPECT-- -1 must be an even number diff --git a/tests/integration/rules/executable.phpt b/tests/integration/rules/executable.phpt index 3528ba7f1..8aec6e0af 100644 --- a/tests/integration/rules/executable.phpt +++ b/tests/integration/rules/executable.phpt @@ -7,34 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\ExecutableException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::executable()->check('bar'); -} catch (ExecutableException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::executable())->check('tests/fixtures/executable'); -} catch (ExecutableException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::executable()->assert('bar'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::executable())->assert('tests/fixtures/executable'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - +exceptionMessage(static fn() => v::executable()->check('bar')); +exceptionMessage(static fn() => v::not(v::executable())->check('tests/fixtures/executable')); +exceptionFullMessage(static fn() => v::executable()->assert('bar')); +exceptionFullMessage(static fn() => v::not(v::executable())->assert('tests/fixtures/executable')); ?> --EXPECT-- "bar" must be an executable file diff --git a/tests/integration/rules/exists.phpt b/tests/integration/rules/exists.phpt index 3bfed8c2e..67ac7fd33 100644 --- a/tests/integration/rules/exists.phpt +++ b/tests/integration/rules/exists.phpt @@ -7,36 +7,15 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\ExistsException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::exists()->check('/path/of/a/non-existent/file'); -} catch (ExistsException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::exists())->check('tests/fixtures/valid-image.gif'); -} catch (ExistsException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::exists()->assert('/path/of/a/non-existent/file'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::exists())->assert('tests/fixtures/valid-image.png'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::exists()->check('/path/of/a/non-existent/file')); +exceptionMessage(static fn() => v::not(v::exists())->check('tests/fixtures/valid-image.gif')); +exceptionFullMessage(static fn() => v::exists()->assert('/path/of/a/non-existent/file')); +exceptionFullMessage(static fn() => v::not(v::exists())->assert('tests/fixtures/valid-image.png')); ?> --EXPECT-- -"/path/of/a/non-existent/file" must exists -"tests/fixtures/valid-image.gif" must not exists -- "/path/of/a/non-existent/file" must exists -- "tests/fixtures/valid-image.png" must not exists +"/path/of/a/non-existent/file" must exist +"tests/fixtures/valid-image.gif" must not exist +- "/path/of/a/non-existent/file" must exist +- "tests/fixtures/valid-image.png" must not exist diff --git a/tests/integration/rules/extension.phpt b/tests/integration/rules/extension.phpt index 80f657f79..2f64c9db4 100644 --- a/tests/integration/rules/extension.phpt +++ b/tests/integration/rules/extension.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\ExtensionException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::extension('png')->check('filename.txt'); -} catch (ExtensionException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::extension('gif'))->check('filename.gif'); -} catch (ExtensionException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::extension('mp3')->assert('filename.wav'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::extension('png'))->assert('tests/fixtures/invalid-image.png'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::extension('png')->check('filename.txt')); +exceptionMessage(static fn() => v::not(v::extension('gif'))->check('filename.gif')); +exceptionFullMessage(static fn() => v::extension('mp3')->assert('filename.wav')); +exceptionFullMessage(static fn() => v::not(v::extension('png'))->assert('tests/fixtures/invalid-image.png')); ?> --EXPECT-- "filename.txt" must have "png" extension diff --git a/tests/integration/rules/factor.phpt b/tests/integration/rules/factor.phpt index c86f23b38..21579b2dd 100644 --- a/tests/integration/rules/factor.phpt +++ b/tests/integration/rules/factor.phpt @@ -7,34 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\FactorException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::factor(3)->check(2); -} catch (FactorException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::factor(0))->check(300); -} catch (FactorException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::factor(5)->assert(3); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::factor(6))->assert(1); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - +exceptionMessage(static fn() => v::factor(3)->check(2)); +exceptionMessage(static fn() => v::not(v::factor(0))->check(300)); +exceptionFullMessage(static fn() => v::factor(5)->assert(3)); +exceptionFullMessage(static fn() => v::not(v::factor(6))->assert(1)); ?> --EXPECT-- 2 must be a factor of 3 diff --git a/tests/integration/rules/falseVal.phpt b/tests/integration/rules/falseVal.phpt index 71391044e..ff044136b 100644 --- a/tests/integration/rules/falseVal.phpt +++ b/tests/integration/rules/falseVal.phpt @@ -7,37 +7,15 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\FalseValException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::falseVal()->check(true); -} catch (FalseValException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::falseVal())->check('false'); -} catch (FalseValException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::falseVal()->assert(1); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::falseVal())->assert(0); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - +exceptionMessage(static fn() => v::falseVal()->check(true)); +exceptionMessage(static fn() => v::not(v::falseVal())->check('false')); +exceptionFullMessage(static fn() => v::falseVal()->assert(1)); +exceptionFullMessage(static fn() => v::not(v::falseVal())->assert(0)); ?> --EXPECT-- -`TRUE` is not considered as "False" -"false" is considered as "False" -- 1 is not considered as "False" -- 0 is considered as "False" +`TRUE` must evaluate to `false` +"false" must not evaluate to `false` +- 1 must evaluate to `false` +- 0 must not evaluate to `false` diff --git a/tests/integration/rules/fibonacci.phpt b/tests/integration/rules/fibonacci.phpt index 7e4ce20cf..6ffe1793a 100644 --- a/tests/integration/rules/fibonacci.phpt +++ b/tests/integration/rules/fibonacci.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\FibonacciException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::fibonacci()->check(4); -} catch (FibonacciException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::fibonacci())->check(5); -} catch (FibonacciException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::fibonacci()->assert(16); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::fibonacci())->assert(21); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::fibonacci()->check(4)); +exceptionMessage(static fn() => v::not(v::fibonacci())->check(5)); +exceptionFullMessage(static fn() => v::fibonacci()->assert(16)); +exceptionFullMessage(static fn() => v::not(v::fibonacci())->assert(21)); ?> --EXPECT-- 4 must be a valid Fibonacci number diff --git a/tests/integration/rules/file.phpt b/tests/integration/rules/file.phpt index 2224e9b68..63389cebf 100644 --- a/tests/integration/rules/file.phpt +++ b/tests/integration/rules/file.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\FileException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::file()->check('tests/fixtures/non-existent.sh'); -} catch (FileException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::file())->check('tests/fixtures/valid-image.png'); -} catch (FileException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::file()->assert('tests/fixtures/non-existent.sh'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::file())->assert('tests/fixtures/valid-image.png'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::file()->check('tests/fixtures/non-existent.sh')); +exceptionMessage(static fn() => v::not(v::file())->check('tests/fixtures/valid-image.png')); +exceptionFullMessage(static fn() => v::file()->assert('tests/fixtures/non-existent.sh')); +exceptionFullMessage(static fn() => v::not(v::file())->assert('tests/fixtures/valid-image.png')); ?> --EXPECT-- "tests/fixtures/non-existent.sh" must be a file diff --git a/tests/integration/rules/filterVar.phpt b/tests/integration/rules/filterVar.phpt index 86130342a..44f83cf1f 100644 --- a/tests/integration/rules/filterVar.phpt +++ b/tests/integration/rules/filterVar.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\FilterVarException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::filterVar(FILTER_VALIDATE_IP)->check(42); -} catch (FilterVarException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::filterVar(FILTER_VALIDATE_BOOLEAN))->check('On'); -} catch (FilterVarException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::filterVar(FILTER_VALIDATE_EMAIL)->assert(1.5); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::filterVar(FILTER_VALIDATE_FLOAT))->assert(1.0); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::filterVar(FILTER_VALIDATE_IP)->check(42)); +exceptionMessage(static fn() => v::not(v::filterVar(FILTER_VALIDATE_BOOLEAN))->check('On')); +exceptionFullMessage(static fn() => v::filterVar(FILTER_VALIDATE_EMAIL)->assert(1.5)); +exceptionFullMessage(static fn() => v::not(v::filterVar(FILTER_VALIDATE_FLOAT))->assert(1.0)); ?> --EXPECT-- 42 must be valid diff --git a/tests/integration/rules/finite.phpt b/tests/integration/rules/finite.phpt index 5b4883e5d..a6b37f992 100644 --- a/tests/integration/rules/finite.phpt +++ b/tests/integration/rules/finite.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\FiniteException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::finite()->check(''); -} catch (FiniteException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::finite())->check(10); -} catch (FiniteException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::finite()->assert([12]); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::finite())->assert('123456'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::finite()->check('')); +exceptionMessage(static fn() => v::not(v::finite())->check(10)); +exceptionFullMessage(static fn() => v::finite()->assert([12])); +exceptionFullMessage(static fn() => v::not(v::finite())->assert('123456')); ?> --EXPECT-- "" must be a finite number diff --git a/tests/integration/rules/floatType.phpt b/tests/integration/rules/floatType.phpt index 4cc333874..b42a47190 100644 --- a/tests/integration/rules/floatType.phpt +++ b/tests/integration/rules/floatType.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\FloatTypeException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::floatType()->check('42.33'); -} catch (FloatTypeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::floatType())->check(INF); -} catch (FloatTypeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::floatType()->assert(true); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::floatType())->assert(2.0); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::floatType()->check('42.33')); +exceptionMessage(static fn() => v::not(v::floatType())->check(INF)); +exceptionFullMessage(static fn() => v::floatType()->assert(true)); +exceptionFullMessage(static fn() => v::not(v::floatType())->assert(2.0)); ?> --EXPECT-- "42.33" must be of type float diff --git a/tests/integration/rules/floatval.phpt b/tests/integration/rules/floatval.phpt index b1a566652..4d2c710d8 100644 --- a/tests/integration/rules/floatval.phpt +++ b/tests/integration/rules/floatval.phpt @@ -7,34 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\FloatValException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::floatVal()->check('a'); -} catch (FloatValException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::floatVal())->check(165.0); -} catch (FloatValException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::floatVal()->assert('a'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::floatVal())->assert('165.7'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - +exceptionMessage(static fn() => v::floatVal()->check('a')); +exceptionMessage(static fn() => v::not(v::floatVal())->check(165.0)); +exceptionFullMessage(static fn() => v::floatVal()->assert('a')); +exceptionFullMessage(static fn() => v::not(v::floatVal())->assert('165.7')); ?> --EXPECT-- "a" must be a float number diff --git a/tests/integration/rules/graph.phpt b/tests/integration/rules/graph.phpt index c412403f3..d27b7d38e 100644 --- a/tests/integration/rules/graph.phpt +++ b/tests/integration/rules/graph.phpt @@ -7,58 +7,16 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\GraphException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::graph()->check("foo\nbar"); -} catch (GraphException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::graph('foo')->check("foo\nbar"); -} catch (GraphException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::graph())->check('foobar'); -} catch (GraphException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::graph("\n"))->check("foo\nbar"); -} catch (GraphException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::graph()->assert("foo\nbar"); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::graph('foo')->assert("foo\nbar"); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::graph())->assert('foobar'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::graph("\n"))->assert("foo\nbar"); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - +exceptionMessage(static fn() => v::graph()->check("foo\nbar")); +exceptionMessage(static fn() => v::graph('foo')->check("foo\nbar")); +exceptionMessage(static fn() => v::not(v::graph())->check('foobar')); +exceptionMessage(static fn() => v::not(v::graph("\n"))->check("foo\nbar")); +exceptionFullMessage(static fn() => v::graph()->assert("foo\nbar")); +exceptionFullMessage(static fn() => v::graph('foo')->assert("foo\nbar")); +exceptionFullMessage(static fn() => v::not(v::graph())->assert('foobar')); +exceptionFullMessage(static fn() => v::not(v::graph("\n"))->assert("foo\nbar")); ?> --EXPECT-- "foo\nbar" must contain only graphical characters diff --git a/tests/integration/rules/greaterThan.phpt b/tests/integration/rules/greaterThan.phpt index a342c7c17..01d1e22bd 100644 --- a/tests/integration/rules/greaterThan.phpt +++ b/tests/integration/rules/greaterThan.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\GreaterThanException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::greaterThan(21)->check(12); -} catch (GreaterThanException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::greaterThan('yesterday'))->check('today'); -} catch (GreaterThanException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::greaterThan('2018-09-09')->assert('1988-09-09'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::greaterThan('a'))->assert('ba'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::greaterThan(21)->check(12)); +exceptionMessage(static fn() => v::not(v::greaterThan('yesterday'))->check('today')); +exceptionFullMessage(static fn() => v::greaterThan('2018-09-09')->assert('1988-09-09')); +exceptionFullMessage(static fn() => v::not(v::greaterThan('a'))->assert('ba')); ?> --EXPECT-- 12 must be greater than 21 diff --git a/tests/integration/rules/hexRgbColor.phpt b/tests/integration/rules/hexRgbColor.phpt index 7231198fe..9d3e34708 100644 --- a/tests/integration/rules/hexRgbColor.phpt +++ b/tests/integration/rules/hexRgbColor.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\HexRgbColorException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::hexRgbColor()->check('invalid'); -} catch (HexRgbColorException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::hexRgbColor())->check('#808080'); -} catch (HexRgbColorException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::hexRgbColor()->assert('invalid'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::hexRgbColor())->assert('#808080'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::hexRgbColor()->check('invalid')); +exceptionMessage(static fn() => v::not(v::hexRgbColor())->check('#808080')); +exceptionFullMessage(static fn() => v::hexRgbColor()->assert('invalid')); +exceptionFullMessage(static fn() => v::not(v::hexRgbColor())->assert('#808080')); ?> --EXPECT-- "invalid" must be a hex RGB color diff --git a/tests/integration/rules/iban.phpt b/tests/integration/rules/iban.phpt index 8d786f31b..c3e02b4cd 100644 --- a/tests/integration/rules/iban.phpt +++ b/tests/integration/rules/iban.phpt @@ -7,34 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\IbanException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::iban()->check('SE35 5000 5880 7742'); -} catch (IbanException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::iban())->check('GB82 WEST 1234 5698 7654 32'); -} catch (IbanException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::iban()->assert('NOT AN IBAN'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::iban())->assert('HU93 1160 0006 0000 0000 1234 5676'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} -?> +exceptionMessage(static fn() => v::iban()->check('SE35 5000 5880 7742')); +exceptionMessage(static fn() => v::not(v::iban())->check('GB82 WEST 1234 5698 7654 32')); +exceptionFullMessage(static fn() => v::iban()->assert('NOT AN IBAN')); +exceptionFullMessage(static fn() => v::not(v::iban())->assert('HU93 1160 0006 0000 0000 1234 5676'));?> --SKIPIF-- check(321); -} catch (IdenticalException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::identical(321))->check(321); -} catch (IdenticalException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::identical(123)->assert(321); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::identical(321))->assert(321); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::identical(123)->check(321)); +exceptionMessage(static fn() => v::not(v::identical(321))->check(321)); +exceptionFullMessage(static fn() => v::identical(123)->assert(321)); +exceptionFullMessage(static fn() => v::not(v::identical(321))->assert(321)); ?> --EXPECT-- 321 must be identical as 123 diff --git a/tests/integration/rules/image.phpt b/tests/integration/rules/image.phpt index 8d32398ad..439ba8922 100644 --- a/tests/integration/rules/image.phpt +++ b/tests/integration/rules/image.phpt @@ -7,34 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\ImageException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::image()->check('tests/fixtures/invalid-image.png'); -} catch (ImageException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::image())->check('tests/fixtures/valid-image.png'); -} catch (ImageException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::image()->assert(new stdClass()); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::image())->assert('tests/fixtures/valid-image.gif'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - +exceptionMessage(static fn() => v::image()->check('tests/fixtures/invalid-image.png')); +exceptionMessage(static fn() => v::not(v::image())->check('tests/fixtures/valid-image.png')); +exceptionFullMessage(static fn() => v::image()->assert(new stdClass())); +exceptionFullMessage(static fn() => v::not(v::image())->assert('tests/fixtures/valid-image.gif')); ?> --EXPECT-- "tests/fixtures/invalid-image.png" must be a valid image diff --git a/tests/integration/rules/imei.phpt b/tests/integration/rules/imei.phpt index c1be82b0d..2c28cd023 100644 --- a/tests/integration/rules/imei.phpt +++ b/tests/integration/rules/imei.phpt @@ -7,34 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\ImeiException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::imei()->check('490154203237512'); -} catch (ImeiException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::imei())->check('350077523237513'); -} catch (ImeiException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::imei()->assert(null); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::imei())->assert('356938035643809'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - +exceptionMessage(static fn() => v::imei()->check('490154203237512')); +exceptionMessage(static fn() => v::not(v::imei())->check('350077523237513')); +exceptionFullMessage(static fn() => v::imei()->assert(null)); +exceptionFullMessage(static fn() => v::not(v::imei())->assert('356938035643809')); ?> --EXPECT-- "490154203237512" must be a valid IMEI diff --git a/tests/integration/rules/in.phpt b/tests/integration/rules/in.phpt index ce25bc8ec..4b620e1d6 100644 --- a/tests/integration/rules/in.phpt +++ b/tests/integration/rules/in.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\InException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::in([3, 2])->check(1); -} catch (InException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::in('foobar'))->check('foo'); -} catch (InException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::in([2, '1', 3], true)->assert('2'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::in([2, '1', 3], true))->assert('1'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::in([3, 2])->check(1)); +exceptionMessage(static fn() => v::not(v::in('foobar'))->check('foo')); +exceptionFullMessage(static fn() => v::in([2, '1', 3], true)->assert('2')); +exceptionFullMessage(static fn() => v::not(v::in([2, '1', 3], true))->assert('1')); ?> --EXPECT-- 1 must be in `{ 3, 2 }` diff --git a/tests/integration/rules/infinite.phpt b/tests/integration/rules/infinite.phpt index 0cf5ceb2a..2c825d8ce 100644 --- a/tests/integration/rules/infinite.phpt +++ b/tests/integration/rules/infinite.phpt @@ -7,34 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\InfiniteException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::infinite()->check(-9); -} catch (InfiniteException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::infinite())->check(INF); -} catch (InfiniteException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::infinite()->assert(new stdClass()); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::infinite())->assert(INF * -1); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - +exceptionMessage(static fn() => v::infinite()->check(-9)); +exceptionMessage(static fn() => v::not(v::infinite())->check(INF)); +exceptionFullMessage(static fn() => v::infinite()->assert(new stdClass())); +exceptionFullMessage(static fn() => v::not(v::infinite())->assert(INF * -1)); ?> --EXPECT-- -9 must be an infinite number diff --git a/tests/integration/rules/instance.phpt b/tests/integration/rules/instance.phpt index 3fd81c36b..78f45be2d 100644 --- a/tests/integration/rules/instance.phpt +++ b/tests/integration/rules/instance.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\InstanceException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::instance(DateTime::class)->check(''); -} catch (InstanceException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::instance(Traversable::class))->check(new ArrayObject()); -} catch (InstanceException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::instance(ArrayIterator::class)->assert(new stdClass()); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::instance(stdClass::class))->assert(new stdClass()); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::instance(DateTime::class)->check('')); +exceptionMessage(static fn() => v::not(v::instance(Traversable::class))->check(new ArrayObject())); +exceptionFullMessage(static fn() => v::instance(ArrayIterator::class)->assert(new stdClass())); +exceptionFullMessage(static fn() => v::not(v::instance(stdClass::class))->assert(new stdClass())); ?> --EXPECT-- "" must be an instance of "DateTime" diff --git a/tests/integration/rules/intType.phpt b/tests/integration/rules/intType.phpt index 130c9f45c..fff5923f4 100644 --- a/tests/integration/rules/intType.phpt +++ b/tests/integration/rules/intType.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\IntTypeException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::intType()->check(new stdClass()); -} catch (IntTypeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::intType())->check(42); -} catch (IntTypeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::intType()->assert(INF); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::intType())->assert(1234567890); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::intType()->check(new stdClass())); +exceptionMessage(static fn() => v::not(v::intType())->check(42)); +exceptionFullMessage(static fn() => v::intType()->assert(INF)); +exceptionFullMessage(static fn() => v::not(v::intType())->assert(1234567890)); ?> --EXPECT-- `[object] (stdClass: { })` must be of type integer diff --git a/tests/integration/rules/intVal.phpt b/tests/integration/rules/intVal.phpt index 18216acbf..0ec1732f1 100644 --- a/tests/integration/rules/intVal.phpt +++ b/tests/integration/rules/intVal.phpt @@ -8,45 +8,14 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\IntValException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::intVal()->check('42.33'); -} catch (IntValException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::intVal())->check(2); -} catch (IntValException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::intVal()->assert('Foo'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::intVal())->assert(3); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::intVal())->assert(-42); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::intVal())->assert('-42'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::intVal()->check('42.33')); +exceptionMessage(static fn() => v::not(v::intVal())->check(2)); +exceptionFullMessage(static fn() => v::intVal()->assert('Foo')); +exceptionFullMessage(static fn() => v::not(v::intVal())->assert(3)); +exceptionFullMessage(static fn() => v::not(v::intVal())->assert(-42)); +exceptionFullMessage(static fn() => v::not(v::intVal())->assert('-42')); ?> --EXPECT-- "42.33" must be an integer number diff --git a/tests/integration/rules/ip.phpt b/tests/integration/rules/ip.phpt index 16b04d68b..28893e835 100644 --- a/tests/integration/rules/ip.phpt +++ b/tests/integration/rules/ip.phpt @@ -8,58 +8,16 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\IpException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::ip()->check('257.0.0.1'); -} catch (IpException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::ip())->check('127.0.0.1'); -} catch (IpException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::ip('127.0.1.*')->check('127.0.0.1'); -} catch (IpException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::ip('127.0.1.*'))->check('127.0.1.1'); -} catch (IpException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::ip()->assert('257.0.0.1'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::ip())->assert('127.0.0.1'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::ip('127.0.1.*')->assert('127.0.0.1'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::ip('127.0.1.*'))->assert('127.0.1.1'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} -?> +exceptionMessage(static fn() => v::ip()->check('257.0.0.1')); +exceptionMessage(static fn() => v::not(v::ip())->check('127.0.0.1')); +exceptionMessage(static fn() => v::ip('127.0.1.*')->check('127.0.0.1')); +exceptionMessage(static fn() => v::not(v::ip('127.0.1.*'))->check('127.0.1.1')); +exceptionFullMessage(static fn() => v::ip()->assert('257.0.0.1')); +exceptionFullMessage(static fn() => v::not(v::ip())->assert('127.0.0.1')); +exceptionFullMessage(static fn() => v::ip('127.0.1.*')->assert('127.0.0.1')); +exceptionFullMessage(static fn() => v::not(v::ip('127.0.1.*'))->assert('127.0.1.1'));?> --SKIPIF-- check('ISBN-12: 978-0-596-52068-7'); -} catch (IsbnException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::isbn())->check('ISBN-13: 978-0-596-52068-7'); -} catch (IsbnException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::isbn()->assert('978 10 596 52068 7'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::isbn())->assert('978 0 596 52068 7'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::isbn()->check('ISBN-12: 978-0-596-52068-7')); +exceptionMessage(static fn() => v::not(v::isbn())->check('ISBN-13: 978-0-596-52068-7')); +exceptionFullMessage(static fn() => v::isbn()->assert('978 10 596 52068 7')); +exceptionFullMessage(static fn() => v::not(v::isbn())->assert('978 0 596 52068 7')); ?> --EXPECT-- "ISBN-12: 978-0-596-52068-7" must be a ISBN diff --git a/tests/integration/rules/iterableType.phpt b/tests/integration/rules/iterableType.phpt index 58a7e5a59..83a925f8c 100644 --- a/tests/integration/rules/iterableType.phpt +++ b/tests/integration/rules/iterableType.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\IterableTypeException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::iterableType()->check(3); -} catch (IterableTypeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::iterableType())->check([2, 3]); -} catch (IterableTypeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::iterableType()->assert('String'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::iterableType())->assert(new stdClass()); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::iterableType()->check(3)); +exceptionMessage(static fn() => v::not(v::iterableType())->check([2, 3])); +exceptionFullMessage(static fn() => v::iterableType()->assert('String')); +exceptionFullMessage(static fn() => v::not(v::iterableType())->assert(new stdClass())); ?> --EXPECT-- 3 must be iterable diff --git a/tests/integration/rules/json.phpt b/tests/integration/rules/json.phpt index ab08d08a6..4e2a943e2 100644 --- a/tests/integration/rules/json.phpt +++ b/tests/integration/rules/json.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\JsonException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::json()->check(false); -} catch (JsonException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::json())->check('{"foo": "bar", "number":1}'); -} catch (JsonException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::json()->assert(new stdClass()); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::json())->assert('{}'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::json()->check(false)); +exceptionMessage(static fn() => v::not(v::json())->check('{"foo": "bar", "number":1}')); +exceptionFullMessage(static fn() => v::json()->assert(new stdClass())); +exceptionFullMessage(static fn() => v::not(v::json())->assert('{}')); ?> --EXPECT-- `FALSE` must be a valid JSON string diff --git a/tests/integration/rules/keyValue.phpt b/tests/integration/rules/keyValue.phpt index 84b760d6d..da4f79b73 100644 --- a/tests/integration/rules/keyValue.phpt +++ b/tests/integration/rules/keyValue.phpt @@ -10,69 +10,18 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\ValidationException; use Respect\Validation\Validator as v; -try { - v::keyValue('foo', 'equals', 'bar')->check(['bar' => 42]); -} catch (ValidationException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::keyValue('foo', 'equals', 'bar')->check(['foo' => 42]); -} catch (ValidationException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::keyValue('foo', 'json', 'bar')->check(['foo' => 42, 'bar' => 43]); -} catch (ValidationException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::keyValue('foo', 'equals', 'bar')->check(['foo' => 1, 'bar' => 2]); -} catch (ValidationException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::keyValue('foo', 'equals', 'bar'))->check(['foo' => 1, 'bar' => 1]); -} catch (ValidationException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::keyValue('foo', 'equals', 'bar')->assert(['bar' => 42]); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::keyValue('foo', 'equals', 'bar')->assert(['foo' => 42]); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::keyValue('foo', 'json', 'bar')->assert(['foo' => 42, 'bar' => 43]); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::keyValue('foo', 'equals', 'bar')->assert(['foo' => 1, 'bar' => 2]); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::keyValue('foo', 'equals', 'bar'))->assert(['foo' => 1, 'bar' => 1]); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::keyValue('foo', 'equals', 'bar')->check(['bar' => 42])); +exceptionMessage(static fn() => v::keyValue('foo', 'equals', 'bar')->check(['foo' => 42])); +exceptionMessage(static fn() => v::keyValue('foo', 'json', 'bar')->check(['foo' => 42, 'bar' => 43])); +exceptionMessage(static fn() => v::keyValue('foo', 'equals', 'bar')->check(['foo' => 1, 'bar' => 2])); +exceptionMessage(static fn() => v::not(v::keyValue('foo', 'equals', 'bar'))->check(['foo' => 1, 'bar' => 1])); +exceptionFullMessage(static fn() => v::keyValue('foo', 'equals', 'bar')->assert(['bar' => 42])); +exceptionFullMessage(static fn() => v::keyValue('foo', 'equals', 'bar')->assert(['foo' => 42])); +exceptionFullMessage(static fn() => v::keyValue('foo', 'json', 'bar')->assert(['foo' => 42, 'bar' => 43])); +exceptionFullMessage(static fn() => v::keyValue('foo', 'equals', 'bar')->assert(['foo' => 1, 'bar' => 2])); +exceptionFullMessage(static fn() => v::not(v::keyValue('foo', 'equals', 'bar'))->assert(['foo' => 1, 'bar' => 1])); ?> --EXPECT-- Key "foo" must be present diff --git a/tests/integration/rules/languageCode.phpt b/tests/integration/rules/languageCode.phpt index 1e0b9caa5..74099b8e5 100644 --- a/tests/integration/rules/languageCode.phpt +++ b/tests/integration/rules/languageCode.phpt @@ -7,34 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\LanguageCodeException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::languageCode()->check(null); -} catch (LanguageCodeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::languageCode())->check('pt'); -} catch (LanguageCodeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::languageCode()->assert('por'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::languageCode())->assert('en'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - +exceptionMessage(static fn() => v::languageCode()->check(null)); +exceptionMessage(static fn() => v::not(v::languageCode())->check('pt')); +exceptionFullMessage(static fn() => v::languageCode()->assert('por')); +exceptionFullMessage(static fn() => v::not(v::languageCode())->assert('en')); ?> --EXPECT-- `NULL` must be a valid ISO 639 "alpha-2" language code diff --git a/tests/integration/rules/leapDate.phpt b/tests/integration/rules/leapDate.phpt index 7f93f0ca9..0ef173dc9 100644 --- a/tests/integration/rules/leapDate.phpt +++ b/tests/integration/rules/leapDate.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\LeapDateException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::leapDate('Y-m-d')->check('1989-02-29'); -} catch (LeapDateException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::leapDate('Y-m-d'))->check('1988-02-29'); -} catch (LeapDateException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::leapDate('Y-m-d')->assert('1990-02-29'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::leapDate('Y-m-d'))->assert('1992-02-29'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::leapDate('Y-m-d')->check('1989-02-29')); +exceptionMessage(static fn() => v::not(v::leapDate('Y-m-d'))->check('1988-02-29')); +exceptionFullMessage(static fn() => v::leapDate('Y-m-d')->assert('1990-02-29')); +exceptionFullMessage(static fn() => v::not(v::leapDate('Y-m-d'))->assert('1992-02-29')); ?> --EXPECT-- "1989-02-29" must be leap date diff --git a/tests/integration/rules/leapYear.phpt b/tests/integration/rules/leapYear.phpt index 3a3025f6b..e2d2ad025 100644 --- a/tests/integration/rules/leapYear.phpt +++ b/tests/integration/rules/leapYear.phpt @@ -7,34 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\LeapYearException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::leapYear()->check('2009'); -} catch (LeapYearException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::leapYear())->check('2008'); -} catch (LeapYearException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::leapYear()->assert('2009-02-29'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::leapYear())->assert('2008'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - +exceptionMessage(static fn() => v::leapYear()->check('2009')); +exceptionMessage(static fn() => v::not(v::leapYear())->check('2008')); +exceptionFullMessage(static fn() => v::leapYear()->assert('2009-02-29')); +exceptionFullMessage(static fn() => v::not(v::leapYear())->assert('2008')); ?> --EXPECT-- "2009" must be a leap year diff --git a/tests/integration/rules/length.phpt b/tests/integration/rules/length.phpt index f3c2bae2d..24100499a 100644 --- a/tests/integration/rules/length.phpt +++ b/tests/integration/rules/length.phpt @@ -8,129 +8,28 @@ declare(strict_types=1); require_once 'vendor/autoload.php'; -use Respect\Validation\Exceptions\LengthException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::length(0, 5, false)->check('phpsp.org.br'); -} catch (LengthException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::length(0, 10)->check('phpsp.org.br'); -} catch (LengthException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::length(15, null, false)->check('phpsp.org.br'); -} catch (LengthException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::length(20)->check('phpsp.org.br'); -} catch (LengthException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::length(5, 10)->check('phpsp.org.br'); -} catch (LengthException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::length(0, 15))->check('phpsp.org.br'); -} catch (LengthException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::length(0, 20, false))->check('phpsp.org.br'); -} catch (LengthException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::length(10, null))->check('phpsp.org.br'); -} catch (LengthException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::length(5, null, false))->check('phpsp.org.br'); -} catch (LengthException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::length(5, 20))->check('phpsp.org.br'); -} catch (LengthException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::length(0, 5, false)->assert('phpsp.org.br'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::length(0, 10)->assert('phpsp.org.br'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::length(15, null, false)->assert('phpsp.org.br'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::length(20)->assert('phpsp.org.br'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::length(5, 10)->assert('phpsp.org.br'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::length(0, 15))->assert('phpsp.org.br'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::length(0, 20, false))->assert('phpsp.org.br'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::length(10, null))->assert('phpsp.org.br'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::length(5, null, false))->assert('phpsp.org.br'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::length(5, 20))->assert('phpsp.org.br'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::length(0, 5, false)->check('phpsp.org.br')); +exceptionMessage(static fn() => v::length(0, 10)->check('phpsp.org.br')); +exceptionMessage(static fn() => v::length(15, null, false)->check('phpsp.org.br')); +exceptionMessage(static fn() => v::length(20)->check('phpsp.org.br')); +exceptionMessage(static fn() => v::length(5, 10)->check('phpsp.org.br')); +exceptionMessage(static fn() => v::not(v::length(0, 15))->check('phpsp.org.br')); +exceptionMessage(static fn() => v::not(v::length(0, 20, false))->check('phpsp.org.br')); +exceptionMessage(static fn() => v::not(v::length(10, null))->check('phpsp.org.br')); +exceptionMessage(static fn() => v::not(v::length(5, null, false))->check('phpsp.org.br')); +exceptionMessage(static fn() => v::not(v::length(5, 20))->check('phpsp.org.br')); +exceptionFullMessage(static fn() => v::length(0, 5, false)->assert('phpsp.org.br')); +exceptionFullMessage(static fn() => v::length(0, 10)->assert('phpsp.org.br')); +exceptionFullMessage(static fn() => v::length(15, null, false)->assert('phpsp.org.br')); +exceptionFullMessage(static fn() => v::length(20)->assert('phpsp.org.br')); +exceptionFullMessage(static fn() => v::length(5, 10)->assert('phpsp.org.br')); +exceptionFullMessage(static fn() => v::not(v::length(0, 15))->assert('phpsp.org.br')); +exceptionFullMessage(static fn() => v::not(v::length(0, 20, false))->assert('phpsp.org.br')); +exceptionFullMessage(static fn() => v::not(v::length(10, null))->assert('phpsp.org.br')); +exceptionFullMessage(static fn() => v::not(v::length(5, null, false))->assert('phpsp.org.br')); +exceptionFullMessage(static fn() => v::not(v::length(5, 20))->assert('phpsp.org.br')); ?> --EXPECT-- "phpsp.org.br" must have a length lower than 5 diff --git a/tests/integration/rules/lessThan.phpt b/tests/integration/rules/lessThan.phpt index 115261454..72cf5d275 100644 --- a/tests/integration/rules/lessThan.phpt +++ b/tests/integration/rules/lessThan.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\LessThanException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::lessThan(12)->check(21); -} catch (LessThanException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::lessThan('today'))->check('yesterday'); -} catch (LessThanException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::lessThan('1988-09-09')->assert('2018-09-09'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::lessThan('b'))->assert('a'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::lessThan(12)->check(21)); +exceptionMessage(static fn() => v::not(v::lessThan('today'))->check('yesterday')); +exceptionFullMessage(static fn() => v::lessThan('1988-09-09')->assert('2018-09-09')); +exceptionFullMessage(static fn() => v::not(v::lessThan('b'))->assert('a')); ?> --EXPECT-- 21 must be less than 12 diff --git a/tests/integration/rules/lowercase.phpt b/tests/integration/rules/lowercase.phpt index 4897d295a..043375c3f 100644 --- a/tests/integration/rules/lowercase.phpt +++ b/tests/integration/rules/lowercase.phpt @@ -7,34 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\LowercaseException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::lowercase()->check('UPPERCASE'); -} catch (LowercaseException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::lowercase())->check('lowercase'); -} catch (LowercaseException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::lowercase()->assert('UPPERCASE'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::lowercase())->assert('lowercase'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - +exceptionMessage(static fn() => v::lowercase()->check('UPPERCASE')); +exceptionMessage(static fn() => v::not(v::lowercase())->check('lowercase')); +exceptionFullMessage(static fn() => v::lowercase()->assert('UPPERCASE')); +exceptionFullMessage(static fn() => v::not(v::lowercase())->assert('lowercase')); ?> --EXPECT-- "UPPERCASE" must be lowercase diff --git a/tests/integration/rules/luhn.phpt b/tests/integration/rules/luhn.phpt index 8d5ef2bd1..cca9bdb7c 100644 --- a/tests/integration/rules/luhn.phpt +++ b/tests/integration/rules/luhn.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\LuhnException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::luhn()->check('2222400041240021'); -} catch (LuhnException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::luhn())->check('2223000048400011'); -} catch (LuhnException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::luhn()->assert('340316193809334'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::luhn())->assert('6011000990139424'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::luhn()->check('2222400041240021')); +exceptionMessage(static fn() => v::not(v::luhn())->check('2223000048400011')); +exceptionFullMessage(static fn() => v::luhn()->assert('340316193809334')); +exceptionFullMessage(static fn() => v::not(v::luhn())->assert('6011000990139424')); ?> --EXPECT-- "2222400041240021" must be a valid Luhn number diff --git a/tests/integration/rules/macAddress.phpt b/tests/integration/rules/macAddress.phpt index f1f051c23..b2239fb5c 100644 --- a/tests/integration/rules/macAddress.phpt +++ b/tests/integration/rules/macAddress.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\MacAddressException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::macAddress()->check('00-11222:33:44:55'); -} catch (MacAddressException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::macAddress())->check('00:11:22:33:44:55'); -} catch (MacAddressException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::macAddress()->assert('90-bc-nk:1a-dd-cc'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::macAddress())->assert('AF:0F:bd:12:44:ba'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::macAddress()->check('00-11222:33:44:55')); +exceptionMessage(static fn() => v::not(v::macAddress())->check('00:11:22:33:44:55')); +exceptionFullMessage(static fn() => v::macAddress()->assert('90-bc-nk:1a-dd-cc')); +exceptionFullMessage(static fn() => v::not(v::macAddress())->assert('AF:0F:bd:12:44:ba')); ?> --EXPECT-- "00-11222:33:44:55" must be a valid MAC address diff --git a/tests/integration/rules/max.phpt b/tests/integration/rules/max.phpt index 970836c7c..dd82cb49e 100644 --- a/tests/integration/rules/max.phpt +++ b/tests/integration/rules/max.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\MaxException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::max(10)->check(11); -} catch (MaxException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::max(10))->check(5); -} catch (MaxException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::max('today')->assert('tomorrow'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::max('b'))->assert('a'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::max(10)->check(11)); +exceptionMessage(static fn() => v::not(v::max(10))->check(5)); +exceptionFullMessage(static fn() => v::max('today')->assert('tomorrow')); +exceptionFullMessage(static fn() => v::not(v::max('b'))->assert('a')); ?> --EXPECT-- 11 must be less than or equal to 10 diff --git a/tests/integration/rules/maxAge.phpt b/tests/integration/rules/maxAge.phpt index 6a8a18a76..6ecec0ae2 100644 --- a/tests/integration/rules/maxAge.phpt +++ b/tests/integration/rules/maxAge.phpt @@ -8,33 +8,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\MaxAgeException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::maxAge(12)->check('50 years ago'); -} catch (MaxAgeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::maxAge(12))->check('11 years ago'); -} catch (MaxAgeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::maxAge(12, 'Y-m-d')->assert('1988-09-09'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::maxAge(12, 'Y-m-d'))->assert('2018-01-01'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::maxAge(12)->check('50 years ago')); +exceptionMessage(static fn() => v::not(v::maxAge(12))->check('11 years ago')); +exceptionFullMessage(static fn() => v::maxAge(12, 'Y-m-d')->assert('1988-09-09')); +exceptionFullMessage(static fn() => v::not(v::maxAge(12, 'Y-m-d'))->assert('2018-01-01')); ?> --EXPECT-- "50 years ago" must be 12 years or less diff --git a/tests/integration/rules/mimetype.phpt b/tests/integration/rules/mimetype.phpt index 93030cb02..52c9b5193 100644 --- a/tests/integration/rules/mimetype.phpt +++ b/tests/integration/rules/mimetype.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\MimetypeException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::mimetype('image/png')->check('image.png'); -} catch (MimetypeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::mimetype('image/png'))->check('tests/fixtures/valid-image.png'); -} catch (MimetypeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::mimetype('image/png')->assert('tests/fixtures/invalid-image.png'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::mimetype('image/png'))->assert('tests/fixtures/valid-image.png'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::mimetype('image/png')->check('image.png')); +exceptionMessage(static fn() => v::not(v::mimetype('image/png'))->check('tests/fixtures/valid-image.png')); +exceptionFullMessage(static fn() => v::mimetype('image/png')->assert('tests/fixtures/invalid-image.png')); +exceptionFullMessage(static fn() => v::not(v::mimetype('image/png'))->assert('tests/fixtures/valid-image.png')); ?> --EXPECT-- "image.png" must have "image/png" MIME type diff --git a/tests/integration/rules/min.phpt b/tests/integration/rules/min.phpt index 2b9098a2e..3b59ffcc8 100644 --- a/tests/integration/rules/min.phpt +++ b/tests/integration/rules/min.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\MinException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::min(INF)->check(10); -} catch (MinException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::min(5))->check(INF); -} catch (MinException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::min('today')->assert('yesterday'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::min('a'))->assert('z'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::min(INF)->check(10)); +exceptionMessage(static fn() => v::not(v::min(5))->check(INF)); +exceptionFullMessage(static fn() => v::min('today')->assert('yesterday')); +exceptionFullMessage(static fn() => v::not(v::min('a'))->assert('z')); ?> --EXPECT-- 10 must be greater than or equal to `INF` diff --git a/tests/integration/rules/minAge.phpt b/tests/integration/rules/minAge.phpt index f4b1b19f5..ae89185f5 100644 --- a/tests/integration/rules/minAge.phpt +++ b/tests/integration/rules/minAge.phpt @@ -10,33 +10,12 @@ require 'vendor/autoload.php'; date_default_timezone_set('UTC'); -use Respect\Validation\Exceptions\MinAgeException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::minAge(18)->check('17 years ago'); -} catch (MinAgeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::minAge(18))->check('-30 years'); -} catch (MinAgeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::minAge(18)->assert('yesterday'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::minAge(18, 'd/m/Y')->assert('12/10/2010'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::minAge(18)->check('17 years ago')); +exceptionMessage(static fn() => v::not(v::minAge(18))->check('-30 years')); +exceptionFullMessage(static fn() => v::minAge(18)->assert('yesterday')); +exceptionFullMessage(static fn() => v::minAge(18, 'd/m/Y')->assert('12/10/2010')); ?> --EXPECT-- "17 years ago" must be 18 years or more diff --git a/tests/integration/rules/multiple.phpt b/tests/integration/rules/multiple.phpt index 6ca75e05e..48827cc2e 100644 --- a/tests/integration/rules/multiple.phpt +++ b/tests/integration/rules/multiple.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\MultipleException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::multiple(3)->check(22); -} catch (MultipleException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::multiple(3))->check(9); -} catch (MultipleException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::multiple(2)->assert(5); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::multiple(5))->assert(25); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::multiple(3)->check(22)); +exceptionMessage(static fn() => v::not(v::multiple(3))->check(9)); +exceptionFullMessage(static fn() => v::multiple(2)->assert(5)); +exceptionFullMessage(static fn() => v::not(v::multiple(5))->assert(25)); ?> --EXPECT-- 22 must be multiple of 3 diff --git a/tests/integration/rules/negative.phpt b/tests/integration/rules/negative.phpt index c400af210..3a5954c1b 100644 --- a/tests/integration/rules/negative.phpt +++ b/tests/integration/rules/negative.phpt @@ -7,34 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NegativeException; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator as v; -try { - v::negative()->check(16); -} catch (NegativeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::negative())->check(-10); -} catch (NegativeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::negative()->assert('a'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::negative())->assert('-144'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - +exceptionMessage(static fn() => v::negative()->check(16)); +exceptionMessage(static fn() => v::not(v::negative())->check(-10)); +exceptionFullMessage(static fn() => v::negative()->assert('a')); +exceptionFullMessage(static fn() => v::not(v::negative())->assert('-144')); ?> --EXPECT-- 16 must be negative diff --git a/tests/integration/rules/nfeAccessKey.phpt b/tests/integration/rules/nfeAccessKey.phpt index 29977cc36..ecdf9a2fd 100644 --- a/tests/integration/rules/nfeAccessKey.phpt +++ b/tests/integration/rules/nfeAccessKey.phpt @@ -7,34 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\NfeAccessKeyException; use Respect\Validation\Validator as v; -try { - v::nfeAccessKey()->check('31841136830118868211870485416765268625116906'); -} catch (NfeAccessKeyException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::nfeAccessKey())->check('52060433009911002506550120000007800267301615'); -} catch (NfeAccessKeyException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::nfeAccessKey()->assert('31841136830118868211870485416765268625116906'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::nfeAccessKey())->assert('52060433009911002506550120000007800267301615'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - +exceptionMessage(static fn() => v::nfeAccessKey()->check('31841136830118868211870485416765268625116906')); +exceptionMessage(static fn() => v::not(v::nfeAccessKey())->check('52060433009911002506550120000007800267301615')); +exceptionFullMessage(static fn() => v::nfeAccessKey()->assert('31841136830118868211870485416765268625116906')); +exceptionFullMessage(static fn() => v::not(v::nfeAccessKey())->assert('52060433009911002506550120000007800267301615')); ?> --EXPECT-- "31841136830118868211870485416765268625116906" must be a valid NFe access key diff --git a/tests/integration/rules/nif.phpt b/tests/integration/rules/nif.phpt index e27b45461..51e0a3ce6 100644 --- a/tests/integration/rules/nif.phpt +++ b/tests/integration/rules/nif.phpt @@ -8,33 +8,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\NifException; use Respect\Validation\Validator as v; -try { - v::nif()->check('06357771Q'); -} catch (NifException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::nif())->check('71110316C'); -} catch (NifException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::nif()->assert('06357771Q'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::nif())->assert('R1332622H'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::nif()->check('06357771Q')); +exceptionMessage(static fn() => v::not(v::nif())->check('71110316C')); +exceptionFullMessage(static fn() => v::nif()->assert('06357771Q')); +exceptionFullMessage(static fn() => v::not(v::nif())->assert('R1332622H')); ?> --EXPECT-- "06357771Q" must be a NIF diff --git a/tests/integration/rules/nip.phpt b/tests/integration/rules/nip.phpt index f2a352f02..bd5b9cda2 100644 --- a/tests/integration/rules/nip.phpt +++ b/tests/integration/rules/nip.phpt @@ -8,33 +8,12 @@ declare(strict_types=1); require_once 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\NipException; use Respect\Validation\Validator as v; -try { - v::nip()->check('1645865778'); -} catch (NipException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::nip())->check('1645865777'); -} catch (NipException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::nip()->assert('1645865778'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::nip())->assert('1645865777'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::nip()->check('1645865778')); +exceptionMessage(static fn() => v::not(v::nip())->check('1645865777')); +exceptionFullMessage(static fn() => v::nip()->assert('1645865778')); +exceptionFullMessage(static fn() => v::not(v::nip())->assert('1645865777')); ?> --EXPECT-- "1645865778" must be a valid Polish VAT identification number diff --git a/tests/integration/rules/no.phpt b/tests/integration/rules/no.phpt index 439b73569..52b3ea226 100644 --- a/tests/integration/rules/no.phpt +++ b/tests/integration/rules/no.phpt @@ -7,36 +7,15 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\NoException; use Respect\Validation\Validator as v; -try { - v::not(v::no())->check('No'); -} catch (NoException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::no()->check('Yes'); -} catch (NoException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::no())->assert('No'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::no()->assert('Yes'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::not(v::no())->check('No')); +exceptionMessage(static fn() => v::no()->check('Yes')); +exceptionFullMessage(static fn() => v::not(v::no())->assert('No')); +exceptionFullMessage(static fn() => v::no()->assert('Yes')); ?> --EXPECT-- -"No" is considered as "No" -"Yes" is not considered as "No" -- "No" is considered as "No" -- "Yes" is not considered as "No" +"No" must not be similar to "No" +"Yes" must be similar to "No" +- "No" must not be similar to "No" +- "Yes" must be similar to "No" diff --git a/tests/integration/rules/noWhitespace.phpt b/tests/integration/rules/noWhitespace.phpt index f53aaf1ce..b8725141d 100644 --- a/tests/integration/rules/noWhitespace.phpt +++ b/tests/integration/rules/noWhitespace.phpt @@ -7,34 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\NoWhitespaceException; use Respect\Validation\Validator as v; -try { - v::noWhitespace()->check('w poiur'); -} catch (NoWhitespaceException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::noWhitespace())->check('wpoiur'); -} catch (NoWhitespaceException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::noWhitespace()->assert('w poiur'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::noWhitespace())->assert('wpoiur'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - +exceptionMessage(static fn() => v::noWhitespace()->check('w poiur')); +exceptionMessage(static fn() => v::not(v::noWhitespace())->check('wpoiur')); +exceptionFullMessage(static fn() => v::noWhitespace()->assert('w poiur')); +exceptionFullMessage(static fn() => v::not(v::noWhitespace())->assert('wpoiur')); ?> --EXPECT-- "w poiur" must not contain whitespace diff --git a/tests/integration/rules/notBlank.phpt b/tests/integration/rules/notBlank.phpt index df26f19ac..42be67bac 100644 --- a/tests/integration/rules/notBlank.phpt +++ b/tests/integration/rules/notBlank.phpt @@ -7,45 +7,14 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\NotBlankException; use Respect\Validation\Validator as v; -try { - v::notBlank()->check(null); -} catch (NotBlankException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::notBlank()->setName('Field')->check(null); -} catch (NotBlankException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::notBlank())->check(1); -} catch (NotBlankException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::notBlank()->assert(''); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::notBlank()->setName('Field')->assert(''); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::notBlank())->assert([1]); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::notBlank()->check(null)); +exceptionMessage(static fn() => v::notBlank()->setName('Field')->check(null)); +exceptionMessage(static fn() => v::not(v::notBlank())->check(1)); +exceptionFullMessage(static fn() => v::notBlank()->assert('')); +exceptionFullMessage(static fn() => v::notBlank()->setName('Field')->assert('')); +exceptionFullMessage(static fn() => v::not(v::notBlank())->assert([1])); ?> --EXPECT-- The value must not be blank diff --git a/tests/integration/rules/notEmoji.phpt b/tests/integration/rules/notEmoji.phpt index 1072256d5..b43f015a3 100644 --- a/tests/integration/rules/notEmoji.phpt +++ b/tests/integration/rules/notEmoji.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\NotEmojiException; use Respect\Validation\Validator as v; -try { - v::notEmoji()->check('🍕'); -} catch (NotEmojiException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::notEmoji())->check('AB'); -} catch (NotEmojiException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::notEmoji()->assert('🏄'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::notEmoji())->assert('YZ'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::notEmoji()->check('🍕')); +exceptionMessage(static fn() => v::not(v::notEmoji())->check('AB')); +exceptionFullMessage(static fn() => v::notEmoji()->assert('🏄')); +exceptionFullMessage(static fn() => v::not(v::notEmoji())->assert('YZ')); ?> --EXPECT-- "🍕" must not contain an Emoji diff --git a/tests/integration/rules/notEmpty.phpt b/tests/integration/rules/notEmpty.phpt index 7c220bf2b..7a2538c11 100644 --- a/tests/integration/rules/notEmpty.phpt +++ b/tests/integration/rules/notEmpty.phpt @@ -8,46 +8,14 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\NotEmptyException; use Respect\Validation\Validator as v; -try { - v::notEmpty()->check(null); -} catch (NotEmptyException $e) { - echo $e->getMessage() . PHP_EOL; -} - -try { - v::notEmpty()->setName('Field')->check(null); -} catch (NotEmptyException $e) { - echo $e->getMessage() . PHP_EOL; -} - -try { - v::not(v::notEmpty())->check(1); -} catch (NotEmptyException $e) { - echo $e->getMessage() . PHP_EOL; -} - -try { - v::notEmpty()->assert(''); -} catch (NestedValidationException $e) { - echo $e->getFullMessage() . PHP_EOL; -} - -try { - v::notEmpty()->setName('Field')->assert(''); -} catch (NestedValidationException $e) { - echo $e->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::notEmpty())->assert([1]); -} catch (NestedValidationException $e) { - echo $e->getFullMessage() . PHP_EOL; -} - +exceptionMessage(static fn() => v::notEmpty()->check(null)); +exceptionMessage(static fn() => v::notEmpty()->setName('Field')->check(null)); +exceptionMessage(static fn() => v::not(v::notEmpty())->check(1)); +exceptionFullMessage(static fn() => v::notEmpty()->assert('')); +exceptionFullMessage(static fn() => v::notEmpty()->setName('Field')->assert('')); +exceptionFullMessage(static fn() => v::not(v::notEmpty())->assert([1])); ?> --EXPECT-- The value must not be empty diff --git a/tests/integration/rules/notOptional.phpt b/tests/integration/rules/notOptional.phpt index 9339d7721..dcf06462f 100644 --- a/tests/integration/rules/notOptional.phpt +++ b/tests/integration/rules/notOptional.phpt @@ -7,57 +7,16 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\NotOptionalException; use Respect\Validation\Validator as v; -try { - v::notOptional()->check(null); -} catch (NotOptionalException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::notOptional())->check(0); -} catch (NotOptionalException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::notOptional()->setName('Field')->check(null); -} catch (NotOptionalException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::notOptional()->setName('Field'))->check([]); -} catch (NotOptionalException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::notOptional()->assert(''); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::notOptional())->assert([]); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::notOptional()->setName('Field')->assert(''); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::notOptional()->setName('Field'))->assert([]); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::notOptional()->check(null)); +exceptionMessage(static fn() => v::not(v::notOptional())->check(0)); +exceptionMessage(static fn() => v::notOptional()->setName('Field')->check(null)); +exceptionMessage(static fn() => v::not(v::notOptional()->setName('Field'))->check([])); +exceptionFullMessage(static fn() => v::notOptional()->assert('')); +exceptionFullMessage(static fn() => v::not(v::notOptional())->assert([])); +exceptionFullMessage(static fn() => v::notOptional()->setName('Field')->assert('')); +exceptionFullMessage(static fn() => v::not(v::notOptional()->setName('Field'))->assert([])); ?> --EXPECT-- The value must not be optional diff --git a/tests/integration/rules/nullType.phpt b/tests/integration/rules/nullType.phpt index 891146435..38b6b095a 100644 --- a/tests/integration/rules/nullType.phpt +++ b/tests/integration/rules/nullType.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\NullTypeException; use Respect\Validation\Validator as v; -try { - v::nullType()->check(''); -} catch (NullTypeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::nullType())->check(null); -} catch (NullTypeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::nullType()->assert(false); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::nullType())->assert(null); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::nullType()->check('')); +exceptionMessage(static fn() => v::not(v::nullType())->check(null)); +exceptionFullMessage(static fn() => v::nullType()->assert(false)); +exceptionFullMessage(static fn() => v::not(v::nullType())->assert(null)); ?> --EXPECT-- "" must be null diff --git a/tests/integration/rules/number.phpt b/tests/integration/rules/number.phpt index fb7f12088..6385539a8 100644 --- a/tests/integration/rules/number.phpt +++ b/tests/integration/rules/number.phpt @@ -7,34 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\NumberException; use Respect\Validation\Validator as v; -try { - v::number()->check(acos(1.01)); -} catch (NumberException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::number())->check(42); -} catch (NumberException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::number()->assert(NAN); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::number())->assert(42); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - +exceptionMessage(static fn() => v::number()->check(acos(1.01))); +exceptionMessage(static fn() => v::not(v::number())->check(42)); +exceptionFullMessage(static fn() => v::number()->assert(NAN)); +exceptionFullMessage(static fn() => v::not(v::number())->assert(42)); ?> --EXPECT-- `NaN` must be a number diff --git a/tests/integration/rules/numericVal.phpt b/tests/integration/rules/numericVal.phpt index 5d493e561..af40dc97a 100644 --- a/tests/integration/rules/numericVal.phpt +++ b/tests/integration/rules/numericVal.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\NumericValException; use Respect\Validation\Validator as v; -try { - v::numericVal()->check('a'); -} catch (NumericValException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::numericVal())->check('1'); -} catch (NumericValException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::numericVal()->assert('a'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::numericVal())->assert('1'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::numericVal()->check('a')); +exceptionMessage(static fn() => v::not(v::numericVal())->check('1')); +exceptionFullMessage(static fn() => v::numericVal()->assert('a')); +exceptionFullMessage(static fn() => v::not(v::numericVal())->assert('1')); ?> --EXPECT-- "a" must be numeric diff --git a/tests/integration/rules/objectType.phpt b/tests/integration/rules/objectType.phpt index 53a16dea1..0fe687cde 100644 --- a/tests/integration/rules/objectType.phpt +++ b/tests/integration/rules/objectType.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\ObjectTypeException; use Respect\Validation\Validator as v; -try { - v::objectType()->check([]); -} catch (ObjectTypeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::objectType())->check(new stdClass()); -} catch (ObjectTypeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::objectType()->assert('test'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::objectType())->assert(new ArrayObject()); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::objectType()->check([])); +exceptionMessage(static fn() => v::not(v::objectType())->check(new stdClass())); +exceptionFullMessage(static fn() => v::objectType()->assert('test')); +exceptionFullMessage(static fn() => v::not(v::objectType())->assert(new ArrayObject())); ?> --EXPECT-- `{ }` must be of type object diff --git a/tests/integration/rules/odd.phpt b/tests/integration/rules/odd.phpt index 224a51160..43691af25 100644 --- a/tests/integration/rules/odd.phpt +++ b/tests/integration/rules/odd.phpt @@ -7,34 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\OddException; use Respect\Validation\Validator as v; -try { - v::odd()->check(2); -} catch (OddException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::odd())->check(7); -} catch (OddException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::odd()->assert(2); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::odd())->assert(9); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - +exceptionMessage(static fn() => v::odd()->check(2)); +exceptionMessage(static fn() => v::not(v::odd())->check(7)); +exceptionFullMessage(static fn() => v::odd()->assert(2)); +exceptionFullMessage(static fn() => v::not(v::odd())->assert(9)); ?> --EXPECT-- 2 must be an odd number diff --git a/tests/integration/rules/optional.phpt b/tests/integration/rules/optional.phpt index 08259f9b9..799fd5fe3 100644 --- a/tests/integration/rules/optional.phpt +++ b/tests/integration/rules/optional.phpt @@ -7,58 +7,16 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\ValidationException; use Respect\Validation\Validator as v; -try { - v::optional(v::alpha())->check(1234); -} catch (ValidationException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::optional(v::alpha())->setName('Name')->check(1234); -} catch (ValidationException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::optional(v::alpha()))->check('abcd'); -} catch (ValidationException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::optional(v::alpha()))->setName('Name')->check('abcd'); -} catch (ValidationException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::optional(v::alpha())->assert(1234); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::optional(v::alpha())->setName('Name')->assert(1234); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::optional(v::alpha()))->assert('abcd'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::optional(v::alpha()))->setName('Name')->assert('abcd'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - +exceptionMessage(static fn() => v::optional(v::alpha())->check(1234)); +exceptionMessage(static fn() => v::optional(v::alpha())->setName('Name')->check(1234)); +exceptionMessage(static fn() => v::not(v::optional(v::alpha()))->check('abcd')); +exceptionMessage(static fn() => v::not(v::optional(v::alpha()))->setName('Name')->check('abcd')); +exceptionFullMessage(static fn() => v::optional(v::alpha())->assert(1234)); +exceptionFullMessage(static fn() => v::optional(v::alpha())->setName('Name')->assert(1234)); +exceptionFullMessage(static fn() => v::not(v::optional(v::alpha()))->assert('abcd')); +exceptionFullMessage(static fn() => v::not(v::optional(v::alpha()))->setName('Name')->assert('abcd')); ?> --EXPECT-- 1234 must contain only letters (a-z) diff --git a/tests/integration/rules/perfectSquare.phpt b/tests/integration/rules/perfectSquare.phpt index 53392c07c..50a5c62b6 100644 --- a/tests/integration/rules/perfectSquare.phpt +++ b/tests/integration/rules/perfectSquare.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\PerfectSquareException; use Respect\Validation\Validator as v; -try { - v::perfectSquare()->check(250); -} catch (PerfectSquareException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::perfectSquare())->check(9); -} catch (PerfectSquareException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::perfectSquare()->assert(7); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::perfectSquare())->assert(400); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::perfectSquare()->check(250)); +exceptionMessage(static fn() => v::not(v::perfectSquare())->check(9)); +exceptionFullMessage(static fn() => v::perfectSquare()->assert(7)); +exceptionFullMessage(static fn() => v::not(v::perfectSquare())->assert(400)); ?> --EXPECT-- 250 must be a valid perfect square diff --git a/tests/integration/rules/pesel.phpt b/tests/integration/rules/pesel.phpt index 236e59fc8..0f3e17430 100644 --- a/tests/integration/rules/pesel.phpt +++ b/tests/integration/rules/pesel.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require_once 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\PeselException; use Respect\Validation\Validator as v; -try { - v::pesel()->check('21120209251'); -} catch (PeselException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::pesel())->check('21120209256'); -} catch (PeselException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::pesel()->assert('21120209251'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::pesel())->assert('21120209256'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::pesel()->check('21120209251')); +exceptionMessage(static fn() => v::not(v::pesel())->check('21120209256')); +exceptionFullMessage(static fn() => v::pesel()->assert('21120209251')); +exceptionFullMessage(static fn() => v::not(v::pesel())->assert('21120209256')); ?> --EXPECT--; "21120209251" must be a valid PESEL diff --git a/tests/integration/rules/phone.phpt b/tests/integration/rules/phone.phpt index ddbaa26bd..87b79deba 100644 --- a/tests/integration/rules/phone.phpt +++ b/tests/integration/rules/phone.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\PhoneException; use Respect\Validation\Validator as v; -try { - v::phone()->check('123'); -} catch (PhoneException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::phone())->check('+1 650 253 00 00'); -} catch (PhoneException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::phone()->assert('(555)5555 555'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::phone())->assert('+55 11 91111 1111'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::phone()->check('123')); +exceptionMessage(static fn() => v::not(v::phone())->check('+1 650 253 00 00')); +exceptionFullMessage(static fn() => v::phone()->assert('(555)5555 555')); +exceptionFullMessage(static fn() => v::not(v::phone())->assert('+55 11 91111 1111')); ?> --EXPECT-- "123" must be a valid telephone number diff --git a/tests/integration/rules/phplabel.phpt b/tests/integration/rules/phplabel.phpt index b07446fbd..c586d41e9 100644 --- a/tests/integration/rules/phplabel.phpt +++ b/tests/integration/rules/phplabel.phpt @@ -10,33 +10,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\PhpLabelException; use Respect\Validation\Validator as v; -try { - v::phpLabel()->check('f o o'); -} catch (PhpLabelException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::phpLabel())->check('correctOne'); -} catch (PhpLabelException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::phpLabel()->assert('0wner'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::phpLabel())->assert('Respect'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::phpLabel()->check('f o o')); +exceptionMessage(static fn() => v::not(v::phpLabel())->check('correctOne')); +exceptionFullMessage(static fn() => v::phpLabel()->assert('0wner')); +exceptionFullMessage(static fn() => v::not(v::phpLabel())->assert('Respect')); ?> --EXPECT-- "f o o" must be a valid PHP label diff --git a/tests/integration/rules/pis.phpt b/tests/integration/rules/pis.phpt index 43deab40a..3b0f5f4ca 100644 --- a/tests/integration/rules/pis.phpt +++ b/tests/integration/rules/pis.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\PisException; use Respect\Validation\Validator as v; -try { - v::pis()->check('this thing'); -} catch (PisException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::pis())->check('120.6671.406-4'); -} catch (PisException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::pis()->assert('your mother'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::pis())->assert('120.9378.174-5'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::pis()->check('this thing')); +exceptionMessage(static fn() => v::not(v::pis())->check('120.6671.406-4')); +exceptionFullMessage(static fn() => v::pis()->assert('your mother')); +exceptionFullMessage(static fn() => v::not(v::pis())->assert('120.9378.174-5')); ?> --EXPECT-- "this thing" must be a valid PIS number diff --git a/tests/integration/rules/polishIdCard.phpt b/tests/integration/rules/polishIdCard.phpt index 1cdbcc89e..5da987ae1 100644 --- a/tests/integration/rules/polishIdCard.phpt +++ b/tests/integration/rules/polishIdCard.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require_once 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\PolishIdCardException; use Respect\Validation\Validator as v; -try { - v::polishIdCard()->check('AYE205411'); -} catch (PolishIdCardException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::polishIdCard())->check('AYE205410'); -} catch (PolishIdCardException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::polishIdCard()->assert('AYE205411'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::polishIdCard())->assert('AYE205410'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::polishIdCard()->check('AYE205411')); +exceptionMessage(static fn() => v::not(v::polishIdCard())->check('AYE205410')); +exceptionFullMessage(static fn() => v::polishIdCard()->assert('AYE205411')); +exceptionFullMessage(static fn() => v::not(v::polishIdCard())->assert('AYE205410')); ?> --EXPECT-- "AYE205411" must be a valid Polish Identity Card number diff --git a/tests/integration/rules/positive.phpt b/tests/integration/rules/positive.phpt index 987797ef6..1e0a22829 100644 --- a/tests/integration/rules/positive.phpt +++ b/tests/integration/rules/positive.phpt @@ -7,34 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\PositiveException; use Respect\Validation\Validator as v; -try { - v::positive()->check(-10); -} catch (PositiveException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::positive())->check(16); -} catch (PositiveException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::positive()->assert('a'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::positive())->assert('165'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - +exceptionMessage(static fn() => v::positive()->check(-10)); +exceptionMessage(static fn() => v::not(v::positive())->check(16)); +exceptionFullMessage(static fn() => v::positive()->assert('a')); +exceptionFullMessage(static fn() => v::not(v::positive())->assert('165')); ?> --EXPECT-- -10 must be positive diff --git a/tests/integration/rules/postalCode.phpt b/tests/integration/rules/postalCode.phpt index 30090866f..bf2ea9636 100644 --- a/tests/integration/rules/postalCode.phpt +++ b/tests/integration/rules/postalCode.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\PostalCodeException; use Respect\Validation\Validator as v; -try { - v::postalCode('BR')->check('1057BV'); -} catch (PostalCodeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::postalCode('NL'))->check('1057BV'); -} catch (PostalCodeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::postalCode('BR')->assert('1057BV'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::postalCode('NL'))->assert('1057BV'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::postalCode('BR')->check('1057BV')); +exceptionMessage(static fn() => v::not(v::postalCode('NL'))->check('1057BV')); +exceptionFullMessage(static fn() => v::postalCode('BR')->assert('1057BV')); +exceptionFullMessage(static fn() => v::not(v::postalCode('NL'))->assert('1057BV')); ?> --EXPECT-- "1057BV" must be a valid postal code on "BR" diff --git a/tests/integration/rules/primeNumber.phpt b/tests/integration/rules/primeNumber.phpt index 4791899e1..c9cf6d33e 100644 --- a/tests/integration/rules/primeNumber.phpt +++ b/tests/integration/rules/primeNumber.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\PrimeNumberException; use Respect\Validation\Validator as v; -try { - v::primeNumber()->check(10); -} catch (PrimeNumberException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::primeNumber())->check(3); -} catch (PrimeNumberException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::primeNumber()->assert('Foo'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::primeNumber())->assert('+7'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::primeNumber()->check(10)); +exceptionMessage(static fn() => v::not(v::primeNumber())->check(3)); +exceptionFullMessage(static fn() => v::primeNumber()->assert('Foo')); +exceptionFullMessage(static fn() => v::not(v::primeNumber())->assert('+7')); ?> --EXPECT-- 10 must be a valid prime number diff --git a/tests/integration/rules/printable.phpt b/tests/integration/rules/printable.phpt index ecd5c28a8..162501162 100644 --- a/tests/integration/rules/printable.phpt +++ b/tests/integration/rules/printable.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\PrintableException; use Respect\Validation\Validator as v; -try { - v::printable()->check(''); -} catch (PrintableException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::printable())->check('abc'); -} catch (PrintableException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::printable()->assert('foo' . chr(10) . 'bar'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::printable())->assert('$%asd'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::printable()->check('')); +exceptionMessage(static fn() => v::not(v::printable())->check('abc')); +exceptionFullMessage(static fn() => v::printable()->assert('foo' . chr(10) . 'bar')); +exceptionFullMessage(static fn() => v::not(v::printable())->assert('$%asd')); ?> --EXPECT-- "" must contain only printable characters diff --git a/tests/integration/rules/punct.phpt b/tests/integration/rules/punct.phpt index 74cc10dcb..dbf33a003 100644 --- a/tests/integration/rules/punct.phpt +++ b/tests/integration/rules/punct.phpt @@ -7,57 +7,16 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\PunctException; use Respect\Validation\Validator as v; -try { - v::punct()->check('a'); -} catch (PunctException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::punct('c')->check('b'); -} catch (PunctException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::punct())->check('.'); -} catch (PunctException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::punct('d'))->check('?'); -} catch (PunctException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::punct()->assert('e'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::punct('f')->assert('g'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::punct())->assert('!'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::punct('h'))->assert(';'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::punct()->check('a')); +exceptionMessage(static fn() => v::punct('c')->check('b')); +exceptionMessage(static fn() => v::not(v::punct())->check('.')); +exceptionMessage(static fn() => v::not(v::punct('d'))->check('?')); +exceptionFullMessage(static fn() => v::punct()->assert('e')); +exceptionFullMessage(static fn() => v::punct('f')->assert('g')); +exceptionFullMessage(static fn() => v::not(v::punct())->assert('!')); +exceptionFullMessage(static fn() => v::not(v::punct('h'))->assert(';')); ?> --EXPECT-- "a" must contain only punctuation characters diff --git a/tests/integration/rules/readable.phpt b/tests/integration/rules/readable.phpt index 207128e0d..f3b1c9a52 100644 --- a/tests/integration/rules/readable.phpt +++ b/tests/integration/rules/readable.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\ReadableException; use Respect\Validation\Validator as v; -try { - v::readable()->check('tests/fixtures/invalid-image.jpg'); -} catch (ReadableException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::readable())->check('tests/fixtures/valid-image.png'); -} catch (ReadableException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::readable()->assert(new stdClass()); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::readable())->assert('tests/fixtures/valid-image.png'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::readable()->check('tests/fixtures/invalid-image.jpg')); +exceptionMessage(static fn() => v::not(v::readable())->check('tests/fixtures/valid-image.png')); +exceptionFullMessage(static fn() => v::readable()->assert(new stdClass())); +exceptionFullMessage(static fn() => v::not(v::readable())->assert('tests/fixtures/valid-image.png')); ?> --EXPECT-- "tests/fixtures/invalid-image.jpg" must be readable diff --git a/tests/integration/rules/regex.phpt b/tests/integration/rules/regex.phpt index 4be9ff432..dc1cd5c32 100644 --- a/tests/integration/rules/regex.phpt +++ b/tests/integration/rules/regex.phpt @@ -5,33 +5,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\RegexException; use Respect\Validation\Validator as v; -try { - v::regex('/^w+$/')->check('w poiur'); -} catch (RegexException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::regex('/^[a-z]+$/'))->check('wpoiur'); -} catch (RegexException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::regex('/^w+$/')->assert(new stdClass()); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::regex('/^[a-z]+$/i'))->assert('wPoiur'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::regex('/^w+$/')->check('w poiur')); +exceptionMessage(static fn() => v::not(v::regex('/^[a-z]+$/'))->check('wpoiur')); +exceptionFullMessage(static fn() => v::regex('/^w+$/')->assert(new stdClass())); +exceptionFullMessage(static fn() => v::not(v::regex('/^[a-z]+$/i'))->assert('wPoiur')); ?> --EXPECT-- "w poiur" must validate against "/^w+$/" diff --git a/tests/integration/rules/resourceType.phpt b/tests/integration/rules/resourceType.phpt index ce906ebbf..809514e37 100644 --- a/tests/integration/rules/resourceType.phpt +++ b/tests/integration/rules/resourceType.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\ResourceTypeException; use Respect\Validation\Validator as v; -try { - v::resourceType()->check('test'); -} catch (ResourceTypeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::resourceType())->check(tmpfile()); -} catch (ResourceTypeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::resourceType()->assert([]); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::resourceType())->assert(tmpfile()); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::resourceType()->check('test')); +exceptionMessage(static fn() => v::not(v::resourceType())->check(tmpfile())); +exceptionFullMessage(static fn() => v::resourceType()->assert([])); +exceptionFullMessage(static fn() => v::not(v::resourceType())->assert(tmpfile())); ?> --EXPECT-- "test" must be a resource diff --git a/tests/integration/rules/roman.phpt b/tests/integration/rules/roman.phpt index 7cc54b015..322d6c1e2 100644 --- a/tests/integration/rules/roman.phpt +++ b/tests/integration/rules/roman.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\RomanException; use Respect\Validation\Validator as v; -try { - v::roman()->check(1234); -} catch (RomanException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::roman())->check('XL'); -} catch (RomanException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::roman()->assert('e2'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::roman())->assert('IV'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::roman()->check(1234)); +exceptionMessage(static fn() => v::not(v::roman())->check('XL')); +exceptionFullMessage(static fn() => v::roman()->assert('e2')); +exceptionFullMessage(static fn() => v::not(v::roman())->assert('IV')); ?> --EXPECT-- 1234 must be a valid Roman numeral diff --git a/tests/integration/rules/scalarVal.phpt b/tests/integration/rules/scalarVal.phpt index 3d19ed45a..257fdfe50 100644 --- a/tests/integration/rules/scalarVal.phpt +++ b/tests/integration/rules/scalarVal.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\ScalarValException; use Respect\Validation\Validator as v; -try { - v::scalarVal()->check([]); -} catch (ScalarValException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::scalarVal())->check(true); -} catch (ScalarValException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::scalarVal()->assert(new stdClass()); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::scalarVal())->assert(42); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::scalarVal()->check([])); +exceptionMessage(static fn() => v::not(v::scalarVal())->check(true)); +exceptionFullMessage(static fn() => v::scalarVal()->assert(new stdClass())); +exceptionFullMessage(static fn() => v::not(v::scalarVal())->assert(42)); ?> --EXPECT-- `{ }` must be a scalar value diff --git a/tests/integration/rules/size.phpt b/tests/integration/rules/size.phpt index e5d2fa748..51b7978e6 100644 --- a/tests/integration/rules/size.phpt +++ b/tests/integration/rules/size.phpt @@ -7,81 +7,20 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\SizeException; use Respect\Validation\Validator as v; -try { - v::size('1kb', '2kb')->check('tests/fixtures/valid-image.gif'); -} catch (SizeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::size('700kb', null)->check('tests/fixtures/valid-image.gif'); -} catch (SizeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::size(null, '1kb')->check('tests/fixtures/valid-image.gif'); -} catch (SizeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::size('500kb', '600kb'))->check('tests/fixtures/valid-image.gif'); -} catch (SizeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::size('500kb', null))->check('tests/fixtures/valid-image.gif'); -} catch (SizeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::size(null, '600kb'))->check('tests/fixtures/valid-image.gif'); -} catch (SizeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::size('1kb', '2kb')->assert('tests/fixtures/valid-image.gif'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::size('700kb', null)->assert('tests/fixtures/valid-image.gif'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::size(null, '1kb')->assert('tests/fixtures/valid-image.gif'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::size('500kb', '600kb'))->assert('tests/fixtures/valid-image.gif'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::size('500kb', null))->assert('tests/fixtures/valid-image.gif'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::size(null, '600kb'))->assert('tests/fixtures/valid-image.gif'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::size('1kb', '2kb')->check('tests/fixtures/valid-image.gif')); +exceptionMessage(static fn() => v::size('700kb', null)->check('tests/fixtures/valid-image.gif')); +exceptionMessage(static fn() => v::size(null, '1kb')->check('tests/fixtures/valid-image.gif')); +exceptionMessage(static fn() => v::not(v::size('500kb', '600kb'))->check('tests/fixtures/valid-image.gif')); +exceptionMessage(static fn() => v::not(v::size('500kb', null))->check('tests/fixtures/valid-image.gif')); +exceptionMessage(static fn() => v::not(v::size(null, '600kb'))->check('tests/fixtures/valid-image.gif')); +exceptionFullMessage(static fn() => v::size('1kb', '2kb')->assert('tests/fixtures/valid-image.gif')); +exceptionFullMessage(static fn() => v::size('700kb', null)->assert('tests/fixtures/valid-image.gif')); +exceptionFullMessage(static fn() => v::size(null, '1kb')->assert('tests/fixtures/valid-image.gif')); +exceptionFullMessage(static fn() => v::not(v::size('500kb', '600kb'))->assert('tests/fixtures/valid-image.gif')); +exceptionFullMessage(static fn() => v::not(v::size('500kb', null))->assert('tests/fixtures/valid-image.gif')); +exceptionFullMessage(static fn() => v::not(v::size(null, '600kb'))->assert('tests/fixtures/valid-image.gif')); ?> --EXPECT-- "tests/fixtures/valid-image.gif" must be between "1kb" and "2kb" diff --git a/tests/integration/rules/slug.phpt b/tests/integration/rules/slug.phpt index f69b16557..4d516da7b 100644 --- a/tests/integration/rules/slug.phpt +++ b/tests/integration/rules/slug.phpt @@ -8,33 +8,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\SlugException; use Respect\Validation\Validator as v; -try { - v::slug()->check('my-Slug'); -} catch (SlugException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::slug())->check('my-slug'); -} catch (SlugException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::slug()->assert('my-Slug'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::slug())->assert('my-slug'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::slug()->check('my-Slug')); +exceptionMessage(static fn() => v::not(v::slug())->check('my-slug')); +exceptionFullMessage(static fn() => v::slug()->assert('my-Slug')); +exceptionFullMessage(static fn() => v::not(v::slug())->assert('my-slug')); ?> --EXPECT-- "my-Slug" must be a valid slug diff --git a/tests/integration/rules/sorted.phpt b/tests/integration/rules/sorted.phpt index b578cfbbb..50d2800b4 100644 --- a/tests/integration/rules/sorted.phpt +++ b/tests/integration/rules/sorted.phpt @@ -8,57 +8,16 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\SortedException; use Respect\Validation\Validator as v; -try { - v::sorted('ASC')->check([1, 3, 2]); -} catch (SortedException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::sorted('DESC')->check([1, 2, 3]); -} catch (SortedException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::sorted('ASC'))->check([1, 2, 3]); -} catch (SortedException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::sorted('DESC'))->check([3, 2, 1]); -} catch (SortedException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::sorted('ASC')->assert([3, 2, 1]); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::sorted('DESC')->assert([1, 2, 3]); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::sorted('ASC'))->assert([1, 2, 3]); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::sorted('DESC'))->assert([3, 2, 1]); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::sorted('ASC')->check([1, 3, 2])); +exceptionMessage(static fn() => v::sorted('DESC')->check([1, 2, 3])); +exceptionMessage(static fn() => v::not(v::sorted('ASC'))->check([1, 2, 3])); +exceptionMessage(static fn() => v::not(v::sorted('DESC'))->check([3, 2, 1])); +exceptionFullMessage(static fn() => v::sorted('ASC')->assert([3, 2, 1])); +exceptionFullMessage(static fn() => v::sorted('DESC')->assert([1, 2, 3])); +exceptionFullMessage(static fn() => v::not(v::sorted('ASC'))->assert([1, 2, 3])); +exceptionFullMessage(static fn() => v::not(v::sorted('DESC'))->assert([3, 2, 1])); ?> --EXPECT-- `{ 1, 3, 2 }` must be sorted in ascending order diff --git a/tests/integration/rules/space.phpt b/tests/integration/rules/space.phpt index 1838a7b8f..ced885568 100644 --- a/tests/integration/rules/space.phpt +++ b/tests/integration/rules/space.phpt @@ -7,57 +7,16 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\SpaceException; use Respect\Validation\Validator as v; -try { - v::space()->check('ab'); -} catch (SpaceException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::space('c')->check('cd'); -} catch (SpaceException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::space())->check("\t"); -} catch (SpaceException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::space('def'))->check("\r"); -} catch (SpaceException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::space()->assert('ef'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::space('e')->assert('gh'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::space())->assert("\n"); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::space('yk'))->assert(' k'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::space()->check('ab')); +exceptionMessage(static fn() => v::space('c')->check('cd')); +exceptionMessage(static fn() => v::not(v::space())->check("\t")); +exceptionMessage(static fn() => v::not(v::space('def'))->check("\r")); +exceptionFullMessage(static fn() => v::space()->assert('ef')); +exceptionFullMessage(static fn() => v::space('e')->assert('gh')); +exceptionFullMessage(static fn() => v::not(v::space())->assert("\n")); +exceptionFullMessage(static fn() => v::not(v::space('yk'))->assert(' k')); ?> --EXPECT-- "ab" must contain only space characters diff --git a/tests/integration/rules/startsWith.phpt b/tests/integration/rules/startsWith.phpt index ae8c11c92..5f8980845 100644 --- a/tests/integration/rules/startsWith.phpt +++ b/tests/integration/rules/startsWith.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\StartsWithException; use Respect\Validation\Validator as v; -try { - v::startsWith('b')->check(['a', 'b']); -} catch (StartsWithException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::startsWith(1.1))->check([1.1, 2.2]); -} catch (StartsWithException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::startsWith('3.3', true)->assert([3.3, 4.4]); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::startsWith('c'))->assert(['c', 'd']); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::startsWith('b')->check(['a', 'b'])); +exceptionMessage(static fn() => v::not(v::startsWith(1.1))->check([1.1, 2.2])); +exceptionFullMessage(static fn() => v::startsWith('3.3', true)->assert([3.3, 4.4])); +exceptionFullMessage(static fn() => v::not(v::startsWith('c'))->assert(['c', 'd'])); ?> --EXPECT-- `{ "a", "b" }` must start with "b" diff --git a/tests/integration/rules/stringType.phpt b/tests/integration/rules/stringType.phpt index 997694bb6..41cd6317f 100644 --- a/tests/integration/rules/stringType.phpt +++ b/tests/integration/rules/stringType.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\StringTypeException; use Respect\Validation\Validator as v; -try { - v::stringType()->check(42); -} catch (StringTypeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::stringType())->check('foo'); -} catch (StringTypeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::stringType()->assert(true); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::stringType())->assert('bar'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::stringType()->check(42)); +exceptionMessage(static fn() => v::not(v::stringType())->check('foo')); +exceptionFullMessage(static fn() => v::stringType()->assert(true)); +exceptionFullMessage(static fn() => v::not(v::stringType())->assert('bar')); ?> --EXPECT-- 42 must be of type string diff --git a/tests/integration/rules/stringVal.phpt b/tests/integration/rules/stringVal.phpt index eda0593a8..a1b53277b 100644 --- a/tests/integration/rules/stringVal.phpt +++ b/tests/integration/rules/stringVal.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\StringValException; use Respect\Validation\Validator as v; -try { - v::stringVal()->check([]); -} catch (StringValException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::stringVal())->check(true); -} catch (StringValException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::stringVal()->assert(new stdClass()); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::stringVal())->assert(42); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::stringVal()->check([])); +exceptionMessage(static fn() => v::not(v::stringVal())->check(true)); +exceptionFullMessage(static fn() => v::stringVal()->assert(new stdClass())); +exceptionFullMessage(static fn() => v::not(v::stringVal())->assert(42)); ?> --EXPECT-- `{ }` must be a string diff --git a/tests/integration/rules/subset.phpt b/tests/integration/rules/subset.phpt index deab12d47..f85e1e0da 100644 --- a/tests/integration/rules/subset.phpt +++ b/tests/integration/rules/subset.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\SubsetException; use Respect\Validation\Validator as v; -try { - v::subset([1, 2])->check([1, 2, 3]); -} catch (SubsetException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::subset([1, 2, 3]))->check([1, 2]); -} catch (SubsetException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::subset(['A', 'B'])->assert(['B', 'C']); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::subset(['A']))->assert(['A']); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::subset([1, 2])->check([1, 2, 3])); +exceptionMessage(static fn() => v::not(v::subset([1, 2, 3]))->check([1, 2])); +exceptionFullMessage(static fn() => v::subset(['A', 'B'])->assert(['B', 'C'])); +exceptionFullMessage(static fn() => v::not(v::subset(['A']))->assert(['A'])); ?> --EXPECT-- `{ 1, 2, 3 }` must be subset of `{ 1, 2 }` diff --git a/tests/integration/rules/symbolicLink.phpt b/tests/integration/rules/symbolicLink.phpt index 584688f64..8330e8350 100644 --- a/tests/integration/rules/symbolicLink.phpt +++ b/tests/integration/rules/symbolicLink.phpt @@ -8,33 +8,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\SymbolicLinkException; use Respect\Validation\Validator as v; -try { - v::symbolicLink()->check('tests/fixtures/fake-filename'); -} catch (SymbolicLinkException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::symbolicLink())->check('tests/fixtures/symbolic-link'); -} catch (SymbolicLinkException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::symbolicLink()->assert('tests/fixtures/fake-filename'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::symbolicLink())->assert('tests/fixtures/symbolic-link'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::symbolicLink()->check('tests/fixtures/fake-filename')); +exceptionMessage(static fn() => v::not(v::symbolicLink())->check('tests/fixtures/symbolic-link')); +exceptionFullMessage(static fn() => v::symbolicLink()->assert('tests/fixtures/fake-filename')); +exceptionFullMessage(static fn() => v::not(v::symbolicLink())->assert('tests/fixtures/symbolic-link')); ?> --EXPECT-- "tests/fixtures/fake-filename" must be a symbolic link diff --git a/tests/integration/rules/time.phpt b/tests/integration/rules/time.phpt index 816b6a34d..294619a4b 100644 --- a/tests/integration/rules/time.phpt +++ b/tests/integration/rules/time.phpt @@ -7,35 +7,14 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\TimeException; use Respect\Validation\Validator as v; date_default_timezone_set('UTC'); -try { - v::time()->check('2018-01-30'); -} catch (TimeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::time())->check('09:25:46'); -} catch (TimeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::time()->assert('2018-01-30'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::time('g:i A'))->assert('8:13 AM'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::time()->check('2018-01-30')); +exceptionMessage(static fn() => v::not(v::time())->check('09:25:46')); +exceptionFullMessage(static fn() => v::time()->assert('2018-01-30')); +exceptionFullMessage(static fn() => v::not(v::time('g:i A'))->assert('8:13 AM')); ?> --EXPECT-- "2018-01-30" must be a valid time in the format "23:59:59" diff --git a/tests/integration/rules/tld.phpt b/tests/integration/rules/tld.phpt index 7f8dae05e..36a852c2e 100644 --- a/tests/integration/rules/tld.phpt +++ b/tests/integration/rules/tld.phpt @@ -7,34 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\TldException; use Respect\Validation\Validator as v; -try { - v::tld()->check('42'); -} catch (TldException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::tld())->check('com'); -} catch (TldException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::tld()->assert('1984'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::tld())->assert('com'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - +exceptionMessage(static fn() => v::tld()->check('42')); +exceptionMessage(static fn() => v::not(v::tld())->check('com')); +exceptionFullMessage(static fn() => v::tld()->assert('1984')); +exceptionFullMessage(static fn() => v::not(v::tld())->assert('com')); ?> --EXPECT-- "42" must be a valid top-level domain name diff --git a/tests/integration/rules/trueVal.phpt b/tests/integration/rules/trueVal.phpt index 4c90e4a34..1a73c185e 100644 --- a/tests/integration/rules/trueVal.phpt +++ b/tests/integration/rules/trueVal.phpt @@ -7,36 +7,15 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\TrueValException; use Respect\Validation\Validator as v; -try { - v::trueVal()->check(false); -} catch (TrueValException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::trueVal())->check(1); -} catch (TrueValException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::trueVal()->assert(0); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::trueVal())->assert('true'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::trueVal()->check(false)); +exceptionMessage(static fn() => v::not(v::trueVal())->check(1)); +exceptionFullMessage(static fn() => v::trueVal()->assert(0)); +exceptionFullMessage(static fn() => v::not(v::trueVal())->assert('true')); ?> --EXPECT-- -`FALSE` is not considered as "True" -1 is considered as "True" -- 0 is not considered as "True" -- "true" is considered as "True" +`FALSE` must evaluate to `true` +1 must not evaluate to `true` +- 0 must evaluate to `true` +- "true" must not evaluate to `true` diff --git a/tests/integration/rules/type.phpt b/tests/integration/rules/type.phpt index 0b09d9ea2..8f936ccef 100644 --- a/tests/integration/rules/type.phpt +++ b/tests/integration/rules/type.phpt @@ -7,33 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\TypeException; use Respect\Validation\Validator as v; -try { - v::type('integer')->check('42'); -} catch (TypeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::type('string'))->check('foo'); -} catch (TypeException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::type('double')->assert(20); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::type('bool'))->assert(true); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::type('integer')->check('42')); +exceptionMessage(static fn() => v::not(v::type('string'))->check('foo')); +exceptionFullMessage(static fn() => v::type('double')->assert(20)); +exceptionFullMessage(static fn() => v::not(v::type('bool'))->assert(true)); ?> --EXPECT-- "42" must be "integer" diff --git a/tests/integration/rules/unique.phpt b/tests/integration/rules/unique.phpt index 6a4069925..e66c6fb74 100644 --- a/tests/integration/rules/unique.phpt +++ b/tests/integration/rules/unique.phpt @@ -7,34 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\UniqueException; use Respect\Validation\Validator as v; -try { - v::unique()->check([1, 2, 2, 3]); -} catch (UniqueException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::unique())->check([1, 2, 3, 4]); -} catch (UniqueException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::unique()->assert('test'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::unique())->assert(['a', 'b', 'c']); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - +exceptionMessage(static fn() => v::unique()->check([1, 2, 2, 3])); +exceptionMessage(static fn() => v::not(v::unique())->check([1, 2, 3, 4])); +exceptionFullMessage(static fn() => v::unique()->assert('test')); +exceptionFullMessage(static fn() => v::not(v::unique())->assert(['a', 'b', 'c'])); ?> --EXPECT-- `{ 1, 2, 2, 3 }` must not contain duplicates diff --git a/tests/integration/rules/uploaded.phpt b/tests/integration/rules/uploaded.phpt index 0357d924b..b0ccfd9c1 100644 --- a/tests/integration/rules/uploaded.phpt +++ b/tests/integration/rules/uploaded.phpt @@ -7,38 +7,16 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\UploadedException; use Respect\Validation\Validator as v; uopz_set_return('is_uploaded_file', false); -try { - v::uploaded()->check('filename'); -} catch (UploadedException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - +exceptionMessage(static fn() => v::uploaded()->check('filename')); uopz_set_return('is_uploaded_file', true); -try { - v::not(v::uploaded())->check('filename'); -} catch (UploadedException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - +exceptionMessage(static fn() => v::not(v::uploaded())->check('filename')); uopz_set_return('is_uploaded_file', false); -try { - v::uploaded()->assert('filename'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - +exceptionFullMessage(static fn() => v::uploaded()->assert('filename')); uopz_set_return('is_uploaded_file', true); -try { - v::not(v::uploaded())->assert('filename'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} -?> +exceptionFullMessage(static fn() => v::not(v::uploaded())->assert('filename'));?> --SKIPIF-- check('lowercase'); -} catch (UppercaseException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::uppercase()->assert('lowercase'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::uppercase())->check('UPPERCASE'); -} catch (UppercaseException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::uppercase())->assert('UPPERCASE'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - +exceptionMessage(static fn() => v::uppercase()->check('lowercase')); +exceptionFullMessage(static fn() => v::uppercase()->assert('lowercase')); +exceptionMessage(static fn() => v::not(v::uppercase())->check('UPPERCASE')); +exceptionFullMessage(static fn() => v::not(v::uppercase())->assert('UPPERCASE')); ?> --EXPECT-- "lowercase" must be uppercase diff --git a/tests/integration/rules/url.phpt b/tests/integration/rules/url.phpt index 43650ae06..1f6d73ffb 100644 --- a/tests/integration/rules/url.phpt +++ b/tests/integration/rules/url.phpt @@ -7,34 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\UrlException; use Respect\Validation\Validator as v; -try { - v::url()->check('example.com'); -} catch (UrlException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::url())->check('http://example.com'); -} catch (UrlException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::url()->assert('example.com'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::url())->assert('http://example.com'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - +exceptionMessage(static fn() => v::url()->check('example.com')); +exceptionMessage(static fn() => v::not(v::url())->check('http://example.com')); +exceptionFullMessage(static fn() => v::url()->assert('example.com')); +exceptionFullMessage(static fn() => v::not(v::url())->assert('http://example.com')); ?> --EXPECT-- "example.com" must be a URL diff --git a/tests/integration/rules/uuid.phpt b/tests/integration/rules/uuid.phpt index e4ec76c7d..a802eca35 100644 --- a/tests/integration/rules/uuid.phpt +++ b/tests/integration/rules/uuid.phpt @@ -7,57 +7,16 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\UuidException; use Respect\Validation\Validator as v; -try { - v::uuid()->check('g71a18f4-3a13-11e7-a919-92ebcb67fe33'); -} catch (UuidException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::uuid(1)->check('e0b5ffb9-9caf-2a34-9673-8fc91db78be6'); -} catch (UuidException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::uuid())->check('fb3a7909-8034-59f5-8f38-21adbc168db7'); -} catch (UuidException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::uuid(3))->check('11a38b9a-b3da-360f-9353-a5a725514269'); -} catch (UuidException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::uuid()->assert('g71a18f4-3a13-11e7-a919-92ebcb67fe33'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::uuid(4)->assert('a71a18f4-3a13-11e7-a919-92ebcb67fe33'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::uuid())->assert('e0b5ffb9-9caf-4a34-9673-8fc91db78be6'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::uuid(5))->assert('c4a760a8-dbcf-5254-a0d9-6a4474bd1b62'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::uuid()->check('g71a18f4-3a13-11e7-a919-92ebcb67fe33')); +exceptionMessage(static fn() => v::uuid(1)->check('e0b5ffb9-9caf-2a34-9673-8fc91db78be6')); +exceptionMessage(static fn() => v::not(v::uuid())->check('fb3a7909-8034-59f5-8f38-21adbc168db7')); +exceptionMessage(static fn() => v::not(v::uuid(3))->check('11a38b9a-b3da-360f-9353-a5a725514269')); +exceptionFullMessage(static fn() => v::uuid()->assert('g71a18f4-3a13-11e7-a919-92ebcb67fe33')); +exceptionFullMessage(static fn() => v::uuid(4)->assert('a71a18f4-3a13-11e7-a919-92ebcb67fe33')); +exceptionFullMessage(static fn() => v::not(v::uuid())->assert('e0b5ffb9-9caf-4a34-9673-8fc91db78be6')); +exceptionFullMessage(static fn() => v::not(v::uuid(5))->assert('c4a760a8-dbcf-5254-a0d9-6a4474bd1b62')); ?> --EXPECT-- "g71a18f4-3a13-11e7-a919-92ebcb67fe33" must be a valid UUID diff --git a/tests/integration/rules/version.phpt b/tests/integration/rules/version.phpt index 1dd4d77c0..da006de42 100644 --- a/tests/integration/rules/version.phpt +++ b/tests/integration/rules/version.phpt @@ -7,34 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\VersionException; use Respect\Validation\Validator as v; -try { - v::version()->check('1.3.7--'); -} catch (VersionException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::version())->check('1.0.0-alpha'); -} catch (VersionException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::version()->assert('1.2.3.4-beta'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::version())->assert('1.3.7-rc.1'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - +exceptionMessage(static fn() => v::version()->check('1.3.7--')); +exceptionMessage(static fn() => v::not(v::version())->check('1.0.0-alpha')); +exceptionFullMessage(static fn() => v::version()->assert('1.2.3.4-beta')); +exceptionFullMessage(static fn() => v::not(v::version())->assert('1.3.7-rc.1')); ?> --EXPECT-- "1.3.7--" must be a version diff --git a/tests/integration/rules/videoUrl.phpt b/tests/integration/rules/videoUrl.phpt index 4e0be4988..3f63b8805 100644 --- a/tests/integration/rules/videoUrl.phpt +++ b/tests/integration/rules/videoUrl.phpt @@ -7,57 +7,16 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\VideoUrlException; use Respect\Validation\Validator as v; -try { - v::videoUrl()->check('example.com'); -} catch (VideoUrlException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::videoUrl('YouTube')->check('example.com'); -} catch (VideoUrlException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::videoUrl())->check('https://player.vimeo.com/video/7178746722'); -} catch (VideoUrlException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::videoUrl('YouTube'))->check('https://www.youtube.com/embed/netHLn9TScY'); -} catch (VideoUrlException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::videoUrl()->assert('example.com'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::videoUrl('Vimeo')->assert('example.com'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::videoUrl())->assert('https://youtu.be/netHLn9TScY'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::videoUrl('Vimeo'))->assert('https://vimeo.com/71787467'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::videoUrl()->check('example.com')); +exceptionMessage(static fn() => v::videoUrl('YouTube')->check('example.com')); +exceptionMessage(static fn() => v::not(v::videoUrl())->check('https://player.vimeo.com/video/7178746722')); +exceptionMessage(static fn() => v::not(v::videoUrl('YouTube'))->check('https://www.youtube.com/embed/netHLn9TScY')); +exceptionFullMessage(static fn() => v::videoUrl()->assert('example.com')); +exceptionFullMessage(static fn() => v::videoUrl('Vimeo')->assert('example.com')); +exceptionFullMessage(static fn() => v::not(v::videoUrl())->assert('https://youtu.be/netHLn9TScY')); +exceptionFullMessage(static fn() => v::not(v::videoUrl('Vimeo'))->assert('https://vimeo.com/71787467')); ?> --EXPECT-- "example.com" must be a valid video URL diff --git a/tests/integration/rules/vowel.phpt b/tests/integration/rules/vowel.phpt index d69289bc7..e7f25834e 100644 --- a/tests/integration/rules/vowel.phpt +++ b/tests/integration/rules/vowel.phpt @@ -7,58 +7,16 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\VowelException; use Respect\Validation\Validator as v; -try { - v::vowel()->check('b'); -} catch (VowelException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::vowel('c')->check('d'); -} catch (VowelException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::vowel())->check('a'); -} catch (VowelException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::vowel('f'))->check('e'); -} catch (VowelException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::vowel()->assert('g'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::vowel('h')->assert('j'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::vowel())->assert('i'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::vowel('k'))->assert('o'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - +exceptionMessage(static fn() => v::vowel()->check('b')); +exceptionMessage(static fn() => v::vowel('c')->check('d')); +exceptionMessage(static fn() => v::not(v::vowel())->check('a')); +exceptionMessage(static fn() => v::not(v::vowel('f'))->check('e')); +exceptionFullMessage(static fn() => v::vowel()->assert('g')); +exceptionFullMessage(static fn() => v::vowel('h')->assert('j')); +exceptionFullMessage(static fn() => v::not(v::vowel())->assert('i')); +exceptionFullMessage(static fn() => v::not(v::vowel('k'))->assert('o')); ?> --EXPECT-- "b" must contain only vowels diff --git a/tests/integration/rules/when.phpt b/tests/integration/rules/when.phpt index 6bded30ea..99e649d7c 100644 --- a/tests/integration/rules/when.phpt +++ b/tests/integration/rules/when.phpt @@ -7,58 +7,18 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\IntValException; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\WhenException; use Respect\Validation\Validator as v; -try { - v::when(v::alwaysValid(), v::intVal())->check('abc'); -} catch (IntValException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::when(v::alwaysInvalid(), v::alwaysValid(), v::intVal())->check('def'); -} catch (IntValException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::when(v::alwaysValid(), v::stringVal()))->check('ghi'); -} catch (WhenException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::when(v::alwaysInvalid(), v::alwaysValid(), v::stringVal()))->check('jkl'); -} catch (WhenException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::when(v::alwaysValid(), v::intVal())->assert('mno'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::when(v::alwaysInvalid(), v::alwaysValid(), v::intVal())->assert('pqr'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::when(v::alwaysValid(), v::stringVal()))->assert('stu'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { +exceptionMessage(static fn() => v::when(v::alwaysValid(), v::intVal())->check('abc')); +exceptionMessage(static fn() => v::when(v::alwaysInvalid(), v::alwaysValid(), v::intVal())->check('def')); +exceptionMessage(static fn() => v::not(v::when(v::alwaysValid(), v::stringVal()))->check('ghi')); +exceptionMessage(static fn() => v::not(v::when(v::alwaysInvalid(), v::alwaysValid(), v::stringVal()))->check('jkl')); +exceptionFullMessage(static fn() => v::when(v::alwaysValid(), v::intVal())->assert('mno')); +exceptionFullMessage(static fn() => v::when(v::alwaysInvalid(), v::alwaysValid(), v::intVal())->assert('pqr')); +exceptionFullMessage(static fn() => v::not(v::when(v::alwaysValid(), v::stringVal()))->assert('stu')); +exceptionFullMessage(static function () { v::not(v::when(v::alwaysInvalid(), v::alwaysValid(), v::stringVal()))->assert('vwx'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +}); ?> --EXPECT-- "abc" must be an integer number diff --git a/tests/integration/rules/writable.phpt b/tests/integration/rules/writable.phpt index 180b70023..3a8e0e058 100644 --- a/tests/integration/rules/writable.phpt +++ b/tests/integration/rules/writable.phpt @@ -7,34 +7,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\WritableException; use Respect\Validation\Validator as v; -try { - v::writable()->check('/path/of/a/valid/writable/file.txt'); -} catch (WritableException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::writable())->check('tests/fixtures/valid-image.png'); -} catch (WritableException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::writable()->assert([]); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::writable())->assert('tests/fixtures/invalid-image.png'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - +exceptionMessage(static fn() => v::writable()->check('/path/of/a/valid/writable/file.txt')); +exceptionMessage(static fn() => v::not(v::writable())->check('tests/fixtures/valid-image.png')); +exceptionFullMessage(static fn() => v::writable()->assert([])); +exceptionFullMessage(static fn() => v::not(v::writable())->assert('tests/fixtures/invalid-image.png')); ?> --EXPECT-- "/path/of/a/valid/writable/file.txt" must be writable diff --git a/tests/integration/rules/xdigit.phpt b/tests/integration/rules/xdigit.phpt index 2d13b8338..8205efb2c 100644 --- a/tests/integration/rules/xdigit.phpt +++ b/tests/integration/rules/xdigit.phpt @@ -7,57 +7,16 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\XdigitException; use Respect\Validation\Validator as v; -try { - v::xdigit()->check('aaa%a'); -} catch (XdigitException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::xdigit(' ')->check('bbb%b'); -} catch (XdigitException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::xdigit())->check('ccccc'); -} catch (XdigitException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::xdigit('% '))->check('ddd%d'); -} catch (XdigitException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::xdigit()->assert('eee^e'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::xdigit())->assert('fffff'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::xdigit('* &%')->assert('000^0'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::not(v::xdigit('^'))->assert('111^1'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::xdigit()->check('aaa%a')); +exceptionMessage(static fn() => v::xdigit(' ')->check('bbb%b')); +exceptionMessage(static fn() => v::not(v::xdigit())->check('ccccc')); +exceptionMessage(static fn() => v::not(v::xdigit('% '))->check('ddd%d')); +exceptionFullMessage(static fn() => v::xdigit()->assert('eee^e')); +exceptionFullMessage(static fn() => v::not(v::xdigit())->assert('fffff')); +exceptionFullMessage(static fn() => v::xdigit('* &%')->assert('000^0')); +exceptionFullMessage(static fn() => v::not(v::xdigit('^'))->assert('111^1')); ?> --EXPECT-- "aaa%a" contain only hexadecimal digits diff --git a/tests/integration/rules/yes.phpt b/tests/integration/rules/yes.phpt index 418ee886e..9508d9ee1 100644 --- a/tests/integration/rules/yes.phpt +++ b/tests/integration/rules/yes.phpt @@ -7,36 +7,15 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Exceptions\YesException; use Respect\Validation\Validator as v; -try { - v::not(v::yes())->check('Yes'); -} catch (YesException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::yes()->check('si'); -} catch (YesException $exception) { - echo $exception->getMessage() . PHP_EOL; -} - -try { - v::not(v::yes())->assert('Yes'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} - -try { - v::yes()->assert('si'); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::not(v::yes())->check('Yes')); +exceptionMessage(static fn() => v::yes()->check('si')); +exceptionFullMessage(static fn() => v::not(v::yes())->assert('Yes')); +exceptionFullMessage(static fn() => v::yes()->assert('si')); ?> --EXPECT-- -"Yes" is considered as "Yes" -"si" is not considered as "Yes" -- "Yes" is considered as "Yes" -- "si" is not considered as "Yes" +"Yes" must not be similar to "Yes" +"si" must be similar to "Yes" +- "Yes" must not be similar to "Yes" +- "si" must be similar to "Yes" diff --git a/tests/integration/set_template_with_multiple_validators_should_use_template_as_full_message.phpt b/tests/integration/set_template_with_multiple_validators_should_use_template_as_full_message.phpt index 9673e54e7..d1ed065a7 100644 --- a/tests/integration/set_template_with_multiple_validators_should_use_template_as_full_message.phpt +++ b/tests/integration/set_template_with_multiple_validators_should_use_template_as_full_message.phpt @@ -9,14 +9,11 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator; -try { +exceptionFullMessage(static function () { Validator::callback('is_string')->between(1, 2)->setTemplate('{{name}} is not tasty')->assert('something'); -} catch (NestedValidationException $e) { - echo $e->getFullMessage(); -} +}); ?> --EXPECT-- - "something" is not tasty diff --git a/tests/integration/set_template_with_multiple_validators_should_use_template_as_main_message.phpt b/tests/integration/set_template_with_multiple_validators_should_use_template_as_main_message.phpt index 1fd8e0ee6..96973a937 100644 --- a/tests/integration/set_template_with_multiple_validators_should_use_template_as_main_message.phpt +++ b/tests/integration/set_template_with_multiple_validators_should_use_template_as_main_message.phpt @@ -9,14 +9,11 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator; -try { +exceptionMessage(static function () { Validator::callback('is_int')->between(1, 2)->setTemplate('{{name}} is not tasty')->assert('something'); -} catch (NestedValidationException $e) { - echo $e->getMessage(); -} +}); ?> --EXPECT-- "something" is not tasty diff --git a/tests/integration/set_template_with_single_validator_should_use_template_as_main_message.phpt b/tests/integration/set_template_with_single_validator_should_use_template_as_main_message.phpt index afd36de1b..9f0bd2333 100644 --- a/tests/integration/set_template_with_single_validator_should_use_template_as_main_message.phpt +++ b/tests/integration/set_template_with_single_validator_should_use_template_as_main_message.phpt @@ -9,23 +9,12 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Validator; $rule = Validator::callback('is_int')->setTemplate('{{name}} is not tasty'); -try { - $rule->assert('something'); -} catch (NestedValidationException $e) { - echo $e->getMessage(); -} -echo PHP_EOL; - -try { - $rule->check('something'); -} catch (NestedValidationException $e) { - echo $e->getMessage(); -} +exceptionMessage(static fn() => $rule->assert('something')); +exceptionMessage(static fn() => $rule->check('something')); ?> --EXPECT-- "something" is not tasty diff --git a/tests/integration/should_not_overwrite_defined_names.phpt b/tests/integration/should_not_overwrite_defined_names.phpt index 4bd2477a9..0365bc105 100644 --- a/tests/integration/should_not_overwrite_defined_names.phpt +++ b/tests/integration/should_not_overwrite_defined_names.phpt @@ -7,30 +7,17 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\ValidationException; use Respect\Validation\Validator as v; $input = ['email' => 'not an email']; -try { - v::key('email', v::email()->setName('Email'))->setName('Foo')->check($input); -} catch (ValidationException $exception) { - echo $exception->getMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::key('email', v::email()->setName('Email'))->setName('Foo')->check($input)); -try { - // This is a trick thing: the call to `setName()` here seems to be the one - // from the `Key` rule but it's actually from the `Validator`. - v::key('email', v::email())->setName('Email')->check($input); -} catch (ValidationException $exception) { - echo $exception->getMessage() . PHP_EOL; -} +// This is a trick thing: the call to `setName()` here seems to be the one +// from the `Key` rule but it's actually from the `Validator`. +exceptionMessage(static fn() => v::key('email', v::email())->setName('Email')->check($input)); -try { - v::key('email', v::email())->check($input); -} catch (ValidationException $exception) { - echo $exception->getMessage() . PHP_EOL; -} +exceptionMessage(static fn() => v::key('email', v::email())->check($input)); ?> --EXPECT-- Email must be valid email diff --git a/tests/integration/translator-assert.phpt b/tests/integration/translator-assert.phpt index f37c876c0..2085e1a72 100644 --- a/tests/integration/translator-assert.phpt +++ b/tests/integration/translator-assert.phpt @@ -7,7 +7,6 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\NestedValidationException; use Respect\Validation\Factory; use Respect\Validation\Validator; @@ -25,11 +24,7 @@ Factory::setDefaultInstance( }) ); -try { - Validator::stringType()->length(2, 15)->assert(0); -} catch (NestedValidationException $exception) { - echo $exception->getFullMessage(); -} +exceptionFullMessage(static fn() => Validator::stringType()->length(2, 15)->assert(0)); ?> --EXPECT-- - Todas as regras requeridas devem passar para 0 diff --git a/tests/integration/translator-check.phpt b/tests/integration/translator-check.phpt index 9547e6ed6..0c90c2868 100644 --- a/tests/integration/translator-check.phpt +++ b/tests/integration/translator-check.phpt @@ -7,7 +7,6 @@ declare(strict_types=1); require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\ValidationException; use Respect\Validation\Factory; use Respect\Validation\Validator; @@ -20,11 +19,7 @@ Factory::setDefaultInstance( }) ); -try { - Validator::stringType()->length(2, 15)->check(0); -} catch (ValidationException $exception) { - echo $exception->getMessage(); -} +exceptionMessage(static fn() => Validator::stringType()->length(2, 15)->check(0)); ?> --EXPECT-- 0 deve ser do tipo string diff --git a/tests/library/DataProvider/UndefinedProvider.php b/tests/library/DataProvider/UndefinedProvider.php index 3aca0f6e3..51496cd8e 100644 --- a/tests/library/DataProvider/UndefinedProvider.php +++ b/tests/library/DataProvider/UndefinedProvider.php @@ -21,7 +21,7 @@ trait UndefinedProvider * * @return mixed[][] */ - public function providerForUndefined(): array + public static function providerForUndefined(): array { return [ [null], @@ -34,7 +34,7 @@ public function providerForUndefined(): array * * @return mixed[][] */ - public function providerForNotUndefined(): array + public static function providerForNotUndefined(): array { return [ [0], diff --git a/tests/library/RuleTestCase.php b/tests/library/RuleTestCase.php index 1153ac91d..bdd951394 100644 --- a/tests/library/RuleTestCase.php +++ b/tests/library/RuleTestCase.php @@ -9,11 +9,10 @@ namespace Respect\Validation\Test; -use Respect\Validation\Exceptions\ValidationException; -use Respect\Validation\Message\Formatter; -use Respect\Validation\Message\Stringifier\KeepOriginalStringName; use Respect\Validation\Validatable; +use function implode; +use function ltrim; use function realpath; use function Respect\Stringifier\stringify; use function sprintf; @@ -41,7 +40,7 @@ abstract class RuleTestCase extends TestCase * * @return mixed[][] */ - abstract public function providerForValidInput(): array; + abstract public static function providerForValidInput(): array; /** * Data providers for invalid results. @@ -53,67 +52,7 @@ abstract public function providerForValidInput(): array; * * @return mixed[][] */ - abstract public function providerForInvalidInput(): array; - - /** - * Returns the directory used to store test fixtures. - */ - public function getFixtureDirectory(): string - { - return (string) realpath(__DIR__ . '/../fixtures'); - } - - /** - * Create a mock of a Validatable. - * - * @api - */ - public function createValidatableMock(bool $expectedResult, string $mockClassName = ''): Validatable - { - $validatableMocked = $this->getMockBuilder(Validatable::class) - ->disableOriginalConstructor() - ->setMockClassName($mockClassName) - ->getMock(); - - $validatableMocked - ->expects(self::any()) - ->method('validate') - ->willReturn($expectedResult); - - if ($expectedResult) { - $validatableMocked - ->expects(self::any()) - ->method('check'); - $validatableMocked - ->expects(self::any()) - ->method('assert'); - } else { - $checkException = new ValidationException( - 'validatable', - 'input', - [], - new Formatter('strval', new KeepOriginalStringName()) - ); - $checkException->updateTemplate(sprintf('Exception for %s:check() method', $mockClassName)); - $validatableMocked - ->expects(self::any()) - ->method('check') - ->willThrowException($checkException); - $assertException = new ValidationException( - 'validatable', - 'input', - [], - new Formatter('strval', new KeepOriginalStringName()) - ); - $assertException->updateTemplate(sprintf('Exception for %s:assert() method', $mockClassName)); - $validatableMocked - ->expects(self::any()) - ->method('assert') - ->willThrowException($assertException); - } - - return $validatableMocked; - } + abstract public static function providerForInvalidInput(): array; /** * @test @@ -139,6 +78,19 @@ public function shouldValidateInvalidInput(Validatable $validator, $input): void self::assertInvalidInput($validator, $input); } + /** + * Returns the directory used to store test fixtures. + */ + public static function fixture(?string $filename = null): string + { + $parts = [(string) realpath(__DIR__ . '/../fixtures')]; + if ($filename !== null) { + $parts[] = ltrim($filename, '/'); + } + + return implode('/', $parts); + } + /** * @param mixed $input */ diff --git a/tests/library/Rules/Envelop.php b/tests/library/Rules/Envelop.php new file mode 100644 index 000000000..944ac925f --- /dev/null +++ b/tests/library/Rules/Envelop.php @@ -0,0 +1,16 @@ + + * SPDX-License-Identifier: MIT + */ + +declare(strict_types=1); + +namespace Respect\Validation\Test\Rules; + +use Respect\Validation\Rules\AbstractEnvelope; + +final class Envelop extends AbstractEnvelope +{ +} diff --git a/tests/library/Stubs/StreamStub.php b/tests/library/Stubs/StreamStub.php new file mode 100644 index 000000000..b5cda16c5 --- /dev/null +++ b/tests/library/Stubs/StreamStub.php @@ -0,0 +1,138 @@ + + * SPDX-License-Identifier: MIT + */ + +declare(strict_types=1); + +namespace Respect\Validation\Test\Stubs; + +use Psr\Http\Message\StreamInterface; + +use const SEEK_SET; + +final class StreamStub implements StreamInterface +{ + private bool $isReadable = true; + + private bool $isWritable = true; + + private ?int $size = null; + + public static function create(): self + { + return new self(); + } + + public static function createUnwritable(): self + { + $stream = new self(); + $stream->isWritable = false; + + return $stream; + } + + public static function createUnreadable(): self + { + $stream = new self(); + $stream->isReadable = false; + + return $stream; + } + + public static function createWithSize(int $size): self + { + $stream = new self(); + $stream->size = $size; + + return $stream; + } + + public function close(): void + { + } + + /** + * {@inheritDoc} + */ + public function detach() + { + return null; + } + + public function getSize(): ?int + { + return $this->size; + } + + public function tell(): int + { + return 0; + } + + public function eof(): bool + { + return true; + } + + public function isSeekable(): bool + { + return false; + } + + /** + * {@inheritDoc} + */ + public function seek($offset, $whence = SEEK_SET): void + { + } + + public function rewind(): void + { + } + + public function isWritable(): bool + { + return $this->isWritable; + } + + /** + * {@inheritDoc} + */ + public function write($string): int + { + return 0; + } + + public function isReadable(): bool + { + return $this->isReadable; + } + + /** + * {@inheritDoc} + */ + public function read($length): string + { + return ''; + } + + public function getContents(): string + { + return ''; + } + + /** + * {@inheritDoc} + */ + public function getMetadata($key = null): void + { + } + + public function __toString(): string + { + return ''; + } +} diff --git a/tests/library/Stubs/UploadedFileStub.php b/tests/library/Stubs/UploadedFileStub.php new file mode 100644 index 000000000..cdb3586ab --- /dev/null +++ b/tests/library/Stubs/UploadedFileStub.php @@ -0,0 +1,65 @@ + + * SPDX-License-Identifier: MIT + */ + +declare(strict_types=1); + +namespace Respect\Validation\Test\Stubs; + +use Psr\Http\Message\StreamInterface; +use Psr\Http\Message\UploadedFileInterface; + +use const UPLOAD_ERR_OK; + +final class UploadedFileStub implements UploadedFileInterface +{ + private ?int $size = null; + + public static function create(): self + { + return new self(); + } + + public static function createWithSize(int $size): self + { + $stub = new self(); + $stub->size = $size; + + return $stub; + } + + public function getStream(): StreamInterface + { + return StreamStub::create(); + } + + /** + * {@inheritDoc} + */ + public function moveTo($targetPath): void + { + } + + public function getSize(): ?int + { + return $this->size; + } + + public function getError(): int + { + return UPLOAD_ERR_OK; + } + + public function getClientFilename(): ?string + { + return null; + } + + public function getClientMediaType(): ?string + { + return null; + } +} diff --git a/tests/library/Stubs/WithMethods.php b/tests/library/Stubs/WithMethods.php new file mode 100644 index 000000000..ea76c9912 --- /dev/null +++ b/tests/library/Stubs/WithMethods.php @@ -0,0 +1,21 @@ + + * SPDX-License-Identifier: MIT + */ + +declare(strict_types=1); + +namespace Respect\Validation\Test\Stubs; + +final class WithMethods +{ + public function publicMethod(): void + { + } + + public static function publicStaticMethod(): void + { + } +} diff --git a/tests/library/Stubs/WithProperties.php b/tests/library/Stubs/WithProperties.php new file mode 100644 index 000000000..25a9e855e --- /dev/null +++ b/tests/library/Stubs/WithProperties.php @@ -0,0 +1,19 @@ + + * SPDX-License-Identifier: MIT + */ + +declare(strict_types=1); + +namespace Respect\Validation\Test\Stubs; + +final class WithProperties +{ + public string $public = 'public'; + + protected string $protected = 'protected'; + + private string $private = 'private'; // @phpstan-ignore-line +} diff --git a/tests/library/Stubs/WithUninitialized.php b/tests/library/Stubs/WithUninitialized.php new file mode 100644 index 000000000..15ab30c1d --- /dev/null +++ b/tests/library/Stubs/WithUninitialized.php @@ -0,0 +1,17 @@ + + * SPDX-License-Identifier: MIT + */ + +declare(strict_types=1); + +namespace Respect\Validation\Test\Stubs; + +final class WithUninitialized +{ + public string $initialized = 'foo'; + + public string $uninitialized; +} diff --git a/tests/unit/Exceptions/CheckExceptionsTest.php b/tests/unit/Exceptions/CheckExceptionsTest.php index 3701f95e9..4db25c4c0 100644 --- a/tests/unit/Exceptions/CheckExceptionsTest.php +++ b/tests/unit/Exceptions/CheckExceptionsTest.php @@ -27,10 +27,30 @@ */ final class CheckExceptionsTest extends TestCase { + /** + * @dataProvider provideListOfRuleNames + * + * @test + */ + public function ruleHasAnExceptionWhichHasValidApi(string $ruleName): void + { + $exceptionClass = 'Respect\\Validation\\Exceptions\\' . $ruleName . 'Exception'; + self::assertTrue( + class_exists($exceptionClass), + sprintf('Expected exception class to exist: %s.', $ruleName) + ); + + $reflectionClass = new ReflectionClass($exceptionClass); + self::assertTrue( + $reflectionClass->isSubclassOf(ValidationException::class), + 'Every Respect/Validation exception must extend ValidationException.' + ); + } + /** * @return string[][] */ - public function provideListOfRuleNames(): array + public static function provideListOfRuleNames(): array { $rulesDirectory = 'library/Rules'; $rulesDirectoryIterator = new DirectoryIterator($rulesDirectory); @@ -60,24 +80,4 @@ public function provideListOfRuleNames(): array return $ruleNames; } - - /** - * @dataProvider provideListOfRuleNames - * - * @test - */ - public function ruleHasAnExceptionWhichHasValidApi(string $ruleName): void - { - $exceptionClass = 'Respect\\Validation\\Exceptions\\' . $ruleName . 'Exception'; - self::assertTrue( - class_exists($exceptionClass), - sprintf('Expected exception class to exist: %s.', $ruleName) - ); - - $reflectionClass = new ReflectionClass($exceptionClass); - self::assertTrue( - $reflectionClass->isSubclassOf(ValidationException::class), - 'Every Respect/Validation exception must extend ValidationException.' - ); - } } diff --git a/tests/unit/Helpers/CanValidateDateTimeTest.php b/tests/unit/Helpers/CanValidateDateTimeTest.php index f21f4fa49..c707f09cf 100644 --- a/tests/unit/Helpers/CanValidateDateTimeTest.php +++ b/tests/unit/Helpers/CanValidateDateTimeTest.php @@ -22,10 +22,30 @@ final class CanValidateDateTimeTest extends TestCase { use CanValidateDateTime; + /** + * @test + * + * @dataProvider providerForValidDateTime + */ + public function shouldFindWhenValueIsDateTime(string $format, string $value): void + { + self::assertTrue($this->isDateTime($format, $value)); + } + + /** + * @test + * + * @dataProvider providerForInvalidDateTime + */ + public function shouldFindWhenValueIsNotDateTime(string $format, string $value): void + { + self::assertFalse($this->isDateTime($format, $value)); + } + /** * @return mixed[][] */ - public function providerForValidDateTime(): array + public static function providerForValidDateTime(): array { return [ ['Y-m-d', '2009-09-09'], @@ -39,20 +59,10 @@ public function providerForValidDateTime(): array ]; } - /** - * @test - * - * @dataProvider providerForValidDateTime - */ - public function shouldFindWhenValueIsDateTime(string $format, string $value): void - { - self::assertTrue($this->isDateTime($format, $value)); - } - /** * @return mixed[][] */ - public function providerForInvalidDateTime(): array + public static function providerForInvalidDateTime(): array { return [ ['Y-m-d', '0000-01-01'], @@ -63,14 +73,4 @@ public function providerForInvalidDateTime(): array ['Y-m-d H:i:s', '1987-12-31'], ]; } - - /** - * @test - * - * @dataProvider providerForInvalidDateTime - */ - public function shouldFindWhenValueIsNotDateTime(string $format, string $value): void - { - self::assertFalse($this->isDateTime($format, $value)); - } } diff --git a/tests/unit/Rules/AbstractEnvelopeTest.php b/tests/unit/Rules/AbstractEnvelopeTest.php index 2b33f88b2..86ba904ac 100644 --- a/tests/unit/Rules/AbstractEnvelopeTest.php +++ b/tests/unit/Rules/AbstractEnvelopeTest.php @@ -9,8 +9,8 @@ namespace Respect\Validation\Rules; +use Respect\Validation\Test\Rules\Envelop; use Respect\Validation\Test\TestCase; -use Respect\Validation\Validatable; use function array_intersect_key; @@ -28,18 +28,9 @@ final class AbstractEnvelopeTest extends TestCase */ public function itShouldValidateUsingTheInnerRule(): void { - $input = 'value'; - - $innerRule = $this->createMock(Validatable::class); - $innerRule - ->expects(self::once()) - ->method('validate') - ->with($input) - ->willReturn(true); + $rule = new Envelop(new AlwaysValid(), []); - $rule = $this->getMockForAbstractClass(AbstractEnvelope::class, [$innerRule, []]); - - self::assertTrue($rule->validate($input)); + self::assertTrue($rule->validate('something')); } /** @@ -47,33 +38,20 @@ public function itShouldValidateUsingTheInnerRule(): void */ public function itShouldInvalidateUsingTheInnerRule(): void { - $input = 'value'; + $rule = new Envelop(new AlwaysInvalid(), []); - $innerRule = $this->createMock(Validatable::class); - $innerRule - ->expects(self::once()) - ->method('validate') - ->with($input) - ->willReturn(false); - - $rule = $this->getMockForAbstractClass(AbstractEnvelope::class, [$innerRule, []]); - - self::assertFalse($rule->validate($input)); + self::assertFalse($rule->validate('something')); } /** * @test */ - public function itShouldReportErrorUringProperties(): void + public function itShouldReportErrorUsingProperties(): void { $input = 'value'; $parameters = ['foo' => true, 'bar' => false, 'baz' => 42]; - $rule = $this->getMockForAbstractClass( - AbstractEnvelope::class, - [$this->createMock(Validatable::class), $parameters] - ); - + $rule = new Envelop(new AlwaysInvalid(), $parameters); $exception = $rule->reportError($input); self::assertEquals($parameters, array_intersect_key($parameters, $exception->getParams())); diff --git a/tests/unit/Rules/AbstractRuleTest.php b/tests/unit/Rules/AbstractRuleTest.php index 4bfbbb07a..43ae9d557 100644 --- a/tests/unit/Rules/AbstractRuleTest.php +++ b/tests/unit/Rules/AbstractRuleTest.php @@ -23,17 +23,6 @@ */ final class AbstractRuleTest extends TestCase { - /** - * @return bool[][] - */ - public function providerForTrueAndFalse(): array - { - return [ - [true], - [false], - ]; - } - /** * @dataProvider providerForTrueAndFalse * @covers \Respect\Validation\Rules\AbstractRule::__invoke @@ -195,4 +184,15 @@ public function shouldBeAbleToDefineAndRetrivedRuleName(): void self::assertSame($name, $abstractRuleMock->getName()); } + + /** + * @return bool[][] + */ + public static function providerForTrueAndFalse(): array + { + return [ + [true], + [false], + ]; + } } diff --git a/tests/unit/Rules/AllOfTest.php b/tests/unit/Rules/AllOfTest.php index c582631fd..abb1b9f36 100644 --- a/tests/unit/Rules/AllOfTest.php +++ b/tests/unit/Rules/AllOfTest.php @@ -118,7 +118,7 @@ public function validationShouldFailIfAnyRuleFails( /** * @return Validatable[][] */ - public function providerStaticDummyRules(): array + public static function providerStaticDummyRules(): array { $theInvalidOne = new Callback(static function () { return false; diff --git a/tests/unit/Rules/AlnumTest.php b/tests/unit/Rules/AlnumTest.php index d29d07513..d6870ed0e 100644 --- a/tests/unit/Rules/AlnumTest.php +++ b/tests/unit/Rules/AlnumTest.php @@ -30,7 +30,7 @@ final class AlnumTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ [new Alnum(), 'alganet'], @@ -53,7 +53,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ [new Alnum(), ''], diff --git a/tests/unit/Rules/AlphaTest.php b/tests/unit/Rules/AlphaTest.php index 3312eb0e7..bdf72368c 100644 --- a/tests/unit/Rules/AlphaTest.php +++ b/tests/unit/Rules/AlphaTest.php @@ -29,7 +29,7 @@ final class AlphaTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ 'alphabetic' => [new Alpha(), 'alganet'], @@ -43,7 +43,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ 'empty string' => [new Alpha(), ''], diff --git a/tests/unit/Rules/AlwaysInvalidTest.php b/tests/unit/Rules/AlwaysInvalidTest.php index 8d0f11cae..ae051ec44 100644 --- a/tests/unit/Rules/AlwaysInvalidTest.php +++ b/tests/unit/Rules/AlwaysInvalidTest.php @@ -23,10 +23,24 @@ */ final class AlwaysInvalidTest extends TestCase { + /** + * @test + * + * @dataProvider providerForInvalidInput + * + * @param mixed $input + */ + public function itShouldAlwaysBeInvalid($input): void + { + $rule = new AlwaysInvalid(); + + self::assertFalse($rule->validate($input)); + } + /** * @return mixed[][] */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ [0], @@ -40,18 +54,4 @@ public function providerForInvalidInput(): array [['array_full']], ]; } - - /** - * @test - * - * @dataProvider providerForInvalidInput - * - * @param mixed $input - */ - public function itShouldAlwaysBeInvalid($input): void - { - $rule = new AlwaysInvalid(); - - self::assertFalse($rule->validate($input)); - } } diff --git a/tests/unit/Rules/AlwaysValidTest.php b/tests/unit/Rules/AlwaysValidTest.php index 29f06e5aa..e56c04eee 100644 --- a/tests/unit/Rules/AlwaysValidTest.php +++ b/tests/unit/Rules/AlwaysValidTest.php @@ -23,10 +23,24 @@ */ final class AlwaysValidTest extends TestCase { + /** + * @test + * + * @dataProvider providerForValidInput + * + * @param mixed $input + */ + public function itAlwaysBeValid($input): void + { + $rule = new AlwaysValid(); + + self::assertTrue($rule->validate($input)); + } + /** * @return mixed[][] */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ [0], @@ -40,18 +54,4 @@ public function providerForValidInput(): array [['array_full']], ]; } - - /** - * @test - * - * @dataProvider providerForValidInput - * - * @param mixed $input - */ - public function itAlwaysBeValid($input): void - { - $rule = new AlwaysValid(); - - self::assertTrue($rule->validate($input)); - } } diff --git a/tests/unit/Rules/ArrayTypeTest.php b/tests/unit/Rules/ArrayTypeTest.php index d468ef321..863a11d49 100644 --- a/tests/unit/Rules/ArrayTypeTest.php +++ b/tests/unit/Rules/ArrayTypeTest.php @@ -26,7 +26,7 @@ final class ArrayTypeTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new ArrayType(); @@ -39,7 +39,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new ArrayType(); diff --git a/tests/unit/Rules/ArrayValTest.php b/tests/unit/Rules/ArrayValTest.php index 11526bb26..aeed1726b 100644 --- a/tests/unit/Rules/ArrayValTest.php +++ b/tests/unit/Rules/ArrayValTest.php @@ -28,7 +28,7 @@ final class ArrayValTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new ArrayVal(); @@ -43,7 +43,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new ArrayVal(); diff --git a/tests/unit/Rules/AttributeTest.php b/tests/unit/Rules/AttributeTest.php index 8d4c4deed..678d138df 100644 --- a/tests/unit/Rules/AttributeTest.php +++ b/tests/unit/Rules/AttributeTest.php @@ -10,8 +10,8 @@ namespace Respect\Validation\Rules; use Respect\Validation\Test\RuleTestCase; -use Respect\Validation\Validatable; -use stdClass; +use Respect\Validation\Test\Stubs\WithProperties; +use Respect\Validation\Test\Stubs\WithUninitialized; /** * @group rule @@ -36,26 +36,33 @@ final class AttributeTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { - $obj = new stdClass(); - $obj->bar = 'foo'; - - $extraValidator = $this->createMock(Validatable::class); - $extraValidator->method('validate') - ->willReturn(true); - return [ - 'attribute is present without extra validator' => [new Attribute('bar'), $obj], + 'attribute is present without extra validator' => [new Attribute('public'), new WithProperties()], 'private attribute is present without extra validator' => [ - new Attribute('bar'), - $this, + new Attribute('private'), + new WithProperties(), + ], + 'attribute is present with extra validator' => [ + new Attribute('public', new AlwaysValid()), + new WithProperties(), + ], + 'attribute is present but uninitialized' => [ + new Attribute('uninitialized'), + new WithUninitialized(), + ], + 'non mandatory attribute is not present' => [ + new Attribute('nonexistent', null, false), + new WithProperties(), ], - 'attribute is present with extra validator' => [new Attribute('bar', $extraValidator), $obj], - 'non mandatory attribute is not present' => [new Attribute('foo', null, false), $obj], 'non mandatory attribute is not present with extra validator' => [ - new Attribute('foo', $extraValidator, false), - $obj, + new Attribute('nonexistent', new AlwaysValid(), false), + new WithProperties(), + ], + 'attribute is present but uninitialized with extra validator' => [ + new Attribute('uninitialized', new AlwaysValid()), + new WithUninitialized(), ], ]; } @@ -63,22 +70,19 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { - $obj = new stdClass(); - $obj->bar = 'foo'; - - $extraValidatorMock = $this->createMock(Validatable::class); - $extraValidatorMock->method('validate')->willReturn(false); - return [ - 'attribute is absent without extra validator' => [new Attribute('barr'), $obj], + 'attribute is absent without extra validator' => [new Attribute('barr'), new WithProperties()], 'private attribute is not valid based on extra validator' => [ - new Attribute('bar', $extraValidatorMock), - $this, + new Attribute('private', new AlwaysInvalid()), + new WithProperties(), ], 'value provided is an empty string' => [new Attribute('barr'), ''], - 'validator related to attribute does not validate' => [new Attribute('bar', $extraValidatorMock), $obj], + 'validator related to attribute does not validate' => [ + new Attribute('public', new AlwaysInvalid()), + new WithProperties(), + ], ]; } } diff --git a/tests/unit/Rules/Base64Test.php b/tests/unit/Rules/Base64Test.php index b01143ef2..0c7ad3eb3 100644 --- a/tests/unit/Rules/Base64Test.php +++ b/tests/unit/Rules/Base64Test.php @@ -27,7 +27,7 @@ final class Base64Test extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new Base64(); @@ -59,7 +59,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new Base64(); diff --git a/tests/unit/Rules/BaseTest.php b/tests/unit/Rules/BaseTest.php index 0c71b2e37..667949c3a 100644 --- a/tests/unit/Rules/BaseTest.php +++ b/tests/unit/Rules/BaseTest.php @@ -26,7 +26,7 @@ final class BaseTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ [new Base(2), '011010001'], @@ -44,7 +44,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ [new Base(2), ''], diff --git a/tests/unit/Rules/BetweenTest.php b/tests/unit/Rules/BetweenTest.php index 04378d422..f8ae08b7c 100644 --- a/tests/unit/Rules/BetweenTest.php +++ b/tests/unit/Rules/BetweenTest.php @@ -26,10 +26,30 @@ */ final class BetweenTest extends RuleTestCase { + /** + * @test + */ + public function minimumValueShouldNotBeGreaterThanMaximumValue(): void + { + $this->expectExceptionObject(new ComponentException('Minimum cannot be less than or equals to maximum')); + + new Between(10, 5); + } + + /** + * @test + */ + public function minimumValueShouldNotBeEqualsToMaximumValue(): void + { + $this->expectExceptionObject(new ComponentException('Minimum cannot be less than or equals to maximum')); + + new Between(5, 5); + } + /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ [new Between(0, 1), 1], @@ -47,7 +67,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ [new Between(10, 20), ''], @@ -61,24 +81,4 @@ public function providerForInvalidInput(): array [new Between(new CountableStub(1), new CountableStub(10)), 11], ]; } - - /** - * @test - */ - public function minimumValueShouldNotBeGreaterThanMaximumValue(): void - { - $this->expectExceptionObject(new ComponentException('Minimum cannot be less than or equals to maximum')); - - new Between(10, 5); - } - - /** - * @test - */ - public function minimumValueShouldNotBeEqualsToMaximumValue(): void - { - $this->expectExceptionObject(new ComponentException('Minimum cannot be less than or equals to maximum')); - - new Between(5, 5); - } } diff --git a/tests/unit/Rules/BoolTypeTest.php b/tests/unit/Rules/BoolTypeTest.php index 234639ee3..a35c98e7f 100644 --- a/tests/unit/Rules/BoolTypeTest.php +++ b/tests/unit/Rules/BoolTypeTest.php @@ -26,7 +26,7 @@ final class BoolTypeTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new BoolType(); @@ -39,7 +39,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new BoolType(); diff --git a/tests/unit/Rules/BoolValTest.php b/tests/unit/Rules/BoolValTest.php index 9890c4775..f763f4691 100644 --- a/tests/unit/Rules/BoolValTest.php +++ b/tests/unit/Rules/BoolValTest.php @@ -25,7 +25,7 @@ final class BoolValTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new BoolVal(); @@ -45,7 +45,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new BoolVal(); diff --git a/tests/unit/Rules/BsnTest.php b/tests/unit/Rules/BsnTest.php index 2dfc47d3a..fb9faf46d 100644 --- a/tests/unit/Rules/BsnTest.php +++ b/tests/unit/Rules/BsnTest.php @@ -26,7 +26,7 @@ final class BsnTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new Bsn(); @@ -47,7 +47,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new Bsn(); diff --git a/tests/unit/Rules/CallableTypeTest.php b/tests/unit/Rules/CallableTypeTest.php index e630804e7..7b2a6cf26 100644 --- a/tests/unit/Rules/CallableTypeTest.php +++ b/tests/unit/Rules/CallableTypeTest.php @@ -10,6 +10,7 @@ namespace Respect\Validation\Rules; use Respect\Validation\Test\RuleTestCase; +use Respect\Validation\Test\Stubs\WithMethods; use stdClass; use const INF; @@ -27,26 +28,22 @@ final class CallableTypeTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new CallableType(); return [ - [ - $rule, - static function (): void { - }, - ], + [$rule, static fn() => null], [$rule, 'trim'], - [$rule, self::class . '::staticMethod'], - [$rule, [$this, __FUNCTION__]], + [$rule, WithMethods::class . '::publicStaticMethod'], + [$rule, [new WithMethods(), 'publicMethod']], ]; } /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new CallableType(); @@ -58,9 +55,4 @@ public function providerForInvalidInput(): array [$rule, null], ]; } - - public static function staticMethod(): void - { - // This is a static method example - } } diff --git a/tests/unit/Rules/CallbackTest.php b/tests/unit/Rules/CallbackTest.php index 0fb67ddba..d85459d4c 100644 --- a/tests/unit/Rules/CallbackTest.php +++ b/tests/unit/Rules/CallbackTest.php @@ -28,11 +28,11 @@ final class CallbackTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ [new Callback('is_a', 'stdClass'), new stdClass()], - [new Callback([$this, 'sampleCallbackUsedInsideThisTest']), 'test'], + [new Callback([new AlwaysValid(), 'validate']), 'test'], [new Callback('is_string'), 'test'], [ new Callback(static function () { @@ -43,15 +43,10 @@ public function providerForValidInput(): array ]; } - public function sampleCallbackUsedInsideThisTest(): bool - { - return true; - } - /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ [ diff --git a/tests/unit/Rules/CharsetTest.php b/tests/unit/Rules/CharsetTest.php index adf7eb7bd..609ac8e72 100644 --- a/tests/unit/Rules/CharsetTest.php +++ b/tests/unit/Rules/CharsetTest.php @@ -40,7 +40,7 @@ public function itShouldThrowsExceptionWhenCharsetIsNotValid(): void /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ [new Charset('UTF-8'), ''], @@ -57,7 +57,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new Charset('ASCII'); diff --git a/tests/unit/Rules/CnhTest.php b/tests/unit/Rules/CnhTest.php index 340d73c1a..6362d6295 100644 --- a/tests/unit/Rules/CnhTest.php +++ b/tests/unit/Rules/CnhTest.php @@ -29,7 +29,7 @@ final class CnhTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new Cnh(); @@ -64,7 +64,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new Cnh(); diff --git a/tests/unit/Rules/CnpjTest.php b/tests/unit/Rules/CnpjTest.php index e4df63e75..d2000f750 100644 --- a/tests/unit/Rules/CnpjTest.php +++ b/tests/unit/Rules/CnpjTest.php @@ -27,7 +27,7 @@ final class CnpjTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new Cnpj(); @@ -49,7 +49,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new Cnpj(); @@ -75,6 +75,7 @@ public function providerForInvalidInput(): array [$rule, '123'], [$rule, '992999999999929384'], [$rule, '99-010-0.'], + [$rule, null], ]; } } diff --git a/tests/unit/Rules/ConsonantTest.php b/tests/unit/Rules/ConsonantTest.php index 90e6ef753..d4414c0a2 100644 --- a/tests/unit/Rules/ConsonantTest.php +++ b/tests/unit/Rules/ConsonantTest.php @@ -29,7 +29,7 @@ final class ConsonantTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $consonant = new Consonant(); @@ -54,7 +54,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $consonant = new Consonant(); diff --git a/tests/unit/Rules/ContainsAnyTest.php b/tests/unit/Rules/ContainsAnyTest.php index b1327de52..1fdf37dfa 100644 --- a/tests/unit/Rules/ContainsAnyTest.php +++ b/tests/unit/Rules/ContainsAnyTest.php @@ -24,7 +24,7 @@ final class ContainsAnyTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ [new ContainsAny(['Something', 'Else']), 'something else'], @@ -42,7 +42,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ [new ContainsAny(['foo']), ['bar', 'baz']], diff --git a/tests/unit/Rules/ContainsTest.php b/tests/unit/Rules/ContainsTest.php index 1077ae2ee..1d2dbe3be 100644 --- a/tests/unit/Rules/ContainsTest.php +++ b/tests/unit/Rules/ContainsTest.php @@ -27,7 +27,7 @@ final class ContainsTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ [new Contains('foo', false), ['bar', 'foo']], @@ -48,7 +48,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ [new Contains('foo', false), ''], diff --git a/tests/unit/Rules/ControlTest.php b/tests/unit/Rules/ControlTest.php index c5d01838d..519afe363 100644 --- a/tests/unit/Rules/ControlTest.php +++ b/tests/unit/Rules/ControlTest.php @@ -29,7 +29,7 @@ final class ControlTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $sut = new Control(); @@ -46,7 +46,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $sut = new Control(); diff --git a/tests/unit/Rules/CountableTest.php b/tests/unit/Rules/CountableTest.php index 18bf45728..624e4afc6 100644 --- a/tests/unit/Rules/CountableTest.php +++ b/tests/unit/Rules/CountableTest.php @@ -30,7 +30,7 @@ final class CountableTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new Countable(); @@ -44,7 +44,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new Countable(); diff --git a/tests/unit/Rules/CountryCodeTest.php b/tests/unit/Rules/CountryCodeTest.php index 53c41cb09..408ef3244 100644 --- a/tests/unit/Rules/CountryCodeTest.php +++ b/tests/unit/Rules/CountryCodeTest.php @@ -40,7 +40,7 @@ public function itShouldThrowsExceptionWhenInvalidFormat(): void /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ [new CountryCode(CountryCode::ALPHA2), 'BR'], @@ -58,7 +58,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ [new CountryCode(CountryCode::ALPHA2), 'USA'], diff --git a/tests/unit/Rules/CpfTest.php b/tests/unit/Rules/CpfTest.php index b753a1419..4bd834223 100644 --- a/tests/unit/Rules/CpfTest.php +++ b/tests/unit/Rules/CpfTest.php @@ -28,7 +28,7 @@ final class CpfTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new Cpf(); @@ -49,7 +49,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new Cpf(); diff --git a/tests/unit/Rules/CreditCardTest.php b/tests/unit/Rules/CreditCardTest.php index 7e5a50291..f6d8f6afc 100644 --- a/tests/unit/Rules/CreditCardTest.php +++ b/tests/unit/Rules/CreditCardTest.php @@ -42,7 +42,7 @@ public function itShouldThrowExceptionWhenCreditCardBrandIsNotValid(): void /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $general = new CreditCard(); $amex = new CreditCard(CreditCard::AMERICAN_EXPRESS); @@ -79,7 +79,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $general = new CreditCard(); $amex = new CreditCard(CreditCard::AMERICAN_EXPRESS); diff --git a/tests/unit/Rules/CurrencyCodeTest.php b/tests/unit/Rules/CurrencyCodeTest.php index fbb2245c2..2fae9d53e 100644 --- a/tests/unit/Rules/CurrencyCodeTest.php +++ b/tests/unit/Rules/CurrencyCodeTest.php @@ -25,7 +25,7 @@ final class CurrencyCodeTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new CurrencyCode(); @@ -41,7 +41,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new CurrencyCode(); diff --git a/tests/unit/Rules/DateTest.php b/tests/unit/Rules/DateTest.php index 87f8b19b0..bd7ba1038 100644 --- a/tests/unit/Rules/DateTest.php +++ b/tests/unit/Rules/DateTest.php @@ -24,10 +24,45 @@ */ final class DateTest extends RuleTestCase { + /** + * @test + * + * @dataProvider validFormatsProvider + */ + public function shouldThrowAnExceptionWhenFormatIsNotValid(string $format): void + { + $this->expectException(ComponentException::class); + + new Date($format); + } + + /** + * @test + */ + public function shouldPassFormatToParameterToException(): void + { + $format = 'F jS, Y'; + $equals = new Date($format); + $exception = $equals->reportError('input'); + + self::assertSame($format, $exception->getParam('format')); + } + + /** + * @return string[][] + */ + public static function validFormatsProvider(): array + { + return [ + ['Y-m-d H:i:s'], + ['c'], + ]; + } + /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ [new Date(), '2017-12-31'], @@ -41,7 +76,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ [new Date(), 'not-a-date'], @@ -64,39 +99,4 @@ public function providerForInvalidInput(): array [new Date('m'), '99'], ]; } - - /** - * @return string[][] - */ - public function validFormatsProvider(): array - { - return [ - ['Y-m-d H:i:s'], - ['c'], - ]; - } - - /** - * @test - * - * @dataProvider validFormatsProvider - */ - public function shouldThrowAnExceptionWhenFormatIsNotValid(string $format): void - { - $this->expectException(ComponentException::class); - - new Date($format); - } - - /** - * @test - */ - public function shouldPassFormatToParameterToException(): void - { - $format = 'F jS, Y'; - $equals = new Date($format); - $exception = $equals->reportError('input'); - - self::assertSame($format, $exception->getParam('format')); - } } diff --git a/tests/unit/Rules/DateTimeTest.php b/tests/unit/Rules/DateTimeTest.php index bb9a1361c..10f34fb8d 100644 --- a/tests/unit/Rules/DateTimeTest.php +++ b/tests/unit/Rules/DateTimeTest.php @@ -29,10 +29,60 @@ */ final class DateTimeTest extends RuleTestCase { + /** + * @test + */ + public function shouldPassFormatToParameterToException(): void + { + $format = 'F jS, Y'; + $equals = new DateTime($format); + $exception = $equals->reportError('input'); + + self::assertSame($format, $exception->getParam('format')); + } + + /** + * Datetime strings with timezone information are valid independent on the + * system's timezone setting. + * + * @test + * + * @dataProvider providerForDateTimeWithTimezone + */ + public function shouldValidateNoMatterTimezone(string $format, string $input, string $timezone): void + { + $currentTimezone = date_default_timezone_get(); + + date_default_timezone_set($timezone); + + $rule = new DateTime($format); + + self::assertTrue($rule->validate($input)); + + date_default_timezone_set($currentTimezone); + } + + /** + * @return mixed[][] + */ + public static function providerForDateTimeWithTimezone(): array + { + return [ + ['c', '2004-02-12T15:19:21+00:00', 'Europe/Amsterdam'], + ['c', '2004-02-12T15:19:21+00:00', 'UTC'], + ['d/m/Y', '23/05/1987', 'Europe/Amsterdam'], + ['d/m/Y', '23/05/1987', 'UTC'], + ['r', 'Thu, 29 Dec 2005 01:02:03 +0000', 'Europe/Amsterdam'], + ['r', 'Thu, 29 Dec 2005 01:02:03 +0000', 'UTC'], + ['Ym', '202302', 'Europe/Amsterdam'], + ['Ym', '202302', 'UTC'], + ]; + } + /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ [new DateTime(), 'now'], @@ -58,7 +108,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ [new DateTime(), 'not-a-date'], @@ -75,54 +125,4 @@ public function providerForInvalidInput(): array [new DateTime('Y-m-d H:i:s'), '21-3-123:12:01'], ]; } - - /** - * @test - */ - public function shouldPassFormatToParameterToException(): void - { - $format = 'F jS, Y'; - $equals = new DateTime($format); - $exception = $equals->reportError('input'); - - self::assertSame($format, $exception->getParam('format')); - } - - /** - * @return mixed[][] - */ - public function providerForDateTimeWithTimezone(): array - { - return [ - ['c', '2004-02-12T15:19:21+00:00', 'Europe/Amsterdam'], - ['c', '2004-02-12T15:19:21+00:00', 'UTC'], - ['d/m/Y', '23/05/1987', 'Europe/Amsterdam'], - ['d/m/Y', '23/05/1987', 'UTC'], - ['r', 'Thu, 29 Dec 2005 01:02:03 +0000', 'Europe/Amsterdam'], - ['r', 'Thu, 29 Dec 2005 01:02:03 +0000', 'UTC'], - ['Ym', '202302', 'Europe/Amsterdam'], - ['Ym', '202302', 'UTC'], - ]; - } - - /** - * Datetime strings with timezone information are valid independent on the - * system's timezone setting. - * - * @test - * - * @dataProvider providerForDateTimeWithTimezone - */ - public function shouldValidateNoMatterTimezone(string $format, string $input, string $timezone): void - { - $currentTimezone = date_default_timezone_get(); - - date_default_timezone_set($timezone); - - $rule = new DateTime($format); - - self::assertTrue($rule->validate($input)); - - date_default_timezone_set($currentTimezone); - } } diff --git a/tests/unit/Rules/DecimalTest.php b/tests/unit/Rules/DecimalTest.php index 7e7150138..1535c3bc1 100644 --- a/tests/unit/Rules/DecimalTest.php +++ b/tests/unit/Rules/DecimalTest.php @@ -31,7 +31,7 @@ final class DecimalTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ [new Decimal(0), 1], @@ -56,7 +56,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ [new Decimal(1), '1.50'], diff --git a/tests/unit/Rules/DigitTest.php b/tests/unit/Rules/DigitTest.php index 00ebaabfa..45a2c77ea 100644 --- a/tests/unit/Rules/DigitTest.php +++ b/tests/unit/Rules/DigitTest.php @@ -28,7 +28,7 @@ final class DigitTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ 'positive integer' => [new Digit(), 165], @@ -47,7 +47,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ 'empty' => [new Digit(), ''], diff --git a/tests/unit/Rules/DirectoryTest.php b/tests/unit/Rules/DirectoryTest.php index 1b17a743d..2e7836a59 100644 --- a/tests/unit/Rules/DirectoryTest.php +++ b/tests/unit/Rules/DirectoryTest.php @@ -30,7 +30,7 @@ final class DirectoryTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new Directory(); @@ -44,7 +44,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new Directory(); diff --git a/tests/unit/Rules/DomainTest.php b/tests/unit/Rules/DomainTest.php index 5f6563cea..fc22cf4c3 100644 --- a/tests/unit/Rules/DomainTest.php +++ b/tests/unit/Rules/DomainTest.php @@ -28,7 +28,7 @@ final class DomainTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ [new Domain(false), '111111111111domain.local'], @@ -46,7 +46,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ [new Domain(), null], diff --git a/tests/unit/Rules/EachTest.php b/tests/unit/Rules/EachTest.php index e94ea523b..e22edb22e 100644 --- a/tests/unit/Rules/EachTest.php +++ b/tests/unit/Rules/EachTest.php @@ -30,40 +30,6 @@ */ final class EachTest extends RuleTestCase { - /** - * {@inheritDoc} - */ - public function providerForValidInput(): array - { - $rule = new Each($this->createValidatableMock(true)); - - return [ - [$rule, []], - [$rule, [1, 2, 3, 4, 5]], - [$rule, $this->createTraversableInput(1, 5)], - [$rule, $this->createStdClassInput(1, 5)], - ]; - } - - /** - * {@inheritDoc} - */ - public function providerForInvalidInput(): array - { - $rule = new Each($this->createValidatableMock(false)); - - return [ - [$rule, 123], - [$rule, ''], - [$rule, null], - [$rule, false], - [$rule, ['', 2, 3, 4, 5]], - [$rule, ['a', 2, 3, 4, 5]], - [$rule, $this->createTraversableInput(1, 5)], - [$rule, $this->createStdClassInput(1, 5)], - ]; - } - /** * @test */ @@ -114,10 +80,44 @@ public function itShouldNotOverrideMessages(): void } } + /** + * {@inheritDoc} + */ + public static function providerForValidInput(): array + { + $rule = new Each(new AlwaysValid()); + + return [ + [$rule, []], + [$rule, [1, 2, 3, 4, 5]], + [$rule, self::createTraversableInput(1, 5)], + [$rule, self::createStdClassInput(1, 5)], + ]; + } + + /** + * {@inheritDoc} + */ + public static function providerForInvalidInput(): array + { + $rule = new Each(new AlwaysInvalid()); + + return [ + [$rule, 123], + [$rule, ''], + [$rule, null], + [$rule, false], + [$rule, ['', 2, 3, 4, 5]], + [$rule, ['a', 2, 3, 4, 5]], + [$rule, self::createTraversableInput(1, 5)], + [$rule, self::createStdClassInput(1, 5)], + ]; + } + /** * @return Traversable */ - private function createTraversableInput(int $firstValue, int $lastValue): Traversable + private static function createTraversableInput(int $firstValue, int $lastValue): Traversable { /** @var SplStack */ $input = new SplStack(); @@ -128,7 +128,7 @@ private function createTraversableInput(int $firstValue, int $lastValue): Traver return $input; } - private function createStdClassInput(int $firstValue, int $lastValue): stdClass + private static function createStdClassInput(int $firstValue, int $lastValue): stdClass { $input = []; foreach (range($firstValue, $lastValue) as $value) { diff --git a/tests/unit/Rules/EmailTest.php b/tests/unit/Rules/EmailTest.php index 7936c4c7b..6f2fbedab 100644 --- a/tests/unit/Rules/EmailTest.php +++ b/tests/unit/Rules/EmailTest.php @@ -54,9 +54,9 @@ public function shouldUseEmailValidatorToValidate(): void /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { - $sut = $this->createSutWithoutEmailValidator(); + $sut = self::sut(); return [ [$sut, 'test@test.com'], @@ -69,9 +69,9 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { - $sut = $this->createSutWithoutEmailValidator(); + $sut = self::sut(); return [ [$sut, ''], @@ -94,7 +94,7 @@ public function providerForInvalidInput(): array /** * @throws ReflectionException */ - private function createSutWithoutEmailValidator(): Email + private static function sut(): Email { $rule = new Email(); diff --git a/tests/unit/Rules/EndsWithTest.php b/tests/unit/Rules/EndsWithTest.php index 1cb7ebea0..d967d8f47 100644 --- a/tests/unit/Rules/EndsWithTest.php +++ b/tests/unit/Rules/EndsWithTest.php @@ -26,7 +26,7 @@ final class EndsWithTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ [new EndsWith('foo'), ['bar', 'foo']], @@ -42,7 +42,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ [new EndsWith('foo'), ''], diff --git a/tests/unit/Rules/EqualsTest.php b/tests/unit/Rules/EqualsTest.php index 36f3a3ab1..f07f56c44 100644 --- a/tests/unit/Rules/EqualsTest.php +++ b/tests/unit/Rules/EqualsTest.php @@ -22,10 +22,22 @@ */ final class EqualsTest extends RuleTestCase { + /** + * @test + */ + public function shouldPassCompareToParameterToException(): void + { + $compareTo = new stdClass(); + $equals = new Equals($compareTo); + $exception = $equals->reportError('input'); + + self::assertSame($compareTo, $exception->getParam('compareTo')); + } + /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ [new Equals('foo'), 'foo'], @@ -39,23 +51,11 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ [new Equals('foo'), ''], [new Equals('foo'), 'bar'], ]; } - - /** - * @test - */ - public function shouldPassCompareToParameterToException(): void - { - $compareTo = new stdClass(); - $equals = new Equals($compareTo); - $exception = $equals->reportError('input'); - - self::assertSame($compareTo, $exception->getParam('compareTo')); - } } diff --git a/tests/unit/Rules/EquivalentTest.php b/tests/unit/Rules/EquivalentTest.php index 7c7135887..0ea5c2db8 100644 --- a/tests/unit/Rules/EquivalentTest.php +++ b/tests/unit/Rules/EquivalentTest.php @@ -24,7 +24,7 @@ final class EquivalentTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ [new Equivalent(1), true], @@ -38,7 +38,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ [new Equivalent(1), false], diff --git a/tests/unit/Rules/EvenTest.php b/tests/unit/Rules/EvenTest.php index fbd6405bd..206276787 100644 --- a/tests/unit/Rules/EvenTest.php +++ b/tests/unit/Rules/EvenTest.php @@ -28,7 +28,7 @@ final class EvenTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ [new Even(), 2], @@ -41,7 +41,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ [new Even(), ''], diff --git a/tests/unit/Rules/ExecutableTest.php b/tests/unit/Rules/ExecutableTest.php index 9212c9a60..406f78a29 100644 --- a/tests/unit/Rules/ExecutableTest.php +++ b/tests/unit/Rules/ExecutableTest.php @@ -28,7 +28,7 @@ final class ExecutableTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new Executable(); @@ -42,7 +42,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new Executable(); diff --git a/tests/unit/Rules/ExistsTest.php b/tests/unit/Rules/ExistsTest.php index 7534988ec..2be3a6cdd 100644 --- a/tests/unit/Rules/ExistsTest.php +++ b/tests/unit/Rules/ExistsTest.php @@ -28,7 +28,7 @@ final class ExistsTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new Exists(); @@ -42,7 +42,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new Exists(); diff --git a/tests/unit/Rules/ExtensionTest.php b/tests/unit/Rules/ExtensionTest.php index b920334fe..eb2123549 100644 --- a/tests/unit/Rules/ExtensionTest.php +++ b/tests/unit/Rules/ExtensionTest.php @@ -25,7 +25,7 @@ final class ExtensionTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ 'txt' => [new Extension('txt'), 'filename.txt'], @@ -33,16 +33,16 @@ public function providerForValidInput(): array 'inc' => [new Extension('inc'), 'filename.inc'], 'bz2' => [new Extension('bz2'), 'filename.foo.bar.bz2'], 'php' => [new Extension('php'), new SplFileInfo(__FILE__)], - 'png' => [new Extension('png'), $this->getFixtureDirectory() . 'valid-image.png'], - 'gif' => [new Extension('gif'), $this->getFixtureDirectory() . 'valid-image.gif'], - 'file-invalid' => [new Extension('png'), $this->getFixtureDirectory() . 'invalid-image.png'], + 'png' => [new Extension('png'), self::fixture('valid-image.png')], + 'gif' => [new Extension('gif'), self::fixture('valid-image.gif')], + 'file-invalid' => [new Extension('png'), self::fixture('invalid-image.png')], ]; } /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ 'jpg' => [new Extension('jpg'), 'filename.txt'], diff --git a/tests/unit/Rules/FactorTest.php b/tests/unit/Rules/FactorTest.php index 79771f548..78a1c37fd 100644 --- a/tests/unit/Rules/FactorTest.php +++ b/tests/unit/Rules/FactorTest.php @@ -34,7 +34,7 @@ final class FactorTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ '1 is factor 1' => [new Factor(1), 1], @@ -69,7 +69,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ '3 is not factor 2' => [new Factor(3), 2], diff --git a/tests/unit/Rules/FalseValTest.php b/tests/unit/Rules/FalseValTest.php index 1cf71ba48..fa08b9c19 100644 --- a/tests/unit/Rules/FalseValTest.php +++ b/tests/unit/Rules/FalseValTest.php @@ -30,7 +30,7 @@ final class FalseValTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $sut = new FalseVal(); @@ -54,7 +54,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $sut = new FalseVal(); diff --git a/tests/unit/Rules/FibonacciTest.php b/tests/unit/Rules/FibonacciTest.php index ad877a13d..089ef6260 100644 --- a/tests/unit/Rules/FibonacciTest.php +++ b/tests/unit/Rules/FibonacciTest.php @@ -25,7 +25,7 @@ final class FibonacciTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new Fibonacci(); @@ -49,7 +49,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new Fibonacci(); diff --git a/tests/unit/Rules/FileTest.php b/tests/unit/Rules/FileTest.php index 98037e035..59cf1d634 100644 --- a/tests/unit/Rules/FileTest.php +++ b/tests/unit/Rules/FileTest.php @@ -30,21 +30,21 @@ final class FileTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $sut = new File(); return [ 'filename' => [$sut, __FILE__], - 'SplFileInfo' => [$sut, new SplFileInfo($this->getFixtureDirectory() . '/valid-image.png')], - 'SplFileObject' => [$sut, new SplFileObject($this->getFixtureDirectory() . '/invalid-image.png')], + 'SplFileInfo' => [$sut, new SplFileInfo(self::fixture('valid-image.png'))], + 'SplFileObject' => [$sut, new SplFileObject(self::fixture('invalid-image.png'))], ]; } /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $sut = new File(); diff --git a/tests/unit/Rules/FilterVarTest.php b/tests/unit/Rules/FilterVarTest.php index 614d84e05..b5a22e6e7 100644 --- a/tests/unit/Rules/FilterVarTest.php +++ b/tests/unit/Rules/FilterVarTest.php @@ -47,7 +47,7 @@ public function itShouldThrowsExceptionWhenFilterIsNotValid(): void /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ [new FilterVar(FILTER_VALIDATE_INT), '12345'], @@ -63,7 +63,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ [new FilterVar(FILTER_VALIDATE_INT), 1.4], diff --git a/tests/unit/Rules/FiniteTest.php b/tests/unit/Rules/FiniteTest.php index 3346c9fe0..84414ca99 100644 --- a/tests/unit/Rules/FiniteTest.php +++ b/tests/unit/Rules/FiniteTest.php @@ -31,7 +31,7 @@ final class FiniteTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $sut = new Finite(); @@ -49,7 +49,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $sut = new Finite(); diff --git a/tests/unit/Rules/FloatTypeTest.php b/tests/unit/Rules/FloatTypeTest.php index cc88434db..206cd689d 100644 --- a/tests/unit/Rules/FloatTypeTest.php +++ b/tests/unit/Rules/FloatTypeTest.php @@ -26,7 +26,7 @@ final class FloatTypeTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new FloatType(); @@ -44,7 +44,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new FloatType(); diff --git a/tests/unit/Rules/FloatValTest.php b/tests/unit/Rules/FloatValTest.php index af7bfbd4f..18569b901 100644 --- a/tests/unit/Rules/FloatValTest.php +++ b/tests/unit/Rules/FloatValTest.php @@ -26,7 +26,7 @@ final class FloatValTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new FloatVal(); @@ -46,7 +46,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new FloatVal(); diff --git a/tests/unit/Rules/GraphTest.php b/tests/unit/Rules/GraphTest.php index fa4bd063f..661ff9b52 100644 --- a/tests/unit/Rules/GraphTest.php +++ b/tests/unit/Rules/GraphTest.php @@ -28,7 +28,7 @@ final class GraphTest extends RuleTestCase /** * @inheritDoc */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $graph = new Graph(); @@ -50,7 +50,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $graph = new Graph(); diff --git a/tests/unit/Rules/GreaterThanTest.php b/tests/unit/Rules/GreaterThanTest.php index 527452a2a..2f91f07ed 100644 --- a/tests/unit/Rules/GreaterThanTest.php +++ b/tests/unit/Rules/GreaterThanTest.php @@ -26,7 +26,7 @@ final class GreaterThanTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ [new GreaterThan(10), 11], @@ -40,7 +40,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ [new GreaterThan(10), 9], diff --git a/tests/unit/Rules/HexRgbColorTest.php b/tests/unit/Rules/HexRgbColorTest.php index f10692f7b..1930df065 100644 --- a/tests/unit/Rules/HexRgbColorTest.php +++ b/tests/unit/Rules/HexRgbColorTest.php @@ -26,7 +26,7 @@ final class HexRgbColorTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $sut = new HexRgbColor(); @@ -48,7 +48,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $sut = new HexRgbColor(); diff --git a/tests/unit/Rules/IbanTest.php b/tests/unit/Rules/IbanTest.php index 7456f8652..3fb392d45 100644 --- a/tests/unit/Rules/IbanTest.php +++ b/tests/unit/Rules/IbanTest.php @@ -26,7 +26,7 @@ final class IbanTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $sut = new Iban(); @@ -48,7 +48,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $sut = new Iban(); diff --git a/tests/unit/Rules/IdenticalTest.php b/tests/unit/Rules/IdenticalTest.php index d4938bafe..19ef96e82 100644 --- a/tests/unit/Rules/IdenticalTest.php +++ b/tests/unit/Rules/IdenticalTest.php @@ -21,10 +21,22 @@ */ final class IdenticalTest extends RuleTestCase { + /** + * @test + */ + public function shouldPassCompareToParameterToException(): void + { + $compareTo = new stdClass(); + $rule = new Identical($compareTo); + $exception = $rule->reportError('input'); + + self::assertSame($compareTo, $exception->getParam('compareTo')); + } + /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $object = new stdClass(); @@ -40,7 +52,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ [new Identical(42), '42'], @@ -50,16 +62,4 @@ public function providerForInvalidInput(): array [new Identical(10), 10.0], ]; } - - /** - * @test - */ - public function shouldPassCompareToParameterToException(): void - { - $compareTo = new stdClass(); - $rule = new Identical($compareTo); - $exception = $rule->reportError('input'); - - self::assertSame($compareTo, $exception->getParam('compareTo')); - } } diff --git a/tests/unit/Rules/ImageTest.php b/tests/unit/Rules/ImageTest.php index 151b73981..b8b5a2894 100644 --- a/tests/unit/Rules/ImageTest.php +++ b/tests/unit/Rules/ImageTest.php @@ -25,54 +25,54 @@ */ final class ImageTest extends RuleTestCase { + /** + * @test + */ + public function shouldValidateWithDefinedInstanceOfFileInfo(): void + { + $input = self::fixture('valid-image.gif'); + + $finfo = $this->createMock(finfo::class); + $finfo + ->expects(self::once()) + ->method('file') + ->with($input) + ->will(self::returnValue('image/gif')); + + $rule = new Image($finfo); + + self::assertTrue($rule->validate($input)); + } + /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new Image(); return [ - [$rule, $this->getFixtureDirectory() . '/valid-image.gif'], - [$rule, $this->getFixtureDirectory() . '/valid-image.jpg'], - [$rule, $this->getFixtureDirectory() . '/valid-image.png'], - [$rule, new SplFileInfo($this->getFixtureDirectory() . '/valid-image.gif')], - [$rule, new SplFileInfo($this->getFixtureDirectory() . '/valid-image.jpg')], - [$rule, new SplFileObject($this->getFixtureDirectory() . '/valid-image.png')], + [$rule, self::fixture('valid-image.gif')], + [$rule, self::fixture('valid-image.jpg')], + [$rule, self::fixture('valid-image.png')], + [$rule, new SplFileInfo(self::fixture('valid-image.gif'))], + [$rule, new SplFileInfo(self::fixture('valid-image.jpg'))], + [$rule, new SplFileObject(self::fixture('valid-image.png'))], ]; } /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new Image(); return [ - [$rule, $this->getFixtureDirectory() . '/invalid-image.png'], + [$rule, self::fixture('invalid-image.png')], [$rule, 'asdf'], [$rule, 1], [$rule, true], ]; } - - /** - * @test - */ - public function shouldValidateWithDefinedInstanceOfFileInfo(): void - { - $input = $this->getFixtureDirectory() . '/valid-image.gif'; - - $finfo = $this->createMock(finfo::class); - $finfo - ->expects(self::once()) - ->method('file') - ->with($input) - ->will(self::returnValue('image/gif')); - - $rule = new Image($finfo); - - self::assertTrue($rule->validate($input)); - } } diff --git a/tests/unit/Rules/ImeiTest.php b/tests/unit/Rules/ImeiTest.php index da821597c..c4589d0e9 100644 --- a/tests/unit/Rules/ImeiTest.php +++ b/tests/unit/Rules/ImeiTest.php @@ -26,7 +26,7 @@ final class ImeiTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new Imei(); @@ -45,7 +45,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new Imei(); diff --git a/tests/unit/Rules/InTest.php b/tests/unit/Rules/InTest.php index b98a8a8b5..27511aa38 100644 --- a/tests/unit/Rules/InTest.php +++ b/tests/unit/Rules/InTest.php @@ -26,7 +26,7 @@ final class InTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ [new In(''), ''], @@ -45,7 +45,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ [new In('0'), null], diff --git a/tests/unit/Rules/InfiniteTest.php b/tests/unit/Rules/InfiniteTest.php index ef1232a52..8cb8a55a7 100644 --- a/tests/unit/Rules/InfiniteTest.php +++ b/tests/unit/Rules/InfiniteTest.php @@ -29,7 +29,7 @@ final class InfiniteTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new Infinite(); @@ -42,7 +42,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new Infinite(); diff --git a/tests/unit/Rules/InstanceTest.php b/tests/unit/Rules/InstanceTest.php index 4deaba458..c695b9ef9 100644 --- a/tests/unit/Rules/InstanceTest.php +++ b/tests/unit/Rules/InstanceTest.php @@ -32,7 +32,7 @@ final class InstanceTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ [new Instance(DateTime::class), new DateTime()], @@ -44,7 +44,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ [new Instance(DateTime::class), ''], diff --git a/tests/unit/Rules/IntTypeTest.php b/tests/unit/Rules/IntTypeTest.php index 646ae05cb..c378179af 100644 --- a/tests/unit/Rules/IntTypeTest.php +++ b/tests/unit/Rules/IntTypeTest.php @@ -26,7 +26,7 @@ final class IntTypeTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new IntType(); @@ -41,7 +41,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new IntType(); diff --git a/tests/unit/Rules/IntValTest.php b/tests/unit/Rules/IntValTest.php index 5229f4835..833311706 100644 --- a/tests/unit/Rules/IntValTest.php +++ b/tests/unit/Rules/IntValTest.php @@ -29,7 +29,7 @@ final class IntValTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new IntVal(); @@ -54,7 +54,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new IntVal(); diff --git a/tests/unit/Rules/IpTest.php b/tests/unit/Rules/IpTest.php index d78cc8cf7..ac3b368b7 100644 --- a/tests/unit/Rules/IpTest.php +++ b/tests/unit/Rules/IpTest.php @@ -30,10 +30,40 @@ */ final class IpTest extends RuleTestCase { + /** + * @test + * + * @dataProvider providerForInvalidRanges + * + * @throws ComponentException + */ + public function invalidRangeShouldRaiseException(string $range): void + { + $this->expectException(ComponentException::class); + + new Ip($range); + } + + /** + * @return string[][] + */ + public static function providerForInvalidRanges(): array + { + return [ + ['192.168'], + ['asd'], + ['192.168.0.0-192.168.0.256'], + ['192.168.0.0-192.168.0.1/4'], + ['192.168.0/1'], + ['192.168.2.0/256.256.256.256'], + ['192.168.2.0/8.256.256.256'], + ]; + } + /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ [new Ip('127.*'), '127.0.0.1'], @@ -61,7 +91,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ [new Ip('127.*'), '192.0.1.0'], @@ -84,36 +114,6 @@ public function providerForInvalidInput(): array ]; } - /** - * @return string[][] - */ - public function providerForInvalidRanges(): array - { - return [ - ['192.168'], - ['asd'], - ['192.168.0.0-192.168.0.256'], - ['192.168.0.0-192.168.0.1/4'], - ['192.168.0/1'], - ['192.168.2.0/256.256.256.256'], - ['192.168.2.0/8.256.256.256'], - ]; - } - - /** - * @test - * - * @dataProvider providerForInvalidRanges - * - * @throws ComponentException - */ - public function invalidRangeShouldRaiseException(string $range): void - { - $this->expectException(ComponentException::class); - - new Ip($range); - } - /** * {@inheritDoc} */ diff --git a/tests/unit/Rules/IsbnTest.php b/tests/unit/Rules/IsbnTest.php index 2e54dfb87..326c20264 100644 --- a/tests/unit/Rules/IsbnTest.php +++ b/tests/unit/Rules/IsbnTest.php @@ -24,7 +24,7 @@ final class IsbnTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $sut = new Isbn(); @@ -42,7 +42,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $sut = new Isbn(); diff --git a/tests/unit/Rules/IterableTypeTest.php b/tests/unit/Rules/IterableTypeTest.php index 1c884381d..e9fe766d1 100644 --- a/tests/unit/Rules/IterableTypeTest.php +++ b/tests/unit/Rules/IterableTypeTest.php @@ -26,7 +26,7 @@ final class IterableTypeTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new IterableType(); @@ -40,7 +40,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new IterableType(); diff --git a/tests/unit/Rules/JsonTest.php b/tests/unit/Rules/JsonTest.php index d5d85ebeb..cc184f5df 100644 --- a/tests/unit/Rules/JsonTest.php +++ b/tests/unit/Rules/JsonTest.php @@ -28,7 +28,7 @@ final class JsonTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $json = new Json(); @@ -48,7 +48,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $json = new Json(); diff --git a/tests/unit/Rules/KeySetTest.php b/tests/unit/Rules/KeySetTest.php index 4e677c88b..f73221817 100644 --- a/tests/unit/Rules/KeySetTest.php +++ b/tests/unit/Rules/KeySetTest.php @@ -221,7 +221,7 @@ public function shouldThrowExceptionInCaseArgumentIsAnythingOtherThanArray($inpu /** * @return mixed[][] */ - public function providerForInvalidArguments(): array + public static function providerForInvalidArguments(): array { return [ [''], diff --git a/tests/unit/Rules/KeyValueTest.php b/tests/unit/Rules/KeyValueTest.php index 86ec61de4..0177b4fc2 100644 --- a/tests/unit/Rules/KeyValueTest.php +++ b/tests/unit/Rules/KeyValueTest.php @@ -24,7 +24,7 @@ final class KeyValueTest extends RuleTestCase /** * {@inheritdoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ 'Equal values' => [new KeyValue('foo', 'equals', 'bar'), ['foo' => 42, 'bar' => 42]], @@ -42,7 +42,7 @@ public function providerForValidInput(): array /** * {@inheritdoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $keyValue = new KeyValue('foo', 'equals', 'bar'); diff --git a/tests/unit/Rules/LanguageCodeTest.php b/tests/unit/Rules/LanguageCodeTest.php index aa5fd3068..d442903aa 100644 --- a/tests/unit/Rules/LanguageCodeTest.php +++ b/tests/unit/Rules/LanguageCodeTest.php @@ -24,10 +24,20 @@ */ final class LanguageCodeTest extends RuleTestCase { + /** + * @test + */ + public function itShouldThrowAnExceptionWhenSetIsInvalid(): void + { + $this->expectExceptionObject(new ComponentException('"foo" is not a valid language set for ISO 639')); + + new LanguageCode('foo'); + } + /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $sutAlpha2 = new LanguageCode(LanguageCode::ALPHA2); $sutAlpha3 = new LanguageCode(LanguageCode::ALPHA3); @@ -47,7 +57,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $sutAlpha2 = new LanguageCode(LanguageCode::ALPHA2); $sutAlpha3 = new LanguageCode(LanguageCode::ALPHA3); @@ -65,14 +75,4 @@ public function providerForInvalidInput(): array 'alpha-3: null' => [$sutAlpha3, ''], ]; } - - /** - * @test - */ - public function itShouldThrowAnExceptionWhenSetIsInvalid(): void - { - $this->expectExceptionObject(new ComponentException('"foo" is not a valid language set for ISO 639')); - - new LanguageCode('foo'); - } } diff --git a/tests/unit/Rules/LeapDateTest.php b/tests/unit/Rules/LeapDateTest.php index 44b2c0a16..27ca10c76 100644 --- a/tests/unit/Rules/LeapDateTest.php +++ b/tests/unit/Rules/LeapDateTest.php @@ -27,7 +27,7 @@ final class LeapDateTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ [new LeapDate('Y-m-d'), '1988-02-29'], @@ -40,7 +40,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ [new LeapDate('Y-m-d'), '1989-02-29'], diff --git a/tests/unit/Rules/LeapYearTest.php b/tests/unit/Rules/LeapYearTest.php index dfe1d37f2..511382cbb 100644 --- a/tests/unit/Rules/LeapYearTest.php +++ b/tests/unit/Rules/LeapYearTest.php @@ -26,7 +26,7 @@ final class LeapYearTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new LeapYear(); @@ -42,7 +42,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new LeapYear(); diff --git a/tests/unit/Rules/LengthTest.php b/tests/unit/Rules/LengthTest.php index c19b436f1..f49f26b8a 100644 --- a/tests/unit/Rules/LengthTest.php +++ b/tests/unit/Rules/LengthTest.php @@ -30,10 +30,21 @@ */ final class LengthTest extends RuleTestCase { + /** + * @test + */ + public function isShouldNotNotAcceptInvalidLengths(): void + { + $this->expectException(ComponentException::class); + $this->expectExceptionMessage('10 cannot be less than 1 for validation'); + + new Length(10, 1); + } + /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ [new Length(1, 15), 'alganet'], @@ -56,7 +67,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ [new Length(1, 15), ''], @@ -72,15 +83,4 @@ public function providerForInvalidInput(): array [new Length(1, 4), 12345], ]; } - - /** - * @test - */ - public function isShouldNotNotAcceptInvalidLengths(): void - { - $this->expectException(ComponentException::class); - $this->expectExceptionMessage('10 cannot be less than 1 for validation'); - - new Length(10, 1); - } } diff --git a/tests/unit/Rules/LessThanTest.php b/tests/unit/Rules/LessThanTest.php index 6d04cfc9c..ce8d32ac1 100644 --- a/tests/unit/Rules/LessThanTest.php +++ b/tests/unit/Rules/LessThanTest.php @@ -26,7 +26,7 @@ final class LessThanTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ [new LessThan(10), 9], @@ -40,7 +40,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ [new LessThan(10), 10], diff --git a/tests/unit/Rules/LowercaseTest.php b/tests/unit/Rules/LowercaseTest.php index e99d4ca66..0cbc07222 100644 --- a/tests/unit/Rules/LowercaseTest.php +++ b/tests/unit/Rules/LowercaseTest.php @@ -27,7 +27,7 @@ final class LowercaseTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new Lowercase(); @@ -48,7 +48,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new Lowercase(); diff --git a/tests/unit/Rules/LuhnTest.php b/tests/unit/Rules/LuhnTest.php index 1411b1875..6e0e2b486 100644 --- a/tests/unit/Rules/LuhnTest.php +++ b/tests/unit/Rules/LuhnTest.php @@ -26,7 +26,7 @@ final class LuhnTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new Luhn(); @@ -40,7 +40,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new Luhn(); diff --git a/tests/unit/Rules/MacAddressTest.php b/tests/unit/Rules/MacAddressTest.php index 379501903..c2d241fda 100644 --- a/tests/unit/Rules/MacAddressTest.php +++ b/tests/unit/Rules/MacAddressTest.php @@ -31,7 +31,7 @@ final class MacAddressTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $sut = new MacAddress(); @@ -46,7 +46,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $sut = new MacAddress(); diff --git a/tests/unit/Rules/MaxAgeTest.php b/tests/unit/Rules/MaxAgeTest.php index 3293fe864..3155932de 100644 --- a/tests/unit/Rules/MaxAgeTest.php +++ b/tests/unit/Rules/MaxAgeTest.php @@ -31,7 +31,7 @@ final class MaxAgeTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ [new MaxAge(30, 'Y-m-d'), date('Y-m-d', strtotime('30 years ago'))], @@ -44,7 +44,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ [new MaxAge(30), new DateTime('30 years ago')], diff --git a/tests/unit/Rules/MaxTest.php b/tests/unit/Rules/MaxTest.php index 63cc4550f..2b4e8dbd7 100644 --- a/tests/unit/Rules/MaxTest.php +++ b/tests/unit/Rules/MaxTest.php @@ -30,7 +30,7 @@ final class MaxTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ [new Max(10), 9], @@ -46,7 +46,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ [new Max(10), 11], diff --git a/tests/unit/Rules/MimetypeTest.php b/tests/unit/Rules/MimetypeTest.php index 5370e50ea..d1570112e 100644 --- a/tests/unit/Rules/MimetypeTest.php +++ b/tests/unit/Rules/MimetypeTest.php @@ -59,7 +59,7 @@ public function itShouldValidateWithDefinedFinfoInstance(): void /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ 'image/png' => [new Mimetype('image/png'), 'tests/fixtures/valid-image.png'], @@ -74,7 +74,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ 'invalid file' => [new Mimetype('image/png'), 'tests/fixtures/invalid-image.png'], diff --git a/tests/unit/Rules/MinAgeTest.php b/tests/unit/Rules/MinAgeTest.php index 5a5b9b0fe..5d8f2e7b4 100644 --- a/tests/unit/Rules/MinAgeTest.php +++ b/tests/unit/Rules/MinAgeTest.php @@ -33,7 +33,7 @@ final class MinAgeTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ [new MinAge(18, 'Y-m-d'), date('Y-m-d', strtotime('18 years ago'))], @@ -46,7 +46,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ [new MinAge(18), new DateTime('18 years ago')], diff --git a/tests/unit/Rules/MinTest.php b/tests/unit/Rules/MinTest.php index 2d0418fa4..f78a85103 100644 --- a/tests/unit/Rules/MinTest.php +++ b/tests/unit/Rules/MinTest.php @@ -30,7 +30,7 @@ final class MinTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ // From documentation @@ -61,7 +61,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ // From documentation diff --git a/tests/unit/Rules/MultipleTest.php b/tests/unit/Rules/MultipleTest.php index 81aec39eb..c2cdf4629 100644 --- a/tests/unit/Rules/MultipleTest.php +++ b/tests/unit/Rules/MultipleTest.php @@ -26,7 +26,7 @@ final class MultipleTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ [new Multiple(5), 20], @@ -44,7 +44,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ [new Multiple(5), 11], diff --git a/tests/unit/Rules/NegativeTest.php b/tests/unit/Rules/NegativeTest.php index 26952a957..3504b937d 100644 --- a/tests/unit/Rules/NegativeTest.php +++ b/tests/unit/Rules/NegativeTest.php @@ -27,7 +27,7 @@ final class NegativeTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new Negative(); @@ -41,7 +41,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new Negative(); diff --git a/tests/unit/Rules/NfeAccessKeyTest.php b/tests/unit/Rules/NfeAccessKeyTest.php index 8f7fbd85b..b62c3d327 100644 --- a/tests/unit/Rules/NfeAccessKeyTest.php +++ b/tests/unit/Rules/NfeAccessKeyTest.php @@ -26,7 +26,7 @@ final class NfeAccessKeyTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $nfe = new NfeAccessKey(); @@ -38,7 +38,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $nfe = new NfeAccessKey(); diff --git a/tests/unit/Rules/NifTest.php b/tests/unit/Rules/NifTest.php index c69d3e80e..82062b9d7 100644 --- a/tests/unit/Rules/NifTest.php +++ b/tests/unit/Rules/NifTest.php @@ -27,7 +27,7 @@ final class NifTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new Nif(); @@ -59,7 +59,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new Nif(); diff --git a/tests/unit/Rules/NipTest.php b/tests/unit/Rules/NipTest.php index 5e0527d5e..936715035 100644 --- a/tests/unit/Rules/NipTest.php +++ b/tests/unit/Rules/NipTest.php @@ -25,7 +25,7 @@ final class NipTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new Nip(); @@ -39,7 +39,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new Nip(); diff --git a/tests/unit/Rules/NoTest.php b/tests/unit/Rules/NoTest.php index 8992c8c5c..0f3b4e4d0 100644 --- a/tests/unit/Rules/NoTest.php +++ b/tests/unit/Rules/NoTest.php @@ -32,42 +32,41 @@ final class NoTest extends RuleTestCase private $locale; /** - * {@inheritDoc} + * @test + * + * @dataProvider providerForValidInputWithLocale */ - public function providerForValidInput(): array + public function itShouldValidateInputAccordingToTheLocale(string $locale, string $input): void { - $sut = new No(); + setlocale(LC_ALL, $locale); - return [ - [$sut, 'N'], - [$sut, 'Nay'], - [$sut, 'Nix'], - [$sut, 'No'], - [$sut, 'Nope'], - [$sut, 'Not'], - ]; + if ($locale !== setlocale(LC_ALL, '0')) { + $this->markTestSkipped(sprintf('Could not set locale information to "%s"', $locale)); + } + + self::assertValidInput(new No(true), $input); } /** - * {@inheritDoc} + * @test + * + * @dataProvider providerForInvalidInputWithLocale */ - public function providerForInvalidInput(): array + public function itShouldInvalidateInputAccordingToTheLocale(string $locale, string $input): void { - $sut = new No(); + setlocale(LC_ALL, $locale); - return [ - [$sut, 'Donnot'], - [$sut, 'Never'], - [$sut, 'Niet'], - [$sut, 'Noooooooo'], - [$sut, 'Não'], - ]; + if ($locale !== setlocale(LC_ALL, '0')) { + $this->markTestSkipped(sprintf('Could not set locale information to "%s"', $locale)); + } + + self::assertInvalidInput(new No(true), $input); } /** * @return string[][] */ - public function providerForValidInputWithLocale(): array + public static function providerForValidInputWithLocale(): array { return [ 'nl' => ['nl_NL.UTF-8', 'Nee'], @@ -79,7 +78,7 @@ public function providerForValidInputWithLocale(): array /** * @return string[][] */ - public function providerForInvalidInputWithLocale(): array + public static function providerForInvalidInputWithLocale(): array { return [ 'nl' => ['nl_NL.UTF-8', 'Ez'], @@ -89,35 +88,36 @@ public function providerForInvalidInputWithLocale(): array } /** - * @test - * - * @dataProvider providerForValidInputWithLocale + * {@inheritDoc} */ - public function itShouldValidateInputAccordingToTheLocale(string $locale, string $input): void + public static function providerForValidInput(): array { - setlocale(LC_ALL, $locale); - - if ($locale !== setlocale(LC_ALL, '0')) { - $this->markTestSkipped(sprintf('Could not set locale information to "%s"', $locale)); - } + $sut = new No(); - self::assertValidInput(new No(true), $input); + return [ + [$sut, 'N'], + [$sut, 'Nay'], + [$sut, 'Nix'], + [$sut, 'No'], + [$sut, 'Nope'], + [$sut, 'Not'], + ]; } /** - * @test - * - * @dataProvider providerForInvalidInputWithLocale + * {@inheritDoc} */ - public function itShouldInvalidateInputAccordingToTheLocale(string $locale, string $input): void + public static function providerForInvalidInput(): array { - setlocale(LC_ALL, $locale); - - if ($locale !== setlocale(LC_ALL, '0')) { - $this->markTestSkipped(sprintf('Could not set locale information to "%s"', $locale)); - } + $sut = new No(); - self::assertInvalidInput(new No(true), $input); + return [ + [$sut, 'Donnot'], + [$sut, 'Never'], + [$sut, 'Niet'], + [$sut, 'Noooooooo'], + [$sut, 'Não'], + ]; } /** diff --git a/tests/unit/Rules/NoWhitespaceTest.php b/tests/unit/Rules/NoWhitespaceTest.php index 69488dc9b..fc7409d4b 100644 --- a/tests/unit/Rules/NoWhitespaceTest.php +++ b/tests/unit/Rules/NoWhitespaceTest.php @@ -27,7 +27,7 @@ final class NoWhitespaceTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new NoWhitespace(); @@ -43,7 +43,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new NoWhitespace(); diff --git a/tests/unit/Rules/NotBlankTest.php b/tests/unit/Rules/NotBlankTest.php index 63431d528..6412e9d39 100644 --- a/tests/unit/Rules/NotBlankTest.php +++ b/tests/unit/Rules/NotBlankTest.php @@ -26,7 +26,7 @@ final class NotBlankTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $object = new stdClass(); $object->foo = true; @@ -45,7 +45,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new NotBlank(); diff --git a/tests/unit/Rules/NotEmojiTest.php b/tests/unit/Rules/NotEmojiTest.php index 53400f19a..6827cd9b4 100644 --- a/tests/unit/Rules/NotEmojiTest.php +++ b/tests/unit/Rules/NotEmojiTest.php @@ -25,7 +25,7 @@ final class NotEmojiTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $sut = new NotEmoji(); @@ -43,7 +43,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $sut = new NotEmoji(); diff --git a/tests/unit/Rules/NotEmptyTest.php b/tests/unit/Rules/NotEmptyTest.php index e7f651fdf..0a2866acd 100644 --- a/tests/unit/Rules/NotEmptyTest.php +++ b/tests/unit/Rules/NotEmptyTest.php @@ -26,7 +26,7 @@ final class NotEmptyTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new NotEmpty(); @@ -42,7 +42,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new NotEmpty(); diff --git a/tests/unit/Rules/NotOptionalTest.php b/tests/unit/Rules/NotOptionalTest.php index 6d8e6595d..6a0f95b40 100644 --- a/tests/unit/Rules/NotOptionalTest.php +++ b/tests/unit/Rules/NotOptionalTest.php @@ -25,7 +25,7 @@ final class NotOptionalTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new NotOptional(); @@ -50,7 +50,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new NotOptional(); diff --git a/tests/unit/Rules/NotTest.php b/tests/unit/Rules/NotTest.php index c0ad4826e..8706416c5 100644 --- a/tests/unit/Rules/NotTest.php +++ b/tests/unit/Rules/NotTest.php @@ -74,7 +74,7 @@ public function notSetName(Validatable $rule): void /** * @return mixed[][] */ - public function providerForValidNot(): array + public static function providerForValidNot(): array { return [ [new IntVal(), ''], @@ -91,7 +91,7 @@ public function providerForValidNot(): array /** * @return mixed[][] */ - public function providerForInvalidNot(): array + public static function providerForInvalidNot(): array { return [ [new IntVal(), 123], @@ -104,7 +104,7 @@ public function providerForInvalidNot(): array /** * @return Validatable[][] */ - public function providerForSetName(): array + public static function providerForSetName(): array { return [ 'non-allOf' => [new IntVal()], diff --git a/tests/unit/Rules/NullTypeTest.php b/tests/unit/Rules/NullTypeTest.php index cd485c952..9970984af 100644 --- a/tests/unit/Rules/NullTypeTest.php +++ b/tests/unit/Rules/NullTypeTest.php @@ -26,7 +26,7 @@ final class NullTypeTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new NullType(); @@ -38,7 +38,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new NullType(); diff --git a/tests/unit/Rules/NullableTest.php b/tests/unit/Rules/NullableTest.php index 3f00a9896..66144d045 100644 --- a/tests/unit/Rules/NullableTest.php +++ b/tests/unit/Rules/NullableTest.php @@ -23,33 +23,6 @@ */ final class NullableTest extends TestCase { - /** - * Data provider for not nullable values. - * - * @return mixed[][] - */ - public function providerForNotNullable(): array - { - return [ - [''], - [1], - [[]], - [' '], - [0], - ['0'], - [0], - ['0.0'], - [false], - [['']], - [[' ']], - [[0]], - [['0']], - [[false]], - [[[''], [0]]], - [new stdClass()], - ]; - } - /** * @test */ @@ -153,4 +126,31 @@ public function shouldCheckRuleWhenInputIsNotNullable($input): void $rule = new Nullable($validatable); $rule->check($input); } + + /** + * Data provider for not nullable values. + * + * @return mixed[][] + */ + public static function providerForNotNullable(): array + { + return [ + [''], + [1], + [[]], + [' '], + [0], + ['0'], + [0], + ['0.0'], + [false], + [['']], + [[' ']], + [[0]], + [['0']], + [[false]], + [[[''], [0]]], + [new stdClass()], + ]; + } } diff --git a/tests/unit/Rules/NumberTest.php b/tests/unit/Rules/NumberTest.php index 549bfcd82..89abd89df 100644 --- a/tests/unit/Rules/NumberTest.php +++ b/tests/unit/Rules/NumberTest.php @@ -33,7 +33,7 @@ final class NumberTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new Number(); @@ -52,7 +52,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new Number(); diff --git a/tests/unit/Rules/NumericValTest.php b/tests/unit/Rules/NumericValTest.php index 65110041e..87d06a1fa 100644 --- a/tests/unit/Rules/NumericValTest.php +++ b/tests/unit/Rules/NumericValTest.php @@ -27,7 +27,7 @@ final class NumericValTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $numericVal = new NumericVal(); @@ -44,7 +44,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $numericVal = new NumericVal(); diff --git a/tests/unit/Rules/ObjectTypeTest.php b/tests/unit/Rules/ObjectTypeTest.php index a36133a8e..00898fa8a 100644 --- a/tests/unit/Rules/ObjectTypeTest.php +++ b/tests/unit/Rules/ObjectTypeTest.php @@ -27,7 +27,7 @@ final class ObjectTypeTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new ObjectType(); @@ -40,7 +40,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new ObjectType(); diff --git a/tests/unit/Rules/OddTest.php b/tests/unit/Rules/OddTest.php index ecc48bdcf..3519210b3 100644 --- a/tests/unit/Rules/OddTest.php +++ b/tests/unit/Rules/OddTest.php @@ -28,7 +28,7 @@ final class OddTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new Odd(); @@ -43,7 +43,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new Odd(); diff --git a/tests/unit/Rules/OptionalTest.php b/tests/unit/Rules/OptionalTest.php index a51733872..c44fa2cd6 100644 --- a/tests/unit/Rules/OptionalTest.php +++ b/tests/unit/Rules/OptionalTest.php @@ -23,41 +23,6 @@ */ final class OptionalTest extends TestCase { - /** - * @return mixed[][] - */ - public function providerForOptional(): array - { - return [ - [null], - [''], - ]; - } - - /** - * @return mixed[][] - */ - public function providerForNotOptional(): array - { - return [ - [1], - [[]], - [' '], - [0], - ['0'], - [0], - ['0.0'], - [false], - [['']], - [[' ']], - [[0]], - [['0']], - [[false]], - [[[''], [0]]], - [new stdClass()], - ]; - } - /** * @dataProvider providerForOptional * @@ -165,4 +130,39 @@ public function shouldCheckRuleWhenInputIsNotOptional(): void $rule->check($input); } + + /** + * @return mixed[][] + */ + public static function providerForOptional(): array + { + return [ + [null], + [''], + ]; + } + + /** + * @return mixed[][] + */ + public static function providerForNotOptional(): array + { + return [ + [1], + [[]], + [' '], + [0], + ['0'], + [0], + ['0.0'], + [false], + [['']], + [[' ']], + [[0]], + [['0']], + [[false]], + [[[''], [0]]], + [new stdClass()], + ]; + } } diff --git a/tests/unit/Rules/PerfectSquareTest.php b/tests/unit/Rules/PerfectSquareTest.php index 8fa115905..9baf049ef 100644 --- a/tests/unit/Rules/PerfectSquareTest.php +++ b/tests/unit/Rules/PerfectSquareTest.php @@ -26,7 +26,7 @@ final class PerfectSquareTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new PerfectSquare(); @@ -47,7 +47,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new PerfectSquare(); diff --git a/tests/unit/Rules/PeselTest.php b/tests/unit/Rules/PeselTest.php index 6c77a3534..5d2ff8234 100644 --- a/tests/unit/Rules/PeselTest.php +++ b/tests/unit/Rules/PeselTest.php @@ -25,7 +25,7 @@ final class PeselTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new Pesel(); @@ -44,7 +44,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new Pesel(); diff --git a/tests/unit/Rules/PhoneTest.php b/tests/unit/Rules/PhoneTest.php index 7b6b6e9a5..bc749766e 100644 --- a/tests/unit/Rules/PhoneTest.php +++ b/tests/unit/Rules/PhoneTest.php @@ -25,10 +25,30 @@ */ final class PhoneTest extends RuleTestCase { + public function testThrowsExceptionWithCountryName(): void + { + $phoneValidator = new Phone('BR'); + + $this->expectException(PhoneException::class); + $this->expectExceptionMessage('"abc" must be a valid telephone number for country "Brazil"'); + + $phoneValidator->assert('abc'); + } + + public function testThrowsExceptionForInternationalNumbers(): void + { + $phoneValidator = new Phone(); + + $this->expectException(PhoneException::class); + $this->expectExceptionMessage('"abc" must be a valid telephone number'); + + $phoneValidator->assert('abc'); + } + /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ [new Phone(), '+1 650 253 00 00'], @@ -45,31 +65,11 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ [new Phone(), '+1-650-253-00-0'], [new Phone('BR'), '+1 11 91111 1111'], // invalid + code for BR ]; } - - public function testThrowsExceptionWithCountryName(): void - { - $phoneValidator = new Phone('BR'); - - $this->expectException(PhoneException::class); - $this->expectExceptionMessage('"abc" must be a valid telephone number for country "Brazil"'); - - $phoneValidator->assert('abc'); - } - - public function testThrowsExceptionForInternationalNumbers(): void - { - $phoneValidator = new Phone(); - - $this->expectException(PhoneException::class); - $this->expectExceptionMessage('"abc" must be a valid telephone number'); - - $phoneValidator->assert('abc'); - } } diff --git a/tests/unit/Rules/PhpLabelTest.php b/tests/unit/Rules/PhpLabelTest.php index 493f2be0a..35e9d1405 100644 --- a/tests/unit/Rules/PhpLabelTest.php +++ b/tests/unit/Rules/PhpLabelTest.php @@ -32,7 +32,7 @@ final class PhpLabelTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new PhpLabel(); @@ -50,7 +50,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new PhpLabel(); diff --git a/tests/unit/Rules/PisTest.php b/tests/unit/Rules/PisTest.php index 4f57aab2d..7ba733a91 100644 --- a/tests/unit/Rules/PisTest.php +++ b/tests/unit/Rules/PisTest.php @@ -26,7 +26,7 @@ final class PisTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new Pis(); @@ -48,7 +48,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new Pis(); diff --git a/tests/unit/Rules/PolishIdCardTest.php b/tests/unit/Rules/PolishIdCardTest.php index c2d8bfdcf..2c991b3e8 100644 --- a/tests/unit/Rules/PolishIdCardTest.php +++ b/tests/unit/Rules/PolishIdCardTest.php @@ -23,7 +23,7 @@ final class PolishIdCardTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new PolishIdCard(); @@ -37,7 +37,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new PolishIdCard(); diff --git a/tests/unit/Rules/PortugueseNifTest.php b/tests/unit/Rules/PortugueseNifTest.php index dfc4b12f5..1f3f2002b 100644 --- a/tests/unit/Rules/PortugueseNifTest.php +++ b/tests/unit/Rules/PortugueseNifTest.php @@ -19,7 +19,7 @@ final class PortugueseNifTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new PortugueseNif(); @@ -49,7 +49,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new PortugueseNif(); diff --git a/tests/unit/Rules/PositiveTest.php b/tests/unit/Rules/PositiveTest.php index ae97ee627..cc8b388c9 100644 --- a/tests/unit/Rules/PositiveTest.php +++ b/tests/unit/Rules/PositiveTest.php @@ -27,7 +27,7 @@ final class PositiveTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new Positive(); @@ -42,7 +42,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new Positive(); diff --git a/tests/unit/Rules/PostalCodeTest.php b/tests/unit/Rules/PostalCodeTest.php index 94244fd45..70362bfeb 100644 --- a/tests/unit/Rules/PostalCodeTest.php +++ b/tests/unit/Rules/PostalCodeTest.php @@ -58,7 +58,7 @@ public function shouldThrowsExceptionWhenCountryCodeIsNotValid(): void /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ [new PostalCode('BR'), '02179-000'], @@ -98,7 +98,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ [new PostalCode('BR'), '02179'], diff --git a/tests/unit/Rules/PrimeNumberTest.php b/tests/unit/Rules/PrimeNumberTest.php index fa2ee82fb..b96199f41 100644 --- a/tests/unit/Rules/PrimeNumberTest.php +++ b/tests/unit/Rules/PrimeNumberTest.php @@ -26,7 +26,7 @@ final class PrimeNumberTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new PrimeNumber(); @@ -43,7 +43,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new PrimeNumber(); diff --git a/tests/unit/Rules/PrintableTest.php b/tests/unit/Rules/PrintableTest.php index 3ee0b5f15..802f0efe4 100644 --- a/tests/unit/Rules/PrintableTest.php +++ b/tests/unit/Rules/PrintableTest.php @@ -27,7 +27,7 @@ final class PrintableTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new Printable(); @@ -47,7 +47,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new Printable(); diff --git a/tests/unit/Rules/PublicDomainSuffixTest.php b/tests/unit/Rules/PublicDomainSuffixTest.php index 748c16f4e..487e59672 100644 --- a/tests/unit/Rules/PublicDomainSuffixTest.php +++ b/tests/unit/Rules/PublicDomainSuffixTest.php @@ -22,7 +22,7 @@ final class PublicDomainSuffixTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new PublicDomainSuffix(); @@ -36,7 +36,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new PublicDomainSuffix(); diff --git a/tests/unit/Rules/PunctTest.php b/tests/unit/Rules/PunctTest.php index 599c056d1..125a2ea3e 100644 --- a/tests/unit/Rules/PunctTest.php +++ b/tests/unit/Rules/PunctTest.php @@ -29,7 +29,7 @@ final class PunctTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $sut = new Punct(); @@ -46,7 +46,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $sut = new Punct(); diff --git a/tests/unit/Rules/ReadableTest.php b/tests/unit/Rules/ReadableTest.php index 331413c8f..dec772905 100644 --- a/tests/unit/Rules/ReadableTest.php +++ b/tests/unit/Rules/ReadableTest.php @@ -9,8 +9,8 @@ namespace Respect\Validation\Rules; -use Psr\Http\Message\StreamInterface; use Respect\Validation\Test\RuleTestCase; +use Respect\Validation\Test\Stubs\StreamStub; use SplFileInfo; use stdClass; @@ -27,39 +27,31 @@ final class ReadableTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { - $file = $this->getFixtureDirectory() . '/valid-image.gif'; + $file = self::fixture('valid-image.gif'); $rule = new Readable(); return [ [$rule, $file], [$rule, new SplFileInfo($file)], - [$rule, $this->createPsr7Stream(true)], + [$rule, StreamStub::create()], ]; } /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { - $file = $this->getFixtureDirectory() . '/invalid-image.gif'; + $file = self::fixture('invalid-image.gif'); $rule = new Readable(); return [ [$rule, $file], [$rule, new SplFileInfo($file)], [$rule, new stdClass()], - [$rule, $this->createPsr7Stream(false)], + [$rule, StreamStub::createUnreadable()], ]; } - - private function createPsr7Stream(bool $isReadable): StreamInterface - { - $stream = $this->createMock(StreamInterface::class); - $stream->expects(self::any())->method('isReadable')->willReturn($isReadable); - - return $stream; - } } diff --git a/tests/unit/Rules/RegexTest.php b/tests/unit/Rules/RegexTest.php index f382a7ae0..06fc0caa7 100644 --- a/tests/unit/Rules/RegexTest.php +++ b/tests/unit/Rules/RegexTest.php @@ -25,7 +25,7 @@ final class RegexTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ [new Regex('/^[a-z]+$/'), 'wpoiur'], @@ -37,7 +37,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ [new Regex('/^w+$/'), 'w poiur'], diff --git a/tests/unit/Rules/ResourceTypeTest.php b/tests/unit/Rules/ResourceTypeTest.php index 15f23c5b6..f066267cd 100644 --- a/tests/unit/Rules/ResourceTypeTest.php +++ b/tests/unit/Rules/ResourceTypeTest.php @@ -28,7 +28,7 @@ final class ResourceTypeTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new ResourceType(); @@ -41,7 +41,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new ResourceType(); diff --git a/tests/unit/Rules/RomanTest.php b/tests/unit/Rules/RomanTest.php index efd81d955..ced85e80e 100644 --- a/tests/unit/Rules/RomanTest.php +++ b/tests/unit/Rules/RomanTest.php @@ -25,7 +25,7 @@ final class RomanTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $sut = new Roman(); @@ -48,7 +48,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $sut = new Roman(); diff --git a/tests/unit/Rules/ScalarValTest.php b/tests/unit/Rules/ScalarValTest.php index 6cfb0279b..6773dde00 100644 --- a/tests/unit/Rules/ScalarValTest.php +++ b/tests/unit/Rules/ScalarValTest.php @@ -27,7 +27,7 @@ final class ScalarValTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new ScalarVal(); @@ -44,7 +44,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new ScalarVal(); diff --git a/tests/unit/Rules/SizeTest.php b/tests/unit/Rules/SizeTest.php index 6b09221f6..e11e205ac 100644 --- a/tests/unit/Rules/SizeTest.php +++ b/tests/unit/Rules/SizeTest.php @@ -11,9 +11,10 @@ use org\bovigo\vfs\content\LargeFileContent; use org\bovigo\vfs\vfsStream; -use Psr\Http\Message\StreamInterface; use Respect\Validation\Exceptions\ComponentException; use Respect\Validation\Test\RuleTestCase; +use Respect\Validation\Test\Stubs\StreamStub; +use Respect\Validation\Test\Stubs\UploadedFileStub; use SplFileInfo; /** @@ -27,10 +28,21 @@ */ final class SizeTest extends RuleTestCase { + /** + * @test + */ + public function shouldThrowsAnExceptionWhenSizeIsNotValid(): void + { + $this->expectException(ComponentException::class); + $this->expectExceptionMessage('"42jb" is not a recognized file size'); + + new Size('42jb'); + } + /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $root = vfsStream::setup(); $file2Kb = vfsStream::newFile('2kb.txt') @@ -52,13 +64,15 @@ public function providerForValidInput(): array 'file with up to 3mb' => [new Size(null, '3mb'), $file2Mb->url()], 'file between 1mb and 3mb' => [new Size('1mb', '3mb'), $file2Mb->url()], 'SplFileInfo instance' => [new Size('1mb', '3mb'), new SplFileInfo($file2Mb->url())], + 'PSR-7 stream' => [new Size('1kb', '2kb'), StreamStub::createWithSize(1024)], + 'PSR-7 UploadedFile' => [new Size('1kb', '2kb'), UploadedFileStub::createWithSize(1024)], ]; } /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $root = vfsStream::setup(); $file2Kb = vfsStream::newFile('2kb.txt') @@ -68,9 +82,6 @@ public function providerForInvalidInput(): array ->withContent(LargeFileContent::withMegabytes(2)) ->at($root); - $psr7Stream1Mb = $this->createMock(StreamInterface::class); - $psr7Stream1Mb->expects(self::once())->method('getSize')->willReturn(1024); - return [ 'file with at least 3kb' => [new Size('3kb', null), $file2Kb->url()], 'file with up to 1kb' => [new Size(null, '1kb'), $file2Kb->url()], @@ -81,18 +92,8 @@ public function providerForInvalidInput(): array 'file between 1pb and 3pb' => [new Size('1pb', '3pb'), $file2Mb->url()], 'SplFileInfo instancia' => [new Size('1pb', '3pb'), new SplFileInfo($file2Mb->url())], 'parameter invalid' => [new Size('1pb', '3pb'), []], - 'PSR-7 stream' => [new Size('1MB', '1.1MB'), $psr7Stream1Mb], + 'PSR-7 stream' => [new Size('1MB', '1.1MB'), StreamStub::createWithSize(1024)], + 'PSR-7 UploadedFile' => [new Size('1MB', '1.1MB'), UploadedFileStub::createWithSize(1024)], ]; } - - /** - * @test - */ - public function shouldThrowsAnExceptionWhenSizeIsNotValid(): void - { - $this->expectException(ComponentException::class); - $this->expectExceptionMessage('"42jb" is not a recognized file size'); - - new Size('42jb'); - } } diff --git a/tests/unit/Rules/SlugTest.php b/tests/unit/Rules/SlugTest.php index af92df722..e6bd451c7 100644 --- a/tests/unit/Rules/SlugTest.php +++ b/tests/unit/Rules/SlugTest.php @@ -28,7 +28,7 @@ final class SlugTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $sut = new Slug(); @@ -43,7 +43,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $sut = new Slug(); diff --git a/tests/unit/Rules/SortedTest.php b/tests/unit/Rules/SortedTest.php index be29fcb0e..0ea0c46c5 100644 --- a/tests/unit/Rules/SortedTest.php +++ b/tests/unit/Rules/SortedTest.php @@ -11,6 +11,7 @@ use Respect\Validation\Exceptions\ComponentException; use Respect\Validation\Test\RuleTestCase; +use stdClass; /** * @group rules @@ -23,10 +24,20 @@ */ final class SortedTest extends RuleTestCase { + /** + * @test + */ + public function itShouldNotAcceptWrongSortingDirection(): void + { + $this->expectExceptionObject(new ComponentException('Direction should be either "ASC" or "DESC"')); + + new Sorted('something'); + } + /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ 'empty' => [new Sorted('ASC'), []], @@ -43,7 +54,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ 'duplicate' => [new Sorted('ASC'), [1, 1, 1]], @@ -55,16 +66,10 @@ public function providerForInvalidInput(): array 'DESC string-sequence with ASC validation' => [new Sorted('ASC'), '321'], 'ASC array-sequence with DESC validation' => [new Sorted('DESC'), [1, 2, 3]], 'ASC string-sequence with DESC validation' => [new Sorted('DESC'), 'abc'], + 'unsupported value (integer)' => [new Sorted('DESC'), 1 ], + 'unsupported value (float)' => [new Sorted('DESC'), 1.2 ], + 'unsupported value (bool)' => [new Sorted('DESC'), true ], + 'unsupported value (object)' => [new Sorted('DESC'), new stdClass() ], ]; } - - /** - * @test - */ - public function itShouldNotAcceptWrongSortingDirection(): void - { - $this->expectExceptionObject(new ComponentException('Direction should be either "ASC" or "DESC"')); - - new Sorted('something'); - } } diff --git a/tests/unit/Rules/SpaceTest.php b/tests/unit/Rules/SpaceTest.php index 6bee7e42a..e06da45de 100644 --- a/tests/unit/Rules/SpaceTest.php +++ b/tests/unit/Rules/SpaceTest.php @@ -29,7 +29,7 @@ final class SpaceTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $sut = new Space(); @@ -47,7 +47,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $sut = new Space(); diff --git a/tests/unit/Rules/StartsWithTest.php b/tests/unit/Rules/StartsWithTest.php index 4b9b079b5..3cbc3d498 100644 --- a/tests/unit/Rules/StartsWithTest.php +++ b/tests/unit/Rules/StartsWithTest.php @@ -26,7 +26,7 @@ final class StartsWithTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ [new StartsWith('foo'), ['foo', 'bar']], @@ -41,7 +41,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ [new StartsWith('foo'), ''], diff --git a/tests/unit/Rules/StringTypeTest.php b/tests/unit/Rules/StringTypeTest.php index 17568823f..516540112 100644 --- a/tests/unit/Rules/StringTypeTest.php +++ b/tests/unit/Rules/StringTypeTest.php @@ -27,7 +27,7 @@ final class StringTypeTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new StringType(); @@ -40,7 +40,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new StringType(); diff --git a/tests/unit/Rules/StringValTest.php b/tests/unit/Rules/StringValTest.php index 5db248097..85e6da55b 100644 --- a/tests/unit/Rules/StringValTest.php +++ b/tests/unit/Rules/StringValTest.php @@ -28,7 +28,7 @@ final class StringValTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new StringVal(); @@ -46,7 +46,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new StringVal(); diff --git a/tests/unit/Rules/SubdivisionCodeTest.php b/tests/unit/Rules/SubdivisionCodeTest.php index 341d38143..583c4a545 100644 --- a/tests/unit/Rules/SubdivisionCodeTest.php +++ b/tests/unit/Rules/SubdivisionCodeTest.php @@ -47,20 +47,6 @@ public function shouldNotAcceptWrongNamesOnConstructor(): void new SubdivisionCode('JK'); } - /** - * @return mixed[][] - */ - public function providerForValidSubdivisionCodeInformation(): array - { - return [ - ['AQ', null], - ['BR', 'SP'], - ['MV', '00'], - ['US', 'CA'], - ['YT', ''], - ]; - } - /** * @dataProvider providerForValidSubdivisionCodeInformation * @@ -73,18 +59,6 @@ public function shouldValidateValidSubdivisionCodeInformation(string $countryCod self::assertTrue($countrySubdivision->validate($input)); } - /** - * @return mixed[][] - */ - public function providerForInvalidSubdivisionCodeInformation(): array - { - return [ - ['BR', 'CA'], - ['MV', 0], - ['US', 'CE'], - ]; - } - /** * @dataProvider providerForInvalidSubdivisionCodeInformation * @@ -111,4 +85,30 @@ public function shouldThrowsSubdivisionCodeException(): void $countrySubdivision->assert('CA'); } + + /** + * @return mixed[][] + */ + public static function providerForValidSubdivisionCodeInformation(): array + { + return [ + ['AQ', null], + ['BR', 'SP'], + ['MV', '00'], + ['US', 'CA'], + ['YT', ''], + ]; + } + + /** + * @return mixed[][] + */ + public static function providerForInvalidSubdivisionCodeInformation(): array + { + return [ + ['BR', 'CA'], + ['MV', 0], + ['US', 'CE'], + ]; + } } diff --git a/tests/unit/Rules/SubsetTest.php b/tests/unit/Rules/SubsetTest.php index 8c1741a64..78eecd522 100644 --- a/tests/unit/Rules/SubsetTest.php +++ b/tests/unit/Rules/SubsetTest.php @@ -24,7 +24,7 @@ final class SubsetTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ [new Subset([]), []], @@ -40,7 +40,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ [new Subset([]), [1]], diff --git a/tests/unit/Rules/SymbolicLinkTest.php b/tests/unit/Rules/SymbolicLinkTest.php index 4e6c7c406..ec4f79712 100644 --- a/tests/unit/Rules/SymbolicLinkTest.php +++ b/tests/unit/Rules/SymbolicLinkTest.php @@ -29,7 +29,7 @@ final class SymbolicLinkTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $sut = new SymbolicLink(); @@ -43,7 +43,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $sut = new SymbolicLink(); diff --git a/tests/unit/Rules/TimeTest.php b/tests/unit/Rules/TimeTest.php index d877fb5a3..08ed224e1 100644 --- a/tests/unit/Rules/TimeTest.php +++ b/tests/unit/Rules/TimeTest.php @@ -24,41 +24,33 @@ final class TimeTest extends RuleTestCase { /** - * {@inheritDoc} + * @test + * + * @dataProvider invalidFormatsProvider */ - public function providerForValidInput(): array + public function shouldThrowAnExceptionWhenFormatIsNotValid(string $format): void { - return [ - [new Time(), '00:00:00'], - [new Time(), '23:20:59'], - [new Time('H:i'), '23:59'], - [new Time('g:i A'), '8:13 AM'], - [new Time('His'), 232059], - [new Time('H:i:s.u'), '08:16:01.000000'], - [new Time('ga'), '3am'], - ]; + $this->expectException(ComponentException::class); + + new Time($format); } /** - * {@inheritDoc} + * @test */ - public function providerForInvalidInput(): array + public function shouldPassFormatToParameterToException(): void { - return [ - [new Time(), '00:00:60'], - [new Time(), '00:60:00'], - [new Time(), '24:00:00'], - [new Time(), '00:00'], - [new Time(), new DateTime()], - [new Time(), new DateTimeImmutable()], - [new Time(), ''], - ]; + $format = 'g:i A'; + $equals = new Time($format); + $exception = $equals->reportError('input'); + + self::assertSame($format, $exception->getParam('format')); } /** * @return mixed[][] */ - public function invalidFormatsProvider(): array + public static function invalidFormatsProvider(): array { return [ ['Y-m-d H:i:s'], @@ -67,26 +59,34 @@ public function invalidFormatsProvider(): array } /** - * @test - * - * @dataProvider invalidFormatsProvider + * {@inheritDoc} */ - public function shouldThrowAnExceptionWhenFormatIsNotValid(string $format): void + public static function providerForValidInput(): array { - $this->expectException(ComponentException::class); - - new Time($format); + return [ + [new Time(), '00:00:00'], + [new Time(), '23:20:59'], + [new Time('H:i'), '23:59'], + [new Time('g:i A'), '8:13 AM'], + [new Time('His'), 232059], + [new Time('H:i:s.u'), '08:16:01.000000'], + [new Time('ga'), '3am'], + ]; } /** - * @test + * {@inheritDoc} */ - public function shouldPassFormatToParameterToException(): void + public static function providerForInvalidInput(): array { - $format = 'g:i A'; - $equals = new Time($format); - $exception = $equals->reportError('input'); - - self::assertSame($format, $exception->getParam('format')); + return [ + [new Time(), '00:00:60'], + [new Time(), '00:60:00'], + [new Time(), '24:00:00'], + [new Time(), '00:00'], + [new Time(), new DateTime()], + [new Time(), new DateTimeImmutable()], + [new Time(), ''], + ]; } } diff --git a/tests/unit/Rules/TldTest.php b/tests/unit/Rules/TldTest.php index 3dbb7dfaf..fe16be14f 100644 --- a/tests/unit/Rules/TldTest.php +++ b/tests/unit/Rules/TldTest.php @@ -28,7 +28,7 @@ final class TldTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new Tld(); @@ -46,7 +46,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new Tld(); diff --git a/tests/unit/Rules/TrueValTest.php b/tests/unit/Rules/TrueValTest.php index 4d847649d..fa00d4b32 100644 --- a/tests/unit/Rules/TrueValTest.php +++ b/tests/unit/Rules/TrueValTest.php @@ -25,7 +25,7 @@ final class TrueValTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new TrueVal(); @@ -48,7 +48,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new TrueVal(); diff --git a/tests/unit/Rules/TypeTest.php b/tests/unit/Rules/TypeTest.php index 950406a7b..0923b81cc 100644 --- a/tests/unit/Rules/TypeTest.php +++ b/tests/unit/Rules/TypeTest.php @@ -39,7 +39,7 @@ public function shouldThrowExceptionWhenTypeIsNotValid(): void /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ [new Type('array'), []], @@ -64,7 +64,7 @@ static function (): void { /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ [new Type('int'), '1'], diff --git a/tests/unit/Rules/UniqueTest.php b/tests/unit/Rules/UniqueTest.php index c2e4fb55b..15ce9f515 100644 --- a/tests/unit/Rules/UniqueTest.php +++ b/tests/unit/Rules/UniqueTest.php @@ -25,7 +25,7 @@ final class UniqueTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new Unique(); @@ -43,7 +43,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new Unique(); diff --git a/tests/unit/Rules/UploadedTest.php b/tests/unit/Rules/UploadedTest.php index 37ba1ca49..7e4ea794e 100644 --- a/tests/unit/Rules/UploadedTest.php +++ b/tests/unit/Rules/UploadedTest.php @@ -10,8 +10,8 @@ namespace Respect\Validation\Rules; use PHPUnit\Framework\SkippedTestError; -use Psr\Http\Message\UploadedFileInterface; use Respect\Validation\Test\RuleTestCase; +use Respect\Validation\Test\Stubs\UploadedFileStub; use SplFileInfo; use stdClass; @@ -34,21 +34,21 @@ final class UploadedTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new Uploaded(); return [ [$rule, self::UPLOADED_FILENAME], [$rule, new SplFileInfo(self::UPLOADED_FILENAME)], - [$rule, $this->createMock(UploadedFileInterface::class)], + [$rule, UploadedFileStub::create()], ]; } /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new Uploaded(); diff --git a/tests/unit/Rules/UppercaseTest.php b/tests/unit/Rules/UppercaseTest.php index ba9cd6016..253c83e10 100644 --- a/tests/unit/Rules/UppercaseTest.php +++ b/tests/unit/Rules/UppercaseTest.php @@ -27,7 +27,7 @@ final class UppercaseTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new Uppercase(); @@ -49,7 +49,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new Uppercase(); diff --git a/tests/unit/Rules/UrlTest.php b/tests/unit/Rules/UrlTest.php index 8371a3373..a7102bba4 100644 --- a/tests/unit/Rules/UrlTest.php +++ b/tests/unit/Rules/UrlTest.php @@ -25,7 +25,7 @@ final class UrlTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new Url(); @@ -48,7 +48,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new Url(); diff --git a/tests/unit/Rules/UuidTest.php b/tests/unit/Rules/UuidTest.php index e9ecd008a..159cf4a02 100644 --- a/tests/unit/Rules/UuidTest.php +++ b/tests/unit/Rules/UuidTest.php @@ -34,10 +34,47 @@ final class UuidTest extends RuleTestCase private const UUID_VERSION_4 = '25769c6c-d34d-4bfe-ba98-e0ee856f3e7a'; private const UUID_VERSION_5 = 'c4a760a8-dbcf-5254-a0d9-6a4474bd1b62'; + /** + * @test + */ + public function itShouldThrowExceptionWhenVersionIsTwo(): void + { + self::expectException(ComponentException::class); + self::expectExceptionMessage('Only versions 1, 3, 4, and 5 are supported: 2 given'); + + new Uuid(2); + } + + /** + * @test + */ + public function itShouldThrowExceptionWhenVersionIsGreaterThanFive(): void + { + $version = random_int(6, PHP_INT_MAX); + + self::expectException(ComponentException::class); + self::expectExceptionMessage('Only versions 1, 3, 4, and 5 are supported: ' . $version . ' given'); + + new Uuid($version); + } + + /** + * @test + */ + public function itShouldThrowExceptionWhenVersionIsLessThanOne(): void + { + $version = random_int(PHP_INT_MIN, 0); + + self::expectException(ComponentException::class); + self::expectExceptionMessage('Only versions 1, 3, 4, and 5 are supported: ' . $version . ' given'); + + new Uuid($version); + } + /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $sut = new Uuid(); @@ -56,7 +93,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $sut = new Uuid(); $sutVersion1 = new Uuid(1); @@ -88,41 +125,4 @@ public function providerForInvalidInput(): array 'object' => [$sut, new stdClass()], ]; } - - /** - * @test - */ - public function itShouldThrowExceptionWhenVersionIsTwo(): void - { - self::expectException(ComponentException::class); - self::expectExceptionMessage('Only versions 1, 3, 4, and 5 are supported: 2 given'); - - new Uuid(2); - } - - /** - * @test - */ - public function itShouldThrowExceptionWhenVersionIsGreaterThanFive(): void - { - $version = random_int(6, PHP_INT_MAX); - - self::expectException(ComponentException::class); - self::expectExceptionMessage('Only versions 1, 3, 4, and 5 are supported: ' . $version . ' given'); - - new Uuid($version); - } - - /** - * @test - */ - public function itShouldThrowExceptionWhenVersionIsLessThanOne(): void - { - $version = random_int(PHP_INT_MIN, 0); - - self::expectException(ComponentException::class); - self::expectExceptionMessage('Only versions 1, 3, 4, and 5 are supported: ' . $version . ' given'); - - new Uuid($version); - } } diff --git a/tests/unit/Rules/VersionTest.php b/tests/unit/Rules/VersionTest.php index e82af4049..461665004 100644 --- a/tests/unit/Rules/VersionTest.php +++ b/tests/unit/Rules/VersionTest.php @@ -27,7 +27,7 @@ final class VersionTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $sut = new Version(); @@ -45,7 +45,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $sut = new Version(); diff --git a/tests/unit/Rules/VideoUrlTest.php b/tests/unit/Rules/VideoUrlTest.php index 28b2e6bd0..9d77172f7 100644 --- a/tests/unit/Rules/VideoUrlTest.php +++ b/tests/unit/Rules/VideoUrlTest.php @@ -26,7 +26,7 @@ final class VideoUrlTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ 'vimeo service with subdomain' => [new VideoUrl('vimeo'), 'https://player.vimeo.com/video/71787467'], @@ -47,7 +47,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ 'vimeo service with youtube url' => [new VideoUrl('vimeo'), 'https://www.youtube.com/watch?v=netHLn9TScY'], diff --git a/tests/unit/Rules/VowelTest.php b/tests/unit/Rules/VowelTest.php index c33978cc2..22ec3b021 100644 --- a/tests/unit/Rules/VowelTest.php +++ b/tests/unit/Rules/VowelTest.php @@ -28,7 +28,7 @@ final class VowelTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $sut = new Vowel(); @@ -48,7 +48,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $sut = new Vowel(); diff --git a/tests/unit/Rules/WhenTest.php b/tests/unit/Rules/WhenTest.php index 23b25ab97..7fa60957d 100644 --- a/tests/unit/Rules/WhenTest.php +++ b/tests/unit/Rules/WhenTest.php @@ -26,45 +26,45 @@ final class WhenTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ 'all true' => [ new When( - $this->createValidatableMock(true), - $this->createValidatableMock(true), - $this->createValidatableMock(true) + new AlwaysValid(), + new AlwaysValid(), + new AlwaysValid() ), true, ], 'bool (when = true, then = true, else = false)' => [ new When( - $this->createValidatableMock(true), - $this->createValidatableMock(true), - $this->createValidatableMock(false) + new AlwaysValid(), + new AlwaysValid(), + new AlwaysInvalid() ), true, ], 'bool (when = false, then = true, else = true)' => [ new When( - $this->createValidatableMock(false), - $this->createValidatableMock(true), - $this->createValidatableMock(true) + new AlwaysInvalid(), + new AlwaysValid(), + new AlwaysValid() ), true, ], 'bool (when = false, then = false, else = true)' => [ new When( - $this->createValidatableMock(false), - $this->createValidatableMock(false), - $this->createValidatableMock(true) + new AlwaysInvalid(), + new AlwaysInvalid(), + new AlwaysValid() ), true, ], 'bool (when = false, then = true, else = null)' => [ new When( - $this->createValidatableMock(true), - $this->createValidatableMock(true), + new AlwaysValid(), + new AlwaysValid(), null ), true, @@ -75,37 +75,37 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ 'bool (when = true, then = false, else = false)' => [ new When( - $this->createValidatableMock(true), - $this->createValidatableMock(false), - $this->createValidatableMock(false) + new AlwaysValid(), + new AlwaysInvalid(), + new AlwaysInvalid() ), false, ], 'bool (when = true, then = false, else = true)' => [ new When( - $this->createValidatableMock(true), - $this->createValidatableMock(false), - $this->createValidatableMock(true) + new AlwaysValid(), + new AlwaysInvalid(), + new AlwaysValid() ), false, ], 'bool (when = false, then = false, else = false)' => [ new When( - $this->createValidatableMock(false), - $this->createValidatableMock(false), - $this->createValidatableMock(false) + new AlwaysInvalid(), + new AlwaysInvalid(), + new AlwaysInvalid() ), false, ], 'bool (when = true, then = false, else = null)' => [ new When( - $this->createValidatableMock(true), - $this->createValidatableMock(false), + new AlwaysValid(), + new AlwaysInvalid(), null ), false, diff --git a/tests/unit/Rules/WritableTest.php b/tests/unit/Rules/WritableTest.php index 0e0d80a88..cf4fefa17 100644 --- a/tests/unit/Rules/WritableTest.php +++ b/tests/unit/Rules/WritableTest.php @@ -9,8 +9,8 @@ namespace Respect\Validation\Rules; -use Psr\Http\Message\StreamInterface; use Respect\Validation\Test\RuleTestCase; +use Respect\Validation\Test\Stubs\StreamStub; use SplFileInfo; use SplFileObject; use stdClass; @@ -31,32 +31,36 @@ final class WritableTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $sut = new Writable(); - $filename = $this->getFixtureDirectory() . '/valid-image.png'; + $filename = self::fixture('valid-image.png'); + $directory = self::fixture(); + + chmod($filename, 0644); + chmod($directory, 0755); return [ 'writable file' => [$sut, $filename], - 'writable directory' => [$sut, $this->getFixtureDirectory()], + 'writable directory' => [$sut, $directory], 'writable SplFileInfo file' => [$sut, new SplFileInfo($filename)], 'writable SplFileObject file' => [$sut, new SplFileObject($filename)], - 'writable PSR-7 stream' => [$sut, $this->createPsr7Stream(true)], + 'writable PSR-7 stream' => [$sut, StreamStub::create()], ]; } /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new Writable(); - $filename = $this->getFixtureDirectory() . '/non-writable'; + $filename = self::fixture('non-writable'); - $this->changeFileModeToUnwritable($filename); + chmod($filename, 0555); return [ - 'unwritable PSR-7 stream' => [$rule, $this->createPsr7Stream(false)], + 'unwritable PSR-7 stream' => [$rule, StreamStub::createUnwritable()], 'unwritable filename' => [$rule, $filename], 'unwritable SplFileInfo file' => [$rule, new SplFileInfo($filename)], 'unwritable SplFileObject file' => [$rule, new SplFileObject($filename)], @@ -70,17 +74,4 @@ public function providerForInvalidInput(): array 'array' => [$rule, []], ]; } - - private function createPsr7Stream(bool $isWritable): StreamInterface - { - $stream = $this->createMock(StreamInterface::class); - $stream->expects(self::any())->method('isWritable')->willReturn($isWritable); - - return $stream; - } - - private function changeFileModeToUnwritable(string $filename): void - { - chmod($filename, 0555); - } } diff --git a/tests/unit/Rules/XdigitTest.php b/tests/unit/Rules/XdigitTest.php index 4fd47b910..e5ffa3843 100644 --- a/tests/unit/Rules/XdigitTest.php +++ b/tests/unit/Rules/XdigitTest.php @@ -28,7 +28,7 @@ final class XdigitTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ [new Xdigit(), 'FFF'], @@ -45,7 +45,7 @@ public function providerForValidInput(): array /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ [new Xdigit(), ''], diff --git a/tests/unit/Rules/YesTest.php b/tests/unit/Rules/YesTest.php index df2a22884..3ea051a44 100644 --- a/tests/unit/Rules/YesTest.php +++ b/tests/unit/Rules/YesTest.php @@ -36,45 +36,41 @@ final class YesTest extends RuleTestCase private $locale; /** - * {@inheritDoc} + * @test + * + * @dataProvider providerForValidInputWithLocale */ - public function providerForValidInput(): array + public function itShouldValidateValidInputAccordingToTheLocale(string $locale, string $input): void { - $sut = new Yes(); + setlocale(LC_ALL, $locale); - return [ - 'Y' => [$sut, 'Y'], - 'Yea' => [$sut, 'Yea'], - 'Yeah' => [$sut, 'Yeah'], - 'Yep' => [$sut, 'Yep'], - 'Yes' => [$sut, 'Yes'], - 'with locale + starting with "Y"' => [new Yes(true), 'Yydoesnotmatter'], - ]; + if ($locale !== setlocale(LC_ALL, '0')) { + $this->markTestSkipped(sprintf('Could not set locale information to "%s"', $locale)); + } + + self::assertValidInput(new Yes(true), $input); } /** - * {@inheritDoc} + * @test + * + * @dataProvider providerForInvalidInputWithLocale */ - public function providerForInvalidInput(): array + public function itShouldValidateInvalidInputAccordingToTheLocale(string $locale, string $input): void { - $sut = new Yes(); + setlocale(LC_ALL, $locale); - return [ - 'spanish' => [$sut, 'Si'], - 'portuguese' => [$sut, 'Sim'], - 'starting with "Y"' => [$sut, 'Yoo'], - 'boolean true' => [$sut, true], - 'array' => [$sut, ['Yes']], - 'object' => [$sut, new stdClass()], - 'int' => [$sut, random_int(1, PHP_INT_MAX)], - 'float' => [$sut, random_int(1, 9) / 10], - ]; + if ($locale !== setlocale(LC_ALL, '0')) { + $this->markTestSkipped(sprintf('Could not set locale information to "%s"', $locale)); + } + + self::assertInvalidInput(new Yes(true), $input); } /** * @return string[][] */ - public function providerForValidInputWithLocale(): array + public static function providerForValidInputWithLocale(): array { return [ 'nl' => ['nl_NL.UTF-8', 'Ja'], @@ -86,7 +82,7 @@ public function providerForValidInputWithLocale(): array /** * @return string[][] */ - public function providerForInvalidInputWithLocale(): array + public static function providerForInvalidInputWithLocale(): array { return [ 'nl' => ['nl_NL.UTF-8', 'Sim'], @@ -96,35 +92,39 @@ public function providerForInvalidInputWithLocale(): array } /** - * @test - * - * @dataProvider providerForValidInputWithLocale + * {@inheritDoc} */ - public function itShouldValidateValidInputAccordingToTheLocale(string $locale, string $input): void + public static function providerForValidInput(): array { - setlocale(LC_ALL, $locale); - - if ($locale !== setlocale(LC_ALL, '0')) { - $this->markTestSkipped(sprintf('Could not set locale information to "%s"', $locale)); - } + $sut = new Yes(); - self::assertValidInput(new Yes(true), $input); + return [ + 'Y' => [$sut, 'Y'], + 'Yea' => [$sut, 'Yea'], + 'Yeah' => [$sut, 'Yeah'], + 'Yep' => [$sut, 'Yep'], + 'Yes' => [$sut, 'Yes'], + 'with locale + starting with "Y"' => [new Yes(true), 'Yydoesnotmatter'], + ]; } /** - * @test - * - * @dataProvider providerForInvalidInputWithLocale + * {@inheritDoc} */ - public function itShouldValidateInvalidInputAccordingToTheLocale(string $locale, string $input): void + public static function providerForInvalidInput(): array { - setlocale(LC_ALL, $locale); - - if ($locale !== setlocale(LC_ALL, '0')) { - $this->markTestSkipped(sprintf('Could not set locale information to "%s"', $locale)); - } + $sut = new Yes(); - self::assertInvalidInput(new Yes(true), $input); + return [ + 'spanish' => [$sut, 'Si'], + 'portuguese' => [$sut, 'Sim'], + 'starting with "Y"' => [$sut, 'Yoo'], + 'boolean true' => [$sut, true], + 'array' => [$sut, ['Yes']], + 'object' => [$sut, new stdClass()], + 'int' => [$sut, random_int(1, PHP_INT_MAX)], + 'float' => [$sut, random_int(1, 9) / 10], + ]; } /**