diff --git a/.gitattributes b/.gitattributes index 84c7add05..c34694db5 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,3 +2,4 @@ /phpunit.xml.dist export-ignore /.gitattributes export-ignore /.gitignore export-ignore +/Resources/bin/sync-iban-formats.php export-ignore diff --git a/ConstraintValidator.php b/ConstraintValidator.php index 03ae15673..5d72f43fd 100644 --- a/ConstraintValidator.php +++ b/ConstraintValidator.php @@ -88,6 +88,10 @@ protected function formatValue(mixed $value, int $format = 0): string return $value->format('Y-m-d H:i:s'); } + if ($value instanceof \UnitEnum) { + return $value->name; + } + if (\is_object($value)) { if (($format & self::OBJECT_TO_STRING) && $value instanceof \Stringable) { return $value->__toString(); diff --git a/Constraints/AtLeastOneOfValidator.php b/Constraints/AtLeastOneOfValidator.php index 99de0a50d..36dc7667f 100644 --- a/Constraints/AtLeastOneOfValidator.php +++ b/Constraints/AtLeastOneOfValidator.php @@ -28,7 +28,11 @@ public function validate(mixed $value, Constraint $constraint) $validator = $this->context->getValidator(); - $messages = [$constraint->message]; + // Build a first violation to have the base message of the constraint translated + $baseMessageContext = clone $this->context; + $baseMessageContext->buildViolation($constraint->message)->addViolation(); + $baseViolations = $baseMessageContext->getViolations(); + $messages = [(string) $baseViolations->get(\count($baseViolations) - 1)->getMessage()]; foreach ($constraint->constraints as $key => $item) { if (!\in_array($this->context->getGroup(), $item->groups, true)) { diff --git a/Constraints/BicValidator.php b/Constraints/BicValidator.php index dcb1a90c0..f7e47353d 100644 --- a/Constraints/BicValidator.php +++ b/Constraints/BicValidator.php @@ -29,8 +29,9 @@ */ class BicValidator extends ConstraintValidator { + // Reference: https://www.iban.com/structure private const BIC_COUNTRY_TO_IBAN_COUNTRY_MAP = [ - // Reference: https://www.ecbs.org/iban/france-bank-account-number.html + // FR includes: 'GF' => 'FR', // French Guiana 'PF' => 'FR', // French Polynesia 'TF' => 'FR', // French Southern Territories @@ -39,13 +40,20 @@ class BicValidator extends ConstraintValidator 'YT' => 'FR', // Mayotte 'NC' => 'FR', // New Caledonia 'RE' => 'FR', // Reunion + 'BL' => 'FR', // Saint Barthelemy + 'MF' => 'FR', // Saint Martin (French part) 'PM' => 'FR', // Saint Pierre and Miquelon 'WF' => 'FR', // Wallis and Futuna Islands - // Reference: https://www.ecbs.org/iban/united-kingdom-uk-bank-account-number.html + // GB includes: 'JE' => 'GB', // Jersey 'IM' => 'GB', // Isle of Man 'GG' => 'GB', // Guernsey 'VG' => 'GB', // British Virgin Islands + // FI includes: + 'AX' => 'FI', // Aland Islands + // ES includes: + 'IC' => 'ES', // Canary Islands + 'EA' => 'ES', // Ceuta and Melilla ]; private ?PropertyAccessor $propertyAccessor; @@ -101,7 +109,8 @@ public function validate(mixed $value, Constraint $constraint) return; } - if (!Countries::exists(substr($canonicalize, 4, 2))) { + $bicCountryCode = substr($canonicalize, 4, 2); + if (!isset(self::BIC_COUNTRY_TO_IBAN_COUNTRY_MAP[$bicCountryCode]) && !Countries::exists($bicCountryCode)) { $this->context->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) ->setCode(Bic::INVALID_COUNTRY_CODE_ERROR) @@ -134,7 +143,7 @@ public function validate(mixed $value, Constraint $constraint) return; } $ibanCountryCode = substr($iban, 0, 2); - if (ctype_alpha($ibanCountryCode) && !$this->bicAndIbanCountriesMatch(substr($canonicalize, 4, 2), $ibanCountryCode)) { + if (ctype_alpha($ibanCountryCode) && !$this->bicAndIbanCountriesMatch($bicCountryCode, $ibanCountryCode)) { $this->context->buildViolation($constraint->ibanMessage) ->setParameter('{{ value }}', $this->formatValue($value)) ->setParameter('{{ iban }}', $iban) diff --git a/Constraints/Email.php b/Constraints/Email.php index 55399f977..c7205ec1f 100644 --- a/Constraints/Email.php +++ b/Constraints/Email.php @@ -29,7 +29,7 @@ class Email extends Constraint public const VALIDATION_MODE_HTML5 = 'html5'; public const VALIDATION_MODE_STRICT = 'strict'; /** - * @deprecated since Symfony 6.2 + * @deprecated since Symfony 6.2, use VALIDATION_MODE_HTML5 instead */ public const VALIDATION_MODE_LOOSE = 'loose'; @@ -74,7 +74,7 @@ public function __construct( $this->normalizer = $normalizer ?? $this->normalizer; if (self::VALIDATION_MODE_LOOSE === $this->mode) { - trigger_deprecation('symfony/validator', '6.2', 'The "%s" mode is deprecated. The default mode will be changed to "%s" in 7.0.', self::VALIDATION_MODE_LOOSE, self::VALIDATION_MODE_HTML5); + trigger_deprecation('symfony/validator', '6.2', 'The "%s" mode is deprecated. It will be removed in 7.0 and the default mode will be changed to "%s".', self::VALIDATION_MODE_LOOSE, self::VALIDATION_MODE_HTML5); } if (self::VALIDATION_MODE_STRICT === $this->mode && !class_exists(StrictEmailValidator::class)) { diff --git a/Constraints/EmailValidator.php b/Constraints/EmailValidator.php index df5cd1408..08210ce65 100644 --- a/Constraints/EmailValidator.php +++ b/Constraints/EmailValidator.php @@ -44,7 +44,7 @@ public function __construct(string $defaultMode = Email::VALIDATION_MODE_LOOSE) } if (Email::VALIDATION_MODE_LOOSE === $defaultMode) { - trigger_deprecation('symfony/validator', '6.2', 'The "%s" mode is deprecated. The default mode will be changed to "%s" in 7.0.', Email::VALIDATION_MODE_LOOSE, Email::VALIDATION_MODE_HTML5); + trigger_deprecation('symfony/validator', '6.2', 'The "%s" mode is deprecated. It will be removed in 7.0 and the default mode will be changed to "%s".', Email::VALIDATION_MODE_LOOSE, Email::VALIDATION_MODE_HTML5); } $this->defaultMode = $defaultMode; diff --git a/Constraints/IbanValidator.php b/Constraints/IbanValidator.php index 43b62b5d3..970051ae7 100644 --- a/Constraints/IbanValidator.php +++ b/Constraints/IbanValidator.php @@ -20,8 +20,6 @@ * @author Manuel Reinhard * @author Michael Schummel * @author Bernhard Schussek - * - * @see http://www.michael-schummel.de/2007/10/05/iban-prufung-mit-php/ */ class IbanValidator extends ConstraintValidator { @@ -34,107 +32,135 @@ class IbanValidator extends ConstraintValidator * a BBAN (Basic Bank Account Number) which has a fixed length per country and, * included within it, a bank identifier with a fixed position and a fixed length per country * - * @see https://www.swift.com/sites/default/files/resources/iban_registry.pdf + * @see Resources/bin/sync-iban-formats.php + * @see https://www.swift.com/swift-resource/11971/download?language=en + * @see https://en.wikipedia.org/wiki/International_Bank_Account_Number */ private const FORMATS = [ + // auto-generated 'AD' => 'AD\d{2}\d{4}\d{4}[\dA-Z]{12}', // Andorra - 'AE' => 'AE\d{2}\d{3}\d{16}', // United Arab Emirates + 'AE' => 'AE\d{2}\d{3}\d{16}', // United Arab Emirates (The) 'AL' => 'AL\d{2}\d{8}[\dA-Z]{16}', // Albania 'AO' => 'AO\d{2}\d{21}', // Angola 'AT' => 'AT\d{2}\d{5}\d{11}', // Austria - 'AX' => 'FI\d{2}\d{6}\d{7}\d{1}', // Aland Islands + 'AX' => 'FI\d{2}\d{3}\d{11}', // Finland 'AZ' => 'AZ\d{2}[A-Z]{4}[\dA-Z]{20}', // Azerbaijan 'BA' => 'BA\d{2}\d{3}\d{3}\d{8}\d{2}', // Bosnia and Herzegovina 'BE' => 'BE\d{2}\d{3}\d{7}\d{2}', // Belgium - 'BF' => 'BF\d{2}\d{23}', // Burkina Faso + 'BF' => 'BF\d{2}[\dA-Z]{2}\d{22}', // Burkina Faso 'BG' => 'BG\d{2}[A-Z]{4}\d{4}\d{2}[\dA-Z]{8}', // Bulgaria 'BH' => 'BH\d{2}[A-Z]{4}[\dA-Z]{14}', // Bahrain - 'BI' => 'BI\d{2}\d{12}', // Burundi - 'BJ' => 'BJ\d{2}[A-Z]{1}\d{23}', // Benin - 'BY' => 'BY\d{2}[\dA-Z]{4}\d{4}[\dA-Z]{16}', // Belarus - https://bank.codes/iban/structure/belarus/ - 'BL' => 'FR\d{2}\d{5}\d{5}[\dA-Z]{11}\d{2}', // Saint Barthelemy - 'BR' => 'BR\d{2}\d{8}\d{5}\d{10}[A-Z][\dA-Z]', // Brazil - 'CG' => 'CG\d{2}\d{23}', // Congo + 'BI' => 'BI\d{2}\d{5}\d{5}\d{11}\d{2}', // Burundi + 'BJ' => 'BJ\d{2}[\dA-Z]{2}\d{22}', // Benin + 'BL' => 'FR\d{2}\d{5}\d{5}[\dA-Z]{11}\d{2}', // France + 'BR' => 'BR\d{2}\d{8}\d{5}\d{10}[A-Z]{1}[\dA-Z]{1}', // Brazil + 'BY' => 'BY\d{2}[\dA-Z]{4}\d{4}[\dA-Z]{16}', // Republic of Belarus + 'CF' => 'CF\d{2}\d{23}', // Central African Republic + 'CG' => 'CG\d{2}\d{23}', // Congo, Republic of the 'CH' => 'CH\d{2}\d{5}[\dA-Z]{12}', // Switzerland - 'CI' => 'CI\d{2}[A-Z]{1}\d{23}', // Ivory Coast - 'CM' => 'CM\d{2}\d{23}', // Cameron - 'CR' => 'CR\d{2}0\d{3}\d{14}', // Costa Rica - 'CV' => 'CV\d{2}\d{21}', // Cape Verde + 'CI' => 'CI\d{2}[A-Z]{1}\d{23}', // Côte d'Ivoire + 'CM' => 'CM\d{2}\d{23}', // Cameroon + 'CR' => 'CR\d{2}\d{4}\d{14}', // Costa Rica + 'CV' => 'CV\d{2}\d{21}', // Cabo Verde 'CY' => 'CY\d{2}\d{3}\d{5}[\dA-Z]{16}', // Cyprus - 'CZ' => 'CZ\d{2}\d{20}', // Czech Republic + 'CZ' => 'CZ\d{2}\d{4}\d{6}\d{10}', // Czechia 'DE' => 'DE\d{2}\d{8}\d{10}', // Germany + 'DJ' => 'DJ\d{2}\d{5}\d{5}\d{11}\d{2}', // Djibouti + 'DK' => 'DK\d{2}\d{4}\d{9}\d{1}', // Denmark 'DO' => 'DO\d{2}[\dA-Z]{4}\d{20}', // Dominican Republic - 'DK' => 'DK\d{2}\d{4}\d{10}', // Denmark - 'DZ' => 'DZ\d{2}\d{20}', // Algeria + 'DZ' => 'DZ\d{2}\d{22}', // Algeria 'EE' => 'EE\d{2}\d{2}\d{2}\d{11}\d{1}', // Estonia - 'ES' => 'ES\d{2}\d{4}\d{4}\d{1}\d{1}\d{10}', // Spain (also includes Canary Islands, Ceuta and Melilla) - 'FI' => 'FI\d{2}\d{6}\d{7}\d{1}', // Finland + 'EG' => 'EG\d{2}\d{4}\d{4}\d{17}', // Egypt + 'ES' => 'ES\d{2}\d{4}\d{4}\d{1}\d{1}\d{10}', // Spain + 'FI' => 'FI\d{2}\d{3}\d{11}', // Finland 'FO' => 'FO\d{2}\d{4}\d{9}\d{1}', // Faroe Islands 'FR' => 'FR\d{2}\d{5}\d{5}[\dA-Z]{11}\d{2}', // France - 'GF' => 'FR\d{2}\d{5}\d{5}[\dA-Z]{11}\d{2}', // French Guyana - 'GB' => 'GB\d{2}[A-Z]{4}\d{6}\d{8}', // United Kingdom of Great Britain and Northern Ireland + 'GA' => 'GA\d{2}\d{23}', // Gabon + 'GB' => 'GB\d{2}[A-Z]{4}\d{6}\d{8}', // United Kingdom 'GE' => 'GE\d{2}[A-Z]{2}\d{16}', // Georgia + 'GF' => 'FR\d{2}\d{5}\d{5}[\dA-Z]{11}\d{2}', // France + 'GG' => 'GB\d{2}[A-Z]{4}\d{6}\d{8}', // United Kingdom 'GI' => 'GI\d{2}[A-Z]{4}[\dA-Z]{15}', // Gibraltar 'GL' => 'GL\d{2}\d{4}\d{9}\d{1}', // Greenland - 'GP' => 'FR\d{2}\d{5}\d{5}[\dA-Z]{11}\d{2}', // Guadeloupe + 'GP' => 'FR\d{2}\d{5}\d{5}[\dA-Z]{11}\d{2}', // France + 'GQ' => 'GQ\d{2}\d{23}', // Equatorial Guinea 'GR' => 'GR\d{2}\d{3}\d{4}[\dA-Z]{16}', // Greece 'GT' => 'GT\d{2}[\dA-Z]{4}[\dA-Z]{20}', // Guatemala + 'GW' => 'GW\d{2}[\dA-Z]{2}\d{19}', // Guinea-Bissau + 'HN' => 'HN\d{2}[A-Z]{4}\d{20}', // Honduras 'HR' => 'HR\d{2}\d{7}\d{10}', // Croatia 'HU' => 'HU\d{2}\d{3}\d{4}\d{1}\d{15}\d{1}', // Hungary 'IE' => 'IE\d{2}[A-Z]{4}\d{6}\d{8}', // Ireland 'IL' => 'IL\d{2}\d{3}\d{3}\d{13}', // Israel + 'IM' => 'GB\d{2}[A-Z]{4}\d{6}\d{8}', // United Kingdom + 'IQ' => 'IQ\d{2}[A-Z]{4}\d{3}\d{12}', // Iraq 'IR' => 'IR\d{2}\d{22}', // Iran 'IS' => 'IS\d{2}\d{4}\d{2}\d{6}\d{10}', // Iceland 'IT' => 'IT\d{2}[A-Z]{1}\d{5}\d{5}[\dA-Z]{12}', // Italy + 'JE' => 'GB\d{2}[A-Z]{4}\d{6}\d{8}', // United Kingdom 'JO' => 'JO\d{2}[A-Z]{4}\d{4}[\dA-Z]{18}', // Jordan - 'KW' => 'KW\d{2}[A-Z]{4}\d{22}', // KUWAIT + 'KM' => 'KM\d{2}\d{23}', // Comoros + 'KW' => 'KW\d{2}[A-Z]{4}[\dA-Z]{22}', // Kuwait 'KZ' => 'KZ\d{2}\d{3}[\dA-Z]{13}', // Kazakhstan - 'LB' => 'LB\d{2}\d{4}[\dA-Z]{20}', // LEBANON - 'LI' => 'LI\d{2}\d{5}[\dA-Z]{12}', // Liechtenstein (Principality of) + 'LB' => 'LB\d{2}\d{4}[\dA-Z]{20}', // Lebanon + 'LC' => 'LC\d{2}[A-Z]{4}[\dA-Z]{24}', // Saint Lucia + 'LI' => 'LI\d{2}\d{5}[\dA-Z]{12}', // Liechtenstein 'LT' => 'LT\d{2}\d{5}\d{11}', // Lithuania 'LU' => 'LU\d{2}\d{3}[\dA-Z]{13}', // Luxembourg 'LV' => 'LV\d{2}[A-Z]{4}[\dA-Z]{13}', // Latvia + 'LY' => 'LY\d{2}\d{3}\d{3}\d{15}', // Libya + 'MA' => 'MA\d{2}\d{24}', // Morocco 'MC' => 'MC\d{2}\d{5}\d{5}[\dA-Z]{11}\d{2}', // Monaco 'MD' => 'MD\d{2}[\dA-Z]{2}[\dA-Z]{18}', // Moldova 'ME' => 'ME\d{2}\d{3}\d{13}\d{2}', // Montenegro - 'MF' => 'FR\d{2}\d{5}\d{5}[\dA-Z]{11}\d{2}', // Saint Martin (French part) + 'MF' => 'FR\d{2}\d{5}\d{5}[\dA-Z]{11}\d{2}', // France 'MG' => 'MG\d{2}\d{23}', // Madagascar - 'MK' => 'MK\d{2}\d{3}[\dA-Z]{10}\d{2}', // Macedonia, Former Yugoslav Republic of - 'ML' => 'ML\d{2}[A-Z]{1}\d{23}', // Mali - 'MQ' => 'FR\d{2}\d{5}\d{5}[\dA-Z]{11}\d{2}', // Martinique + 'MK' => 'MK\d{2}\d{3}[\dA-Z]{10}\d{2}', // Macedonia + 'ML' => 'ML\d{2}[\dA-Z]{2}\d{22}', // Mali + 'MQ' => 'FR\d{2}\d{5}\d{5}[\dA-Z]{11}\d{2}', // France 'MR' => 'MR\d{2}\d{5}\d{5}\d{11}\d{2}', // Mauritania 'MT' => 'MT\d{2}[A-Z]{4}\d{5}[\dA-Z]{18}', // Malta 'MU' => 'MU\d{2}[A-Z]{4}\d{2}\d{2}\d{12}\d{3}[A-Z]{3}', // Mauritius 'MZ' => 'MZ\d{2}\d{21}', // Mozambique - 'NC' => 'FR\d{2}\d{5}\d{5}[\dA-Z]{11}\d{2}', // New Caledonia - 'NL' => 'NL\d{2}[A-Z]{4}\d{10}', // The Netherlands + 'NC' => 'FR\d{2}\d{5}\d{5}[\dA-Z]{11}\d{2}', // France + 'NE' => 'NE\d{2}[A-Z]{2}\d{22}', // Niger + 'NI' => 'NI\d{2}[A-Z]{4}\d{24}', // Nicaragua + 'NL' => 'NL\d{2}[A-Z]{4}\d{10}', // Netherlands (The) 'NO' => 'NO\d{2}\d{4}\d{6}\d{1}', // Norway - 'PF' => 'FR\d{2}\d{5}\d{5}[\dA-Z]{11}\d{2}', // French Polynesia + 'PF' => 'FR\d{2}\d{5}\d{5}[\dA-Z]{11}\d{2}', // France 'PK' => 'PK\d{2}[A-Z]{4}[\dA-Z]{16}', // Pakistan 'PL' => 'PL\d{2}\d{8}\d{16}', // Poland - 'PM' => 'FR\d{2}\d{5}\d{5}[\dA-Z]{11}\d{2}', // Saint Pierre et Miquelon + 'PM' => 'FR\d{2}\d{5}\d{5}[\dA-Z]{11}\d{2}', // France 'PS' => 'PS\d{2}[A-Z]{4}[\dA-Z]{21}', // Palestine, State of - 'PT' => 'PT\d{2}\d{4}\d{4}\d{11}\d{2}', // Portugal (plus Azores and Madeira) + 'PT' => 'PT\d{2}\d{4}\d{4}\d{11}\d{2}', // Portugal 'QA' => 'QA\d{2}[A-Z]{4}[\dA-Z]{21}', // Qatar - 'RE' => 'FR\d{2}\d{5}\d{5}[\dA-Z]{11}\d{2}', // Reunion + 'RE' => 'FR\d{2}\d{5}\d{5}[\dA-Z]{11}\d{2}', // France 'RO' => 'RO\d{2}[A-Z]{4}[\dA-Z]{16}', // Romania 'RS' => 'RS\d{2}\d{3}\d{13}\d{2}', // Serbia + 'RU' => 'RU\d{2}\d{9}\d{5}[\dA-Z]{15}', // Russia 'SA' => 'SA\d{2}\d{2}[\dA-Z]{18}', // Saudi Arabia + 'SC' => 'SC\d{2}[A-Z]{4}\d{2}\d{2}\d{16}[A-Z]{3}', // Seychelles + 'SD' => 'SD\d{2}\d{2}\d{12}', // Sudan 'SE' => 'SE\d{2}\d{3}\d{16}\d{1}', // Sweden 'SI' => 'SI\d{2}\d{5}\d{8}\d{2}', // Slovenia - 'SK' => 'SK\d{2}\d{4}\d{6}\d{10}', // Slovak Republic + 'SK' => 'SK\d{2}\d{4}\d{6}\d{10}', // Slovakia 'SM' => 'SM\d{2}[A-Z]{1}\d{5}\d{5}[\dA-Z]{12}', // San Marino - 'SN' => 'SN\d{2}[A-Z]{1}\d{23}', // Senegal - 'TF' => 'FR\d{2}\d{5}\d{5}[\dA-Z]{11}\d{2}', // French Southern Territories + 'SN' => 'SN\d{2}[A-Z]{2}\d{22}', // Senegal + 'SO' => 'SO\d{2}\d{4}\d{3}\d{12}', // Somalia + 'ST' => 'ST\d{2}\d{4}\d{4}\d{11}\d{2}', // Sao Tome and Principe + 'SV' => 'SV\d{2}[A-Z]{4}\d{20}', // El Salvador + 'TD' => 'TD\d{2}\d{23}', // Chad + 'TF' => 'FR\d{2}\d{5}\d{5}[\dA-Z]{11}\d{2}', // France + 'TG' => 'TG\d{2}[A-Z]{2}\d{22}', // Togo 'TL' => 'TL\d{2}\d{3}\d{14}\d{2}', // Timor-Leste 'TN' => 'TN\d{2}\d{2}\d{3}\d{13}\d{2}', // Tunisia - 'TR' => 'TR\d{2}\d{5}[\dA-Z]{1}[\dA-Z]{16}', // Turkey + 'TR' => 'TR\d{2}\d{5}\d{1}[\dA-Z]{16}', // Turkey 'UA' => 'UA\d{2}\d{6}[\dA-Z]{19}', // Ukraine 'VA' => 'VA\d{2}\d{3}\d{15}', // Vatican City State - 'VG' => 'VG\d{2}[A-Z]{4}\d{16}', // Virgin Islands, British - 'WF' => 'FR\d{2}\d{5}\d{5}[\dA-Z]{11}\d{2}', // Wallis and Futuna Islands - 'XK' => 'XK\d{2}\d{4}\d{10}\d{2}', // Republic of Kosovo - 'YT' => 'FR\d{2}\d{5}\d{5}[\dA-Z]{11}\d{2}', // Mayotte + 'VG' => 'VG\d{2}[A-Z]{4}\d{16}', // Virgin Islands + 'WF' => 'FR\d{2}\d{5}\d{5}[\dA-Z]{11}\d{2}', // France + 'XK' => 'XK\d{2}\d{4}\d{10}\d{2}', // Kosovo + 'YT' => 'FR\d{2}\d{5}\d{5}[\dA-Z]{11}\d{2}', // France ]; public function validate(mixed $value, Constraint $constraint) diff --git a/LICENSE b/LICENSE index 008370457..0138f8f07 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2004-2023 Fabien Potencier +Copyright (c) 2004-present Fabien Potencier Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Resources/bin/sync-iban-formats.php b/Resources/bin/sync-iban-formats.php new file mode 100755 index 000000000..fa7ba520c --- /dev/null +++ b/Resources/bin/sync-iban-formats.php @@ -0,0 +1,204 @@ +#!/usr/bin/env php + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +if ('cli' !== \PHP_SAPI) { + throw new \Exception('This script must be run from the command line.'); +} + +/* + * This script syncs IBAN formats from the upstream and updates them into IbanValidator. + * + * Usage: + * php Resources/bin/sync-iban-formats.php + */ + +error_reporting(\E_ALL); + +set_error_handler(static function (int $type, string $msg, string $file, int $line): void { + throw new \ErrorException($msg, 0, $type, $file, $line); +}); + +echo "Collecting IBAN formats...\n"; + +$formats = array_merge( + (new WikipediaIbanProvider())->getIbanFormats(), + (new SwiftRegistryIbanProvider())->getIbanFormats() +); + +printf("Collected %d IBAN formats\n", count($formats)); + +echo "Updating validator...\n"; + +updateValidatorFormats(__DIR__.'/../../Constraints/IbanValidator.php', $formats); + +echo "Done.\n"; + +exit(0); + +function updateValidatorFormats(string $validatorPath, array $formats): void +{ + ksort($formats); + + $formatsContent = "[\n"; + $formatsContent .= " // auto-generated\n"; + + foreach ($formats as $countryCode => [$format, $country]) { + $formatsContent .= " '{$countryCode}' => '{$format}', // {$country}\n"; + } + + $formatsContent .= ' ]'; + + $validatorContent = file_get_contents($validatorPath); + + $validatorContent = preg_replace( + '/FORMATS = \[.*?\];/s', + "FORMATS = {$formatsContent};", + $validatorContent + ); + + file_put_contents($validatorPath, $validatorContent); +} + +final class SwiftRegistryIbanProvider +{ + /** + * @return array + */ + public function getIbanFormats(): array + { + $items = $this->readPropertiesFromRegistry([ + 'Name of country' => 'country', + 'IBAN prefix country code (ISO 3166)' => 'country_code', + 'IBAN structure' => 'iban_structure', + 'Country code includes other countries/territories' => 'included_country_codes', + ]); + + $formats = []; + + foreach ($items as $item) { + $formats[$item['country_code']] = [$this->buildIbanRegexp($item['iban_structure']), $item['country']]; + + foreach ($this->parseCountryCodesList($item['included_country_codes']) as $includedCountryCode) { + $formats[$includedCountryCode] = $formats[$item['country_code']]; + } + } + + return $formats; + } + + /** + * @return list + */ + private function parseCountryCodesList(string $countryCodesList): array + { + if ('N/A' === $countryCodesList) { + return []; + } + + $countryCodes = []; + + foreach (explode(',', $countryCodesList) as $countryCode) { + $countryCodes[] = preg_replace('/^([A-Z]{2})(\s+\(.+?\))?$/', '$1', trim($countryCode)); + } + + return $countryCodes; + } + + /** + * @param array $properties + * + * @return list> + */ + private function readPropertiesFromRegistry(array $properties): array + { + $items = []; + + $registryContent = file_get_contents('https://www.swift.com/swift-resource/11971/download'); + $lines = explode("\n", $registryContent); + + // skip header line + array_shift($lines); + + foreach ($lines as $line) { + $columns = str_getcsv($line, "\t"); + $propertyLabel = array_shift($columns); + + if (!isset($properties[$propertyLabel])) { + continue; + } + + $propertyField = $properties[$propertyLabel]; + + foreach ($columns as $index => $value) { + $items[$index][$propertyField] = $value; + } + } + + return array_values($items); + } + + private function buildIbanRegexp(string $ibanStructure): string + { + $pattern = $ibanStructure; + + $pattern = preg_replace('/(\d+)!n/', '\\d{$1}', $pattern); + $pattern = preg_replace('/(\d+)!a/', '[A-Z]{$1}', $pattern); + $pattern = preg_replace('/(\d+)!c/', '[\\dA-Z]{$1}', $pattern); + + return $pattern; + } +} + +final class WikipediaIbanProvider +{ + /** + * @return array + */ + public function getIbanFormats(): array + { + $formats = []; + + foreach ($this->readIbanFormatsTable() as $item) { + if (!preg_match('/^([A-Z]{2})/', $item['Example'], $matches)) { + continue; + } + + $countryCode = $matches[1]; + + $formats[$countryCode] = [$this->buildIbanRegexp($countryCode, $item['BBAN Format']), $item['Country']]; + } + + return $formats; + } + + /** + * @return list> + */ + private function readIbanFormatsTable(): array + { + $tablesResponse = file_get_contents('https://www.wikitable2json.com/api/International_Bank_Account_Number?table=3&keyRows=1&clearRef=true'); + + return json_decode($tablesResponse, true, 512, JSON_THROW_ON_ERROR)[0]; + } + + private function buildIbanRegexp(string $countryCode, string $bbanFormat): string + { + $pattern = $bbanFormat; + + $pattern = preg_replace('/\s*,\s*/', '', $pattern); + $pattern = preg_replace('/(\d+)n/', '\\d{$1}', $pattern); + $pattern = preg_replace('/(\d+)a/', '[A-Z]{$1}', $pattern); + $pattern = preg_replace('/(\d+)c/', '[\\dA-Z]{$1}', $pattern); + + return $countryCode.'\\d{2}'.$pattern; + } +} diff --git a/Resources/translations/validators.de.xlf b/Resources/translations/validators.de.xlf index 1c6d0c6c9..7f9a34a71 100644 --- a/Resources/translations/validators.de.xlf +++ b/Resources/translations/validators.de.xlf @@ -402,6 +402,10 @@ The value of the netmask should be between {{ min }} and {{ max }}. Der Wert der Subnetzmaske sollte zwischen {{ min }} und {{ max }} liegen. + + The filename is too long. It should have {{ filename_max_length }} character or less.|The filename is too long. It should have {{ filename_max_length }} characters or less. + Der Dateiname ist zu lang. Er sollte nicht länger als {{ filename_max_length }} Zeichen sein.|Der Dateiname ist zu lang. Er sollte nicht länger als {{ filename_max_length }} Zeichen sein. + diff --git a/Resources/translations/validators.en.xlf b/Resources/translations/validators.en.xlf index 34c54212d..f6772fdfb 100644 --- a/Resources/translations/validators.en.xlf +++ b/Resources/translations/validators.en.xlf @@ -402,6 +402,10 @@ The value of the netmask should be between {{ min }} and {{ max }}. The value of the netmask should be between {{ min }} and {{ max }}. + + The filename is too long. It should have {{ filename_max_length }} character or less.|The filename is too long. It should have {{ filename_max_length }} characters or less. + The filename is too long. It should have {{ filename_max_length }} character or less.|The filename is too long. It should have {{ filename_max_length }} characters or less. + diff --git a/Test/ConstraintValidatorTestCase.php b/Test/ConstraintValidatorTestCase.php index d9bb9bd39..744a2cd72 100644 --- a/Test/ConstraintValidatorTestCase.php +++ b/Test/ConstraintValidatorTestCase.php @@ -133,16 +133,18 @@ protected function createContext() $context->setNode($this->value, $this->object, $this->metadata, $this->propertyPath); $context->setConstraint($this->constraint); - $contextualValidator = $this->getMockBuilder(AssertingContextualValidator::class) - ->setConstructorArgs([$context]) - ->setMethods([ - 'atPath', - 'validate', - 'validateProperty', - 'validatePropertyValue', - 'getViolations', - ]) - ->getMock(); + $contextualValidatorMockBuilder = $this->getMockBuilder(AssertingContextualValidator::class) + ->setConstructorArgs([$context]); + $contextualValidatorMethods = [ + 'atPath', + 'validate', + 'validateProperty', + 'validatePropertyValue', + 'getViolations', + ]; + + $contextualValidatorMockBuilder->onlyMethods($contextualValidatorMethods); + $contextualValidator = $contextualValidatorMockBuilder->getMock(); $contextualValidator->expects($this->any()) ->method('atPath') ->willReturnCallback(function ($path) use ($contextualValidator) { diff --git a/Tests/ConstraintValidatorTest.php b/Tests/ConstraintValidatorTest.php index 698029f02..c60550184 100644 --- a/Tests/ConstraintValidatorTest.php +++ b/Tests/ConstraintValidatorTest.php @@ -14,6 +14,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; +use Symfony\Component\Validator\Tests\Fixtures\TestEnum; class ConstraintValidatorTest extends TestCase { @@ -27,7 +28,7 @@ public function testFormatValue($expected, $value, $format = 0) $this->assertSame($expected, (new TestFormatValueConstraintValidator())->formatValueProxy($value, $format)); } - public function formatValueProvider() + public static function formatValueProvider() { $defaultTimezone = date_default_timezone_get(); date_default_timezone_set('Europe/Moscow'); // GMT+3 @@ -48,6 +49,10 @@ public function formatValueProvider() [class_exists(\IntlDateFormatter::class) ? 'Jan 1, 1970, 3:00 PM' : '1970-01-01 15:00:00', (new \DateTimeImmutable('1970-01-01T23:00:00'))->setTimezone(new \DateTimeZone('America/New_York')), ConstraintValidator::PRETTY_DATE], ]; + if (\PHP_VERSION_ID >= 80100) { + $data[] = ['FirstCase', TestEnum::FirstCase]; + } + date_default_timezone_set($defaultTimezone); return $data; diff --git a/Tests/ConstraintViolationListTest.php b/Tests/ConstraintViolationListTest.php index effaab06d..3aabf7a21 100644 --- a/Tests/ConstraintViolationListTest.php +++ b/Tests/ConstraintViolationListTest.php @@ -146,7 +146,7 @@ public function testFindByCodes($code, $violationsCount) $this->assertCount($violationsCount, $specificErrors); } - public function findByCodesProvider() + public static function findByCodesProvider() { return [ ['code1', 2], diff --git a/Tests/Constraints/AbstractComparisonValidatorTestCase.php b/Tests/Constraints/AbstractComparisonValidatorTestCase.php index c6bbbf76b..5b9100cd4 100644 --- a/Tests/Constraints/AbstractComparisonValidatorTestCase.php +++ b/Tests/Constraints/AbstractComparisonValidatorTestCase.php @@ -69,7 +69,7 @@ protected static function addPhp5Dot5Comparisons(array $comparisons) return $result; } - public function provideInvalidConstraintOptions() + public static function provideInvalidConstraintOptions() { return [ [null], @@ -109,15 +109,16 @@ public function testValidComparisonToValue($dirtyValue, $comparisonValue) $this->assertNoViolation(); } - public function provideAllValidComparisons(): array + public static function provideAllValidComparisons(): array { // The provider runs before setUp(), so we need to manually fix // the default timezone - $this->setDefaultTimezone('UTC'); + $timezone = date_default_timezone_get(); + date_default_timezone_set('UTC'); - $comparisons = self::addPhp5Dot5Comparisons($this->provideValidComparisons()); + $comparisons = self::addPhp5Dot5Comparisons(static::provideValidComparisons()); - $this->restoreDefaultTimezone(); + date_default_timezone_set($timezone); return $comparisons; } @@ -163,9 +164,9 @@ public function testInvalidValuePath() $this->validator->validate(5, $constraint); } - abstract public function provideValidComparisons(): array; + abstract public static function provideValidComparisons(): array; - abstract public function provideValidComparisonsToPropertyPath(): array; + abstract public static function provideValidComparisonsToPropertyPath(): array; /** * @dataProvider provideAllInvalidComparisons @@ -224,9 +225,9 @@ public function testThrowsOnInvalidStringDates(AbstractComparison $constraint, $ $this->validator->validate($value, $constraint); } - public function throwsOnInvalidStringDatesProvider(): array + public static function throwsOnInvalidStringDatesProvider(): array { - $constraint = $this->createConstraint([ + $constraint = static::createConstraint([ 'value' => 'foo', ]); @@ -264,24 +265,25 @@ public function testCompareWithNullValueAtPropertyAt($dirtyValue, $dirtyValueAsS } } - public function provideAllInvalidComparisons(): array + public static function provideAllInvalidComparisons(): array { // The provider runs before setUp(), so we need to manually fix // the default timezone - $this->setDefaultTimezone('UTC'); + $timezone = date_default_timezone_get(); + date_default_timezone_set('UTC'); - $comparisons = self::addPhp5Dot5Comparisons($this->provideInvalidComparisons()); + $comparisons = self::addPhp5Dot5Comparisons(static::provideInvalidComparisons()); - $this->restoreDefaultTimezone(); + date_default_timezone_set($timezone); return $comparisons; } - abstract public function provideInvalidComparisons(): array; + abstract public static function provideInvalidComparisons(): array; - abstract public function provideComparisonsToNullValueAtPropertyPath(); + abstract public static function provideComparisonsToNullValueAtPropertyPath(); - abstract protected function createConstraint(array $options = null): Constraint; + abstract protected static function createConstraint(array $options = null): Constraint; protected function getErrorCode(): ?string { diff --git a/Tests/Constraints/AllValidatorTest.php b/Tests/Constraints/AllValidatorTest.php index b25434597..65dae6275 100644 --- a/Tests/Constraints/AllValidatorTest.php +++ b/Tests/Constraints/AllValidatorTest.php @@ -77,7 +77,7 @@ public function testWalkMultipleConstraints($array) $this->assertNoViolation(); } - public function getValidArguments() + public static function getValidArguments() { return [ [[5, 6, 7]], diff --git a/Tests/Constraints/AtLeastOneOfValidatorTest.php b/Tests/Constraints/AtLeastOneOfValidatorTest.php index c3522f3dc..6c4fe6f9e 100644 --- a/Tests/Constraints/AtLeastOneOfValidatorTest.php +++ b/Tests/Constraints/AtLeastOneOfValidatorTest.php @@ -22,6 +22,7 @@ use Symfony\Component\Validator\Constraints\GreaterThan; use Symfony\Component\Validator\Constraints\GreaterThanOrEqual; use Symfony\Component\Validator\Constraints\IdenticalTo; +use Symfony\Component\Validator\Constraints\IsNull; use Symfony\Component\Validator\Constraints\Language; use Symfony\Component\Validator\Constraints\Length; use Symfony\Component\Validator\Constraints\LessThan; @@ -37,6 +38,9 @@ use Symfony\Component\Validator\Mapping\MetadataInterface; use Symfony\Component\Validator\Test\ConstraintValidatorTestCase; use Symfony\Component\Validator\Validation; +use Symfony\Contracts\Translation\LocaleAwareInterface; +use Symfony\Contracts\Translation\TranslatorInterface; +use Symfony\Contracts\Translation\TranslatorTrait; /** * @author Przemysław Bogusz @@ -56,7 +60,7 @@ public function testValidCombinations($value, $constraints) $this->assertCount(0, Validation::createValidator()->validate($value, new AtLeastOneOf($constraints))); } - public function getValidCombinations() + public static function getValidCombinations() { return [ ['symfony', [ @@ -125,7 +129,7 @@ public function testInvalidCombinationsWithCustomMessage($value, $constraints) $this->assertEquals(new ConstraintViolation('foo', 'foo', [], $value, '', $value, null, AtLeastOneOf::AT_LEAST_ONE_OF_ERROR, $atLeastOneOf), $violations->get(0)); } - public function getInvalidCombinations() + public static function getInvalidCombinations() { return [ ['symphony', [ @@ -258,6 +262,40 @@ public function testNestedConstraintsAreNotExecutedWhenGroupDoesNotMatch() $this->assertCount(1, $violations); } + + public function testTranslatorIsCalledOnConstraintBaseMessageAndViolations() + { + $translator = new class() implements TranslatorInterface, LocaleAwareInterface { + use TranslatorTrait; + + public function trans(?string $id, array $parameters = [], string $domain = null, string $locale = null): string + { + if ('This value should satisfy at least one of the following constraints:' === $id) { + return 'Dummy translation:'; + } + + if ('This value should be null.' === $id) { + return 'Dummy violation.'; + } + + return $id; + } + }; + + $validator = Validation::createValidatorBuilder() + ->setTranslator($translator) + ->getValidator() + ; + + $violations = $validator->validate('Test', [ + new AtLeastOneOf([ + new IsNull(), + ]), + ]); + + $this->assertCount(1, $violations); + $this->assertSame('Dummy translation: [1] Dummy violation.', $violations->get(0)->getMessage()); + } } class ExpressionConstraintNested diff --git a/Tests/Constraints/BicValidatorTest.php b/Tests/Constraints/BicValidatorTest.php index c1a8dbf79..c6b474ad3 100644 --- a/Tests/Constraints/BicValidatorTest.php +++ b/Tests/Constraints/BicValidatorTest.php @@ -188,7 +188,7 @@ public function testValidBics($bic) $this->assertNoViolation(); } - public function getValidBics() + public static function getValidBics() { // http://formvalidation.io/validators/bic/ return [ @@ -233,7 +233,7 @@ public function testInvalidBicsNamed($bic, $code) ->assertRaised(); } - public function getInvalidBics() + public static function getInvalidBics() { return [ ['DEUTD', Bic::INVALID_LENGTH_ERROR], @@ -277,7 +277,7 @@ public function testValidBicSpecialCases(string $bic, string $iban) $this->assertNoViolation(); } - public function getValidBicSpecialCases() + public static function getValidBicSpecialCases() { // FR related special cases yield ['BNPAGFGX', 'FR14 2004 1010 0505 0001 3M02 606']; @@ -288,6 +288,8 @@ public function getValidBicSpecialCases() yield ['BNPAYTGX', 'FR14 2004 1010 0505 0001 3M02 606']; yield ['BNPANCGX', 'FR14 2004 1010 0505 0001 3M02 606']; yield ['BNPAREGX', 'FR14 2004 1010 0505 0001 3M02 606']; + yield ['BNPABLGX', 'FR14 2004 1010 0505 0001 3M02 606']; + yield ['BNPAMFGX', 'FR14 2004 1010 0505 0001 3M02 606']; yield ['BNPAPMGX', 'FR14 2004 1010 0505 0001 3M02 606']; yield ['BNPAWFGX', 'FR14 2004 1010 0505 0001 3M02 606']; @@ -296,6 +298,13 @@ public function getValidBicSpecialCases() yield ['BARCIMSA', 'GB12 CPBK 0892 9965 0449 911']; yield ['BARCGGSA', 'GB12 CPBK 0892 9965 0449 911']; yield ['BARCVGSA', 'GB12 CPBK 0892 9965 0449 911']; + + // FI related special cases + yield ['NDEAAXHH', 'FI14 1009 3000 1234 58']; + + // ES related special cases + yield ['CAIXICBBXXX', 'ES79 2100 0813 6101 2345 6789']; + yield ['CAIXEABBXXX', 'ES79 2100 0813 6101 2345 6789']; } } diff --git a/Tests/Constraints/BlankValidatorTest.php b/Tests/Constraints/BlankValidatorTest.php index 4f36da5db..9643c6793 100644 --- a/Tests/Constraints/BlankValidatorTest.php +++ b/Tests/Constraints/BlankValidatorTest.php @@ -53,7 +53,7 @@ public function testInvalidValues($value, $valueAsString) ->assertRaised(); } - public function getInvalidValues() + public static function getInvalidValues() { return [ ['foobar', '"foobar"'], diff --git a/Tests/Constraints/CardSchemeValidatorTest.php b/Tests/Constraints/CardSchemeValidatorTest.php index 1a2d931a5..7b28ca9dd 100644 --- a/Tests/Constraints/CardSchemeValidatorTest.php +++ b/Tests/Constraints/CardSchemeValidatorTest.php @@ -87,7 +87,7 @@ public function testInvalidNumberNamedArguments() ->assertRaised(); } - public function getValidNumbers() + public static function getValidNumbers() { return [ ['AMEX', '378282246310005'], @@ -142,7 +142,7 @@ public function getValidNumbers() ]; } - public function getInvalidNumbers() + public static function getInvalidNumbers() { return [ ['VISA', '42424242424242424242', CardScheme::INVALID_FORMAT_ERROR], diff --git a/Tests/Constraints/ChoiceValidatorTest.php b/Tests/Constraints/ChoiceValidatorTest.php index 38582d85d..88d11fe8d 100644 --- a/Tests/Constraints/ChoiceValidatorTest.php +++ b/Tests/Constraints/ChoiceValidatorTest.php @@ -84,7 +84,7 @@ public function testValidChoiceArray(Choice $constraint) $this->assertNoViolation(); } - public function provideConstraintsWithChoicesArray(): iterable + public static function provideConstraintsWithChoicesArray(): iterable { yield 'Doctrine style' => [new Choice(['choices' => ['foo', 'bar']])]; yield 'Doctrine default option' => [new Choice(['value' => ['foo', 'bar']])]; @@ -102,7 +102,7 @@ public function testValidChoiceCallbackFunction(Choice $constraint) $this->assertNoViolation(); } - public function provideConstraintsWithCallbackFunction(): iterable + public static function provideConstraintsWithCallbackFunction(): iterable { yield 'doctrine style, namespaced function' => [new Choice(['callback' => __NAMESPACE__.'\choice_callback'])]; yield 'doctrine style, closure' => [new Choice([ @@ -150,7 +150,7 @@ public function testMultipleChoices(Choice $constraint) $this->assertNoViolation(); } - public function provideConstraintsWithMultipleTrue(): iterable + public static function provideConstraintsWithMultipleTrue(): iterable { yield 'Doctrine style' => [new Choice([ 'choices' => ['foo', 'bar', 'baz'], @@ -176,7 +176,7 @@ public function testInvalidChoice(Choice $constraint) ->assertRaised(); } - public function provideConstraintsWithMessage(): iterable + public static function provideConstraintsWithMessage(): iterable { yield 'Doctrine style' => [new Choice(['choices' => ['foo', 'bar'], 'message' => 'myMessage'])]; yield 'named arguments' => [new Choice(choices: ['foo', 'bar'], message: 'myMessage')]; @@ -215,7 +215,7 @@ public function testInvalidChoiceMultiple(Choice $constraint) ->assertRaised(); } - public function provideConstraintsWithMultipleMessage(): iterable + public static function provideConstraintsWithMultipleMessage(): iterable { yield 'Doctrine style' => [new Choice([ 'choices' => ['foo', 'bar'], @@ -248,7 +248,7 @@ public function testTooFewChoices(Choice $constraint) ->assertRaised(); } - public function provideConstraintsWithMin(): iterable + public static function provideConstraintsWithMin(): iterable { yield 'Doctrine style' => [new Choice([ 'choices' => ['foo', 'bar', 'moo', 'maa'], @@ -283,7 +283,7 @@ public function testTooManyChoices(Choice $constraint) ->assertRaised(); } - public function provideConstraintsWithMax(): iterable + public static function provideConstraintsWithMax(): iterable { yield 'Doctrine style' => [new Choice([ 'choices' => ['foo', 'bar', 'moo', 'maa'], diff --git a/Tests/Constraints/CidrTest.php b/Tests/Constraints/CidrTest.php index 674f57dbf..33ce5bdc7 100644 --- a/Tests/Constraints/CidrTest.php +++ b/Tests/Constraints/CidrTest.php @@ -90,7 +90,7 @@ public function testWithInvalidMinMaxValues(string $ipVersion, int $netmaskMin, ]); } - public function getInvalidMinMaxValues(): array + public static function getInvalidMinMaxValues(): array { return [ [Ip::ALL, -1, 23], @@ -108,7 +108,7 @@ public function getInvalidMinMaxValues(): array ]; } - public function getValidMinMaxValues(): array + public static function getValidMinMaxValues(): array { return [ [Ip::ALL, 0, 23], diff --git a/Tests/Constraints/CidrValidatorTest.php b/Tests/Constraints/CidrValidatorTest.php index c522335a8..7c5745ee6 100644 --- a/Tests/Constraints/CidrValidatorTest.php +++ b/Tests/Constraints/CidrValidatorTest.php @@ -135,7 +135,7 @@ public function testWrongVersion(string $cidr, string $version) ->assertRaised(); } - public function getWithInvalidIps(): array + public static function getWithInvalidIps(): array { return [ ['0/20'], @@ -164,7 +164,7 @@ public function getWithInvalidIps(): array ]; } - public function getValid(): array + public static function getValid(): array { return [ ['127.0.0.0/32', Ip::ALL], @@ -198,7 +198,7 @@ public function getValid(): array ]; } - public function getWithInvalidNetmask(): array + public static function getWithInvalidNetmask(): array { return [ ['192.168.1.0/-1'], @@ -217,7 +217,7 @@ public function getWithInvalidNetmask(): array ]; } - public function getWithInvalidMasksAndIps(): array + public static function getWithInvalidMasksAndIps(): array { return [ ['0.0.0.0/foobar'], @@ -236,7 +236,7 @@ public function getWithInvalidMasksAndIps(): array ]; } - public function getOutOfRangeNetmask(): array + public static function getOutOfRangeNetmask(): array { return [ ['10.0.0.0/24', Ip::V4, 10, 20], @@ -244,7 +244,7 @@ public function getOutOfRangeNetmask(): array ]; } - public function getWithWrongVersion(): array + public static function getWithWrongVersion(): array { return [ ['2001:0db8:85a3:0000:0000:8a2e:0370:7334/12', Ip::V4], diff --git a/Tests/Constraints/CollectionValidatorArrayObjectTest.php b/Tests/Constraints/CollectionValidatorArrayObjectTest.php index a3c4b3340..da68d42d9 100644 --- a/Tests/Constraints/CollectionValidatorArrayObjectTest.php +++ b/Tests/Constraints/CollectionValidatorArrayObjectTest.php @@ -11,7 +11,7 @@ namespace Symfony\Component\Validator\Tests\Constraints; -class CollectionValidatorArrayObjectTest extends CollectionValidatorTest +class CollectionValidatorArrayObjectTest extends CollectionValidatorTestCase { public function prepareTestData(array $contents) { diff --git a/Tests/Constraints/CollectionValidatorArrayTest.php b/Tests/Constraints/CollectionValidatorArrayTest.php index 7517d0ce3..993a87071 100644 --- a/Tests/Constraints/CollectionValidatorArrayTest.php +++ b/Tests/Constraints/CollectionValidatorArrayTest.php @@ -11,7 +11,7 @@ namespace Symfony\Component\Validator\Tests\Constraints; -class CollectionValidatorArrayTest extends CollectionValidatorTest +class CollectionValidatorArrayTest extends CollectionValidatorTestCase { public function prepareTestData(array $contents) { diff --git a/Tests/Constraints/CollectionValidatorCustomArrayObjectTest.php b/Tests/Constraints/CollectionValidatorCustomArrayObjectTest.php index 3d4c29681..bfb9af29a 100644 --- a/Tests/Constraints/CollectionValidatorCustomArrayObjectTest.php +++ b/Tests/Constraints/CollectionValidatorCustomArrayObjectTest.php @@ -13,7 +13,7 @@ use Symfony\Component\Validator\Tests\Fixtures\CustomArrayObject; -class CollectionValidatorCustomArrayObjectTest extends CollectionValidatorTest +class CollectionValidatorCustomArrayObjectTest extends CollectionValidatorTestCase { public function prepareTestData(array $contents) { diff --git a/Tests/Constraints/CollectionValidatorTest.php b/Tests/Constraints/CollectionValidatorTestCase.php similarity index 99% rename from Tests/Constraints/CollectionValidatorTest.php rename to Tests/Constraints/CollectionValidatorTestCase.php index a98379a80..92260e966 100644 --- a/Tests/Constraints/CollectionValidatorTest.php +++ b/Tests/Constraints/CollectionValidatorTestCase.php @@ -20,7 +20,7 @@ use Symfony\Component\Validator\Exception\UnexpectedValueException; use Symfony\Component\Validator\Test\ConstraintValidatorTestCase; -abstract class CollectionValidatorTest extends ConstraintValidatorTestCase +abstract class CollectionValidatorTestCase extends ConstraintValidatorTestCase { protected function createValidator(): CollectionValidator { diff --git a/Tests/Constraints/CountValidatorArrayTest.php b/Tests/Constraints/CountValidatorArrayTest.php index 5f562e744..1f441ea13 100644 --- a/Tests/Constraints/CountValidatorArrayTest.php +++ b/Tests/Constraints/CountValidatorArrayTest.php @@ -14,9 +14,9 @@ /** * @author Bernhard Schussek */ -class CountValidatorArrayTest extends CountValidatorTest +class CountValidatorArrayTest extends CountValidatorTestCase { - protected function createCollection(array $content) + protected static function createCollection(array $content) { return $content; } diff --git a/Tests/Constraints/CountValidatorCountableTest.php b/Tests/Constraints/CountValidatorCountableTest.php index 7d46967bd..48a8063e5 100644 --- a/Tests/Constraints/CountValidatorCountableTest.php +++ b/Tests/Constraints/CountValidatorCountableTest.php @@ -16,9 +16,9 @@ /** * @author Bernhard Schussek */ -class CountValidatorCountableTest extends CountValidatorTest +class CountValidatorCountableTest extends CountValidatorTestCase { - protected function createCollection(array $content) + protected static function createCollection(array $content) { return new Countable($content); } diff --git a/Tests/Constraints/CountValidatorTest.php b/Tests/Constraints/CountValidatorTestCase.php similarity index 90% rename from Tests/Constraints/CountValidatorTest.php rename to Tests/Constraints/CountValidatorTestCase.php index ae71acd1e..104c90773 100644 --- a/Tests/Constraints/CountValidatorTest.php +++ b/Tests/Constraints/CountValidatorTestCase.php @@ -20,14 +20,14 @@ /** * @author Bernhard Schussek */ -abstract class CountValidatorTest extends ConstraintValidatorTestCase +abstract class CountValidatorTestCase extends ConstraintValidatorTestCase { protected function createValidator(): CountValidator { return new CountValidator(); } - abstract protected function createCollection(array $content); + abstract protected static function createCollection(array $content); public function testNullIsValid() { @@ -42,30 +42,30 @@ public function testExpectsCountableType() $this->validator->validate(new \stdClass(), new Count(5)); } - public function getThreeOrLessElements() + public static function getThreeOrLessElements() { return [ - [$this->createCollection([1])], - [$this->createCollection([1, 2])], - [$this->createCollection([1, 2, 3])], - [$this->createCollection(['a' => 1, 'b' => 2, 'c' => 3])], + [static::createCollection([1])], + [static::createCollection([1, 2])], + [static::createCollection([1, 2, 3])], + [static::createCollection(['a' => 1, 'b' => 2, 'c' => 3])], ]; } - public function getFourElements() + public static function getFourElements() { return [ - [$this->createCollection([1, 2, 3, 4])], - [$this->createCollection(['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4])], + [static::createCollection([1, 2, 3, 4])], + [static::createCollection(['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4])], ]; } - public function getFiveOrMoreElements() + public static function getFiveOrMoreElements() { return [ - [$this->createCollection([1, 2, 3, 4, 5])], - [$this->createCollection([1, 2, 3, 4, 5, 6])], - [$this->createCollection(['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5])], + [static::createCollection([1, 2, 3, 4, 5])], + [static::createCollection([1, 2, 3, 4, 5, 6])], + [static::createCollection(['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5])], ]; } diff --git a/Tests/Constraints/CountryValidatorTest.php b/Tests/Constraints/CountryValidatorTest.php index bbc68bf4f..fd3ed69e2 100644 --- a/Tests/Constraints/CountryValidatorTest.php +++ b/Tests/Constraints/CountryValidatorTest.php @@ -70,7 +70,7 @@ public function testValidCountries($country) $this->assertNoViolation(); } - public function getValidCountries() + public static function getValidCountries() { return [ ['GB'], @@ -96,7 +96,7 @@ public function testInvalidCountries($country) ->assertRaised(); } - public function getInvalidCountries() + public static function getInvalidCountries() { return [ ['foobar'], @@ -116,7 +116,7 @@ public function testValidAlpha3Countries($country) $this->assertNoViolation(); } - public function getValidAlpha3Countries() + public static function getValidAlpha3Countries() { return [ ['GBR'], @@ -143,7 +143,7 @@ public function testInvalidAlpha3Countries($country) ->assertRaised(); } - public function getInvalidAlpha3Countries() + public static function getInvalidAlpha3Countries() { return [ ['foobar'], diff --git a/Tests/Constraints/CssColorValidatorTest.php b/Tests/Constraints/CssColorValidatorTest.php index 6a9b398ac..95b0b6f29 100644 --- a/Tests/Constraints/CssColorValidatorTest.php +++ b/Tests/Constraints/CssColorValidatorTest.php @@ -52,7 +52,7 @@ public function testValidAnyColor($cssColor) $this->assertNoViolation(); } - public function getValidAnyColor(): array + public static function getValidAnyColor(): array { return [ ['#ABCDEF'], @@ -79,7 +79,7 @@ public function testValidHexLongColors($cssColor) $this->assertNoViolation(); } - public function getValidHexLongColors(): array + public static function getValidHexLongColors(): array { return [['#ABCDEF'], ['#abcdef'], ['#C0FFEE'], ['#c0ffee'], ['#501311']]; } @@ -93,7 +93,7 @@ public function testValidHexLongColorsWithAlpha($cssColor) $this->assertNoViolation(); } - public function getValidHexLongColorsWithAlpha(): array + public static function getValidHexLongColorsWithAlpha(): array { return [['#ABCDEF00'], ['#abcdef01'], ['#C0FFEE02'], ['#c0ffee03'], ['#501311FF']]; } @@ -107,7 +107,7 @@ public function testValidHexShortColors($cssColor) $this->assertNoViolation(); } - public function getValidHexShortColors(): array + public static function getValidHexShortColors(): array { return [['#F4B'], ['#FAB'], ['#f4b'], ['#fab']]; } @@ -121,7 +121,7 @@ public function testValidHexShortColorsWithAlpha($cssColor) $this->assertNoViolation(); } - public function getValidHexShortColorsWithAlpha(): array + public static function getValidHexShortColorsWithAlpha(): array { return [['#F4B1'], ['#FAB1'], ['#f4b1'], ['#fab1']]; } @@ -135,7 +135,7 @@ public function testValidBasicNamedColors($cssColor) $this->assertNoViolation(); } - public function getValidBasicNamedColors(): array + public static function getValidBasicNamedColors(): array { return [ ['black'], ['silver'], ['gray'], ['white'], ['maroon'], ['red'], ['purple'], ['fuchsia'], ['green'], ['lime'], ['olive'], ['yellow'], ['navy'], ['blue'], ['teal'], ['aqua'], @@ -152,7 +152,7 @@ public function testValidExtendedNamedColors($cssColor) $this->assertNoViolation(); } - public function getValidExtendedNamedColors(): array + public static function getValidExtendedNamedColors(): array { return [ ['aliceblue'], ['antiquewhite'], ['aqua'], ['aquamarine'], ['azure'], ['beige'], ['bisque'], ['black'], ['blanchedalmond'], ['blue'], ['blueviolet'], ['brown'], ['burlywood'], ['cadetblue'], ['chartreuse'], ['chocolate'], ['coral'], ['cornflowerblue'], ['cornsilk'], ['crimson'], ['cyan'], ['darkblue'], ['darkcyan'], ['darkgoldenrod'], ['darkgray'], ['darkgreen'], ['darkgrey'], ['darkkhaki'], ['darkmagenta'], ['darkolivegreen'], ['darkorange'], ['darkorchid'], ['darkred'], ['darksalmon'], ['darkseagreen'], ['darkslateblue'], ['darkslategray'], ['darkslategrey'], ['darkturquoise'], ['darkviolet'], ['deeppink'], ['deepskyblue'], ['dimgray'], ['dimgrey'], ['dodgerblue'], ['firebrick'], ['floralwhite'], ['forestgreen'], ['fuchsia'], ['gainsboro'], ['ghostwhite'], ['gold'], ['goldenrod'], ['gray'], ['green'], ['greenyellow'], ['grey'], ['honeydew'], ['hotpink'], ['indianred'], ['indigo'], ['ivory'], ['khaki'], ['lavender'], ['lavenderblush'], ['lawngreen'], ['lemonchiffon'], ['lightblue'], ['lightcoral'], ['lightcyan'], ['lightgoldenrodyellow'], ['lightgray'], ['lightgreen'], ['lightgrey'], ['lightpink'], ['lightsalmon'], ['lightseagreen'], ['lightskyblue'], ['lightslategray'], ['lightslategrey'], ['lightsteelblue'], ['lightyellow'], ['lime'], ['limegreen'], ['linen'], ['magenta'], ['maroon'], ['mediumaquamarine'], ['mediumblue'], ['mediumorchid'], ['mediumpurple'], ['mediumseagreen'], ['mediumslateblue'], ['mediumspringgreen'], ['mediumturquoise'], ['mediumvioletred'], ['midnightblue'], ['mintcream'], ['mistyrose'], ['moccasin'], ['navajowhite'], ['navy'], ['oldlace'], ['olive'], ['olivedrab'], ['orange'], ['orangered'], ['orchid'], ['palegoldenrod'], ['palegreen'], ['paleturquoise'], ['palevioletred'], ['papayawhip'], ['peachpuff'], ['peru'], ['pink'], ['plum'], ['powderblue'], ['purple'], ['red'], ['rosybrown'], ['royalblue'], ['saddlebrown'], ['salmon'], ['sandybrown'], ['seagreen'], ['seashell'], ['sienna'], ['silver'], ['skyblue'], ['slateblue'], ['slategray'], ['slategrey'], ['snow'], ['springgreen'], ['steelblue'], ['tan'], ['teal'], ['thistle'], ['tomato'], ['turquoise'], ['violet'], ['wheat'], ['white'], ['whitesmoke'], ['yellow'], ['yellowgreen'], @@ -169,7 +169,7 @@ public function testValidSystemColors($cssColor) $this->assertNoViolation(); } - public function getValidSystemColors(): array + public static function getValidSystemColors(): array { return [ ['Canvas'], ['CanvasText'], ['LinkText'], ['VisitedText'], ['ActiveText'], ['ButtonFace'], ['ButtonText'], ['ButtonBorder'], ['Field'], ['FieldText'], ['Highlight'], ['HighlightText'], ['SelectedItem'], ['SelectedItemText'], ['Mark'], ['MarkText'], ['GrayText'], @@ -187,7 +187,7 @@ public function testValidKeywords($cssColor) $this->assertNoViolation(); } - public function getValidKeywords(): array + public static function getValidKeywords(): array { return [['transparent'], ['currentColor']]; } @@ -201,7 +201,7 @@ public function testValidRGB($cssColor) $this->assertNoViolation(); } - public function getValidRGB(): array + public static function getValidRGB(): array { return [ ['rgb(0, 255, 243)'], @@ -219,7 +219,7 @@ public function testValidRGBA($cssColor) $this->assertNoViolation(); } - public function getValidRGBA(): array + public static function getValidRGBA(): array { return [ ['rgba( 255, 255, 255, 0.3 )'], ['rgba(255, 255, 255, 0.3)'], ['rgba(255, 255, 255, .3)'], @@ -238,7 +238,7 @@ public function testValidHSL($cssColor) $this->assertNoViolation(); } - public function getValidHSL(): array + public static function getValidHSL(): array { return [ ['hsl(0, 0%, 20%)'], ['hsl( 0, 0%, 20% )'], @@ -256,7 +256,7 @@ public function testValidHSLA($cssColor) $this->assertNoViolation(); } - public function getValidHSLA(): array + public static function getValidHSLA(): array { return [ ['hsla( 0, 0%, 20%, 0.4 )'], ['hsla(0, 0%, 20%, 0.4)'], ['hsla(0, 0%, 20%, .4)'], @@ -280,7 +280,7 @@ public function testInvalidHexColors($cssColor) ->assertRaised(); } - public function getInvalidHexColors(): array + public static function getInvalidHexColors(): array { return [['ABCDEF'], ['abcdef'], ['#K0FFEE'], ['#k0ffee'], ['#_501311'], ['ABCDEF00'], ['abcdefcc'], ['#K0FFEE33'], ['#k0ffeecc'], ['#_50131100'], ['#FAℬ'], ['#Ⅎab'], ['#F4️⃣B'], ['#f(4)b'], ['#907;']]; } @@ -298,7 +298,7 @@ public function testInvalidShortHexColors($cssColor) ->assertRaised(); } - public function getInvalidShortHexColors(): array + public static function getInvalidShortHexColors(): array { return [['ABC'], ['ABCD'], ['abc'], ['abcd'], ['#K0F'], ['#K0FF'], ['#k0f'], ['#k0ff'], ['#_50'], ['#_501']]; } @@ -321,7 +321,7 @@ public function testInvalidNamedColors($cssColor) ->assertRaised(); } - public function getInvalidNamedColors(): array + public static function getInvalidNamedColors(): array { return [['fabpot'], ['ngrekas'], ['symfony'], ['FABPOT'], ['NGREKAS'], ['SYMFONY']]; } @@ -344,7 +344,7 @@ public function testInvalidRGB($cssColor) ->assertRaised(); } - public function getInvalidRGB(): array + public static function getInvalidRGB(): array { return [['rgb(999,999,999)'], ['rgb(-99,-99,-99)'], ['rgb(a,b,c)'], ['rgb(99 99, 9 99, 99 9)']]; } @@ -367,7 +367,7 @@ public function testInvalidRGBA($cssColor) ->assertRaised(); } - public function getInvalidRGBA(): array + public static function getInvalidRGBA(): array { return [['rgba(999,999,999,999)'], ['rgba(-99,-99,-99,-99)'], ['rgba(a,b,c,d)'], ['rgba(99 99, 9 99, 99 9, . 9)']]; } @@ -390,7 +390,7 @@ public function testInvalidHSL($cssColor) ->assertRaised(); } - public function getInvalidHSL(): array + public static function getInvalidHSL(): array { return [['hsl(1000, 1000%, 20000%)'], ['hsl(-100, -10%, -2%)'], ['hsl(a, b, c)'], ['hsl(a, b%, c%)'], ['hsl( 99 99% , 9 99% , 99 9%)']]; } diff --git a/Tests/Constraints/CurrencyValidatorTest.php b/Tests/Constraints/CurrencyValidatorTest.php index 20489b87f..02ec5e5ef 100644 --- a/Tests/Constraints/CurrencyValidatorTest.php +++ b/Tests/Constraints/CurrencyValidatorTest.php @@ -84,7 +84,7 @@ public function testValidCurrenciesWithCountrySpecificLocale($currency) $this->assertNoViolation(); } - public function getValidCurrencies() + public static function getValidCurrencies() { return [ ['EUR'], @@ -127,7 +127,7 @@ public function testInvalidCurrenciesNamed($currency) ->assertRaised(); } - public function getInvalidCurrencies() + public static function getInvalidCurrencies() { return [ ['EN'], diff --git a/Tests/Constraints/DateTimeValidatorTest.php b/Tests/Constraints/DateTimeValidatorTest.php index 1e675b15d..8da07c424 100644 --- a/Tests/Constraints/DateTimeValidatorTest.php +++ b/Tests/Constraints/DateTimeValidatorTest.php @@ -71,7 +71,7 @@ public function testValidDateTimes($format, $dateTime) $this->assertNoViolation(); } - public function getValidDateTimes() + public static function getValidDateTimes() { return [ ['Y-m-d H:i:s e', '1995-03-24 00:00:00 UTC'], @@ -100,7 +100,7 @@ public function testInvalidDateTimes($format, $dateTime, $code) ->assertRaised(); } - public function getInvalidDateTimes() + public static function getInvalidDateTimes() { return [ ['Y-m-d', 'foobar', DateTime::INVALID_FORMAT_ERROR], diff --git a/Tests/Constraints/DateValidatorTest.php b/Tests/Constraints/DateValidatorTest.php index b93c60839..e8642f04a 100644 --- a/Tests/Constraints/DateValidatorTest.php +++ b/Tests/Constraints/DateValidatorTest.php @@ -53,7 +53,7 @@ public function testValidDates($date) $this->assertNoViolation(); } - public function getValidDates() + public static function getValidDates() { return [ ['2010-01-01'], @@ -91,7 +91,7 @@ public function testInvalidDateNamed() ->assertRaised(); } - public function getInvalidDates() + public static function getInvalidDates() { return [ ['foobar', Date::INVALID_FORMAT_ERROR], diff --git a/Tests/Constraints/DivisibleByValidatorTest.php b/Tests/Constraints/DivisibleByValidatorTest.php index 3e2e770e3..06e060796 100644 --- a/Tests/Constraints/DivisibleByValidatorTest.php +++ b/Tests/Constraints/DivisibleByValidatorTest.php @@ -26,7 +26,7 @@ protected function createValidator(): DivisibleByValidator return new DivisibleByValidator(); } - protected function createConstraint(array $options = null): Constraint + protected static function createConstraint(array $options = null): Constraint { return new DivisibleBy($options); } @@ -36,7 +36,7 @@ protected function getErrorCode(): ?string return DivisibleBy::NOT_DIVISIBLE_BY; } - public function provideValidComparisons(): array + public static function provideValidComparisons(): array { return [ [-7, 1], @@ -62,14 +62,14 @@ public function provideValidComparisons(): array ]; } - public function provideValidComparisonsToPropertyPath(): array + public static function provideValidComparisonsToPropertyPath(): array { return [ [25], ]; } - public function provideInvalidComparisons(): array + public static function provideInvalidComparisons(): array { return [ [1, '1', 2, '2', 'int'], @@ -95,7 +95,7 @@ public function testThrowsOnNonNumericValues(string $expectedGivenType, $value, ])); } - public function throwsOnNonNumericValuesProvider() + public static function throwsOnNonNumericValuesProvider() { return [ [\stdClass::class, 2, new \stdClass()], @@ -103,8 +103,8 @@ public function throwsOnNonNumericValuesProvider() ]; } - public function provideComparisonsToNullValueAtPropertyPath() + public static function provideComparisonsToNullValueAtPropertyPath() { - $this->markTestSkipped('DivisibleByValidator rejects null values.'); + self::markTestSkipped('DivisibleByValidator rejects null values.'); } } diff --git a/Tests/Constraints/EmailValidatorTest.php b/Tests/Constraints/EmailValidatorTest.php index 7c3a4d00c..6bf8fec6c 100644 --- a/Tests/Constraints/EmailValidatorTest.php +++ b/Tests/Constraints/EmailValidatorTest.php @@ -73,7 +73,7 @@ public function testValidEmails($email) $this->assertNoViolation(); } - public function getValidEmails() + public static function getValidEmails() { return [ ['fabien@symfony.com'], @@ -95,7 +95,7 @@ public function testValidInLooseModeEmails($email) $this->assertNoViolation(); } - public function getEmailsOnlyValidInLooseMode() + public static function getEmailsOnlyValidInLooseMode() { return [ ['example@example.co..uk'], @@ -116,7 +116,7 @@ public function testValidNormalizedEmails($email) $this->assertNoViolation(); } - public function getValidEmailsWithWhitespaces() + public static function getValidEmailsWithWhitespaces() { return [ ["\x20example@example.co.uk\x20"], @@ -137,7 +137,7 @@ public function testValidNormalizedEmailsInLooseMode($email) $this->assertNoViolation(); } - public function getEmailsWithWhitespacesOnlyValidInLooseMode() + public static function getEmailsWithWhitespacesOnlyValidInLooseMode() { return [ ["\x09\x09example@example.co..uk\x09\x09"], @@ -157,7 +157,7 @@ public function testValidEmailsHtml5($email) $this->assertNoViolation(); } - public function getValidEmailsHtml5() + public static function getValidEmailsHtml5() { return [ ['fabien@symfony.com'], @@ -184,7 +184,7 @@ public function testInvalidEmails($email) ->assertRaised(); } - public function getInvalidEmails() + public static function getInvalidEmails() { return [ ['example'], @@ -212,7 +212,7 @@ public function testInvalidHtml5Emails($email) ->assertRaised(); } - public function getInvalidHtml5Emails() + public static function getInvalidHtml5Emails() { return [ ['example'], @@ -252,7 +252,7 @@ public function testInvalidAllowNoTldEmails($email) ->assertRaised(); } - public function getInvalidAllowNoTldEmails() + public static function getInvalidAllowNoTldEmails() { return [ ['example bar'], @@ -298,7 +298,7 @@ public function testModeHtml5AllowNoTld() */ public function testModeLoose() { - $this->expectDeprecation('Since symfony/validator 6.2: The "loose" mode is deprecated. The default mode will be changed to "html5" in 7.0.'); + $this->expectDeprecation('Since symfony/validator 6.2: The "loose" mode is deprecated. It will be removed in 7.0 and the default mode will be changed to "html5".'); $constraint = new Email(['mode' => Email::VALIDATION_MODE_LOOSE]); @@ -339,7 +339,7 @@ public function testStrictWithInvalidEmails($email) /** * @see https://github.com/egulias/EmailValidator/blob/1.2.8/tests/egulias/Tests/EmailValidator/EmailValidatorTest.php */ - public function getInvalidEmailsForStrictChecks() + public static function getInvalidEmailsForStrictChecks() { return [ ['test@example.com test'], diff --git a/Tests/Constraints/EqualToValidatorTest.php b/Tests/Constraints/EqualToValidatorTest.php index 652fd0df4..ea9efe90e 100644 --- a/Tests/Constraints/EqualToValidatorTest.php +++ b/Tests/Constraints/EqualToValidatorTest.php @@ -25,7 +25,7 @@ protected function createValidator(): EqualToValidator return new EqualToValidator(); } - protected function createConstraint(array $options = null): Constraint + protected static function createConstraint(array $options = null): Constraint { return new EqualTo($options); } @@ -35,7 +35,7 @@ protected function getErrorCode(): ?string return EqualTo::NOT_EQUAL_ERROR; } - public function provideValidComparisons(): array + public static function provideValidComparisons(): array { return [ [3, 3], @@ -49,14 +49,14 @@ public function provideValidComparisons(): array ]; } - public function provideValidComparisonsToPropertyPath(): array + public static function provideValidComparisonsToPropertyPath(): array { return [ [5], ]; } - public function provideInvalidComparisons(): array + public static function provideInvalidComparisons(): array { return [ [1, '1', 2, '2', 'int'], @@ -68,7 +68,7 @@ public function provideInvalidComparisons(): array ]; } - public function provideComparisonsToNullValueAtPropertyPath() + public static function provideComparisonsToNullValueAtPropertyPath() { return [ [5, '5', false], diff --git a/Tests/Constraints/ExpressionLanguageSyntaxTest.php b/Tests/Constraints/ExpressionLanguageSyntaxTest.php index f8a428a75..2fb8bf155 100644 --- a/Tests/Constraints/ExpressionLanguageSyntaxTest.php +++ b/Tests/Constraints/ExpressionLanguageSyntaxTest.php @@ -37,7 +37,7 @@ public function testValidatedByService(ExpressionLanguageSyntax $constraint) self::assertSame('my_service', $constraint->validatedBy()); } - public function provideServiceValidatedConstraints(): iterable + public static function provideServiceValidatedConstraints(): iterable { yield 'Doctrine style' => [new ExpressionLanguageSyntax(['service' => 'my_service'])]; diff --git a/Tests/Constraints/ExpressionSyntaxTest.php b/Tests/Constraints/ExpressionSyntaxTest.php index c7c7d7652..7f319f23d 100644 --- a/Tests/Constraints/ExpressionSyntaxTest.php +++ b/Tests/Constraints/ExpressionSyntaxTest.php @@ -34,7 +34,7 @@ public function testValidatedByService(ExpressionSyntax $constraint) self::assertSame('my_service', $constraint->validatedBy()); } - public function provideServiceValidatedConstraints(): iterable + public static function provideServiceValidatedConstraints(): iterable { yield 'Doctrine style' => [new ExpressionSyntax(['service' => 'my_service'])]; diff --git a/Tests/Constraints/FileTest.php b/Tests/Constraints/FileTest.php index ef66c9df4..c9a36d020 100644 --- a/Tests/Constraints/FileTest.php +++ b/Tests/Constraints/FileTest.php @@ -86,7 +86,7 @@ public function testInvalidMaxSize($maxSize) new File(['maxSize' => $maxSize]); } - public function provideValidSizes() + public static function provideValidSizes() { return [ ['500', 500, false], @@ -106,7 +106,7 @@ public function provideValidSizes() ]; } - public function provideInvalidSizes() + public static function provideInvalidSizes() { return [ ['+100'], @@ -126,7 +126,7 @@ public function testBinaryFormat($maxSize, $guessedFormat, $binaryFormat) $this->assertSame($binaryFormat, $file->binaryFormat); } - public function provideFormats() + public static function provideFormats() { return [ [100, null, false], diff --git a/Tests/Constraints/FileValidatorObjectTest.php b/Tests/Constraints/FileValidatorObjectTest.php index f35f93b17..932b45cbc 100644 --- a/Tests/Constraints/FileValidatorObjectTest.php +++ b/Tests/Constraints/FileValidatorObjectTest.php @@ -13,7 +13,7 @@ use Symfony\Component\HttpFoundation\File\File; -class FileValidatorObjectTest extends FileValidatorTest +class FileValidatorObjectTest extends FileValidatorTestCase { protected function getFile($filename) { diff --git a/Tests/Constraints/FileValidatorPathTest.php b/Tests/Constraints/FileValidatorPathTest.php index dfd82f15c..9a8968801 100644 --- a/Tests/Constraints/FileValidatorPathTest.php +++ b/Tests/Constraints/FileValidatorPathTest.php @@ -13,7 +13,7 @@ use Symfony\Component\Validator\Constraints\File; -class FileValidatorPathTest extends FileValidatorTest +class FileValidatorPathTest extends FileValidatorTestCase { protected function getFile($filename) { diff --git a/Tests/Constraints/FileValidatorTest.php b/Tests/Constraints/FileValidatorTestCase.php similarity index 97% rename from Tests/Constraints/FileValidatorTest.php rename to Tests/Constraints/FileValidatorTestCase.php index 3643adee8..32421123b 100644 --- a/Tests/Constraints/FileValidatorTest.php +++ b/Tests/Constraints/FileValidatorTestCase.php @@ -18,7 +18,7 @@ use Symfony\Component\Validator\Exception\UnexpectedValueException; use Symfony\Component\Validator\Test\ConstraintValidatorTestCase; -abstract class FileValidatorTest extends ConstraintValidatorTestCase +abstract class FileValidatorTestCase extends ConstraintValidatorTestCase { protected $path; @@ -90,7 +90,7 @@ public function testValidUploadedfile() $this->assertNoViolation(); } - public function provideMaxSizeExceededTests() + public static function provideMaxSizeExceededTests() { // We have various interesting limit - size combinations to test. // Assume a limit of 1000 bytes (1 kB). Then the following table @@ -187,7 +187,7 @@ public function testMaxSizeExceeded($bytesWritten, $limit, $sizeAsString, $limit ->assertRaised(); } - public function provideMaxSizeNotExceededTests() + public static function provideMaxSizeNotExceededTests() { return [ // 0 has no effect @@ -242,7 +242,7 @@ public function testInvalidMaxSize() $this->validator->validate($this->path, $constraint); } - public function provideBinaryFormatTests() + public static function provideBinaryFormatTests() { return [ [11, 10, null, '11', '10', 'bytes'], @@ -388,7 +388,7 @@ public function testInvalidMimeType(File $constraint) ->assertRaised(); } - public function provideMimeTypeConstraints(): iterable + public static function provideMimeTypeConstraints(): iterable { yield 'Doctrine style' => [new File([ 'mimeTypes' => ['image/png', 'image/jpg'], @@ -446,7 +446,7 @@ public function testDisallowEmpty(File $constraint) ->assertRaised(); } - public function provideDisallowEmptyConstraints(): iterable + public static function provideDisallowEmptyConstraints(): iterable { yield 'Doctrine style' => [new File([ 'disallowEmptyMessage' => 'myMessage', @@ -476,7 +476,7 @@ public function testUploadedFileError($error, $message, array $params = [], $max ->assertRaised(); } - public function uploadedFileErrorProvider() + public static function uploadedFileErrorProvider() { $tests = [ [(string) \UPLOAD_ERR_FORM_SIZE, 'uploadFormSizeErrorMessage'], @@ -551,7 +551,7 @@ public function testExtensionValid(string $name) $this->assertNoViolation(); } - private function validExtensionProvider(): iterable + private static function validExtensionProvider(): iterable { yield ['test.gif']; yield ['test.png.gif']; @@ -582,7 +582,7 @@ public function testExtensionInvalid(string $name, string $extension) ->assertRaised(); } - private function invalidExtensionProvider(): iterable + private static function invalidExtensionProvider(): iterable { yield ['test.gif', 'gif']; yield ['test.png.gif', 'gif']; diff --git a/Tests/Constraints/GreaterThanOrEqualValidatorTest.php b/Tests/Constraints/GreaterThanOrEqualValidatorTest.php index 48c9f347f..e1e29576b 100644 --- a/Tests/Constraints/GreaterThanOrEqualValidatorTest.php +++ b/Tests/Constraints/GreaterThanOrEqualValidatorTest.php @@ -25,7 +25,7 @@ protected function createValidator(): GreaterThanOrEqualValidator return new GreaterThanOrEqualValidator(); } - protected function createConstraint(array $options = null): Constraint + protected static function createConstraint(array $options = null): Constraint { return new GreaterThanOrEqual($options); } @@ -35,7 +35,7 @@ protected function getErrorCode(): ?string return GreaterThanOrEqual::TOO_LOW_ERROR; } - public function provideValidComparisons(): array + public static function provideValidComparisons(): array { return [ [3, 2], @@ -52,7 +52,7 @@ public function provideValidComparisons(): array ]; } - public function provideValidComparisonsToPropertyPath(): array + public static function provideValidComparisonsToPropertyPath(): array { return [ [5], @@ -60,7 +60,7 @@ public function provideValidComparisonsToPropertyPath(): array ]; } - public function provideInvalidComparisons(): array + public static function provideInvalidComparisons(): array { return [ [1, '1', 2, '2', 'int'], @@ -71,7 +71,7 @@ public function provideInvalidComparisons(): array ]; } - public function provideComparisonsToNullValueAtPropertyPath() + public static function provideComparisonsToNullValueAtPropertyPath() { return [ [5, '5', true], diff --git a/Tests/Constraints/GreaterThanOrEqualValidatorWithPositiveOrZeroConstraintTest.php b/Tests/Constraints/GreaterThanOrEqualValidatorWithPositiveOrZeroConstraintTest.php index c505e4c9e..34e546029 100644 --- a/Tests/Constraints/GreaterThanOrEqualValidatorWithPositiveOrZeroConstraintTest.php +++ b/Tests/Constraints/GreaterThanOrEqualValidatorWithPositiveOrZeroConstraintTest.php @@ -21,12 +21,12 @@ */ class GreaterThanOrEqualValidatorWithPositiveOrZeroConstraintTest extends GreaterThanOrEqualValidatorTest { - protected function createConstraint(array $options = null): Constraint + protected static function createConstraint(array $options = null): Constraint { return new PositiveOrZero(); } - public function provideValidComparisons(): array + public static function provideValidComparisons(): array { return [ [0, 0], @@ -39,7 +39,7 @@ public function provideValidComparisons(): array ]; } - public function provideInvalidComparisons(): array + public static function provideInvalidComparisons(): array { return [ [-1, '-1', 0, '0', 'int'], diff --git a/Tests/Constraints/GreaterThanValidatorTest.php b/Tests/Constraints/GreaterThanValidatorTest.php index 412e7bf00..bc4b5df04 100644 --- a/Tests/Constraints/GreaterThanValidatorTest.php +++ b/Tests/Constraints/GreaterThanValidatorTest.php @@ -25,7 +25,7 @@ protected function createValidator(): GreaterThanValidator return new GreaterThanValidator(); } - protected function createConstraint(array $options = null): Constraint + protected static function createConstraint(array $options = null): Constraint { return new GreaterThan($options); } @@ -35,7 +35,7 @@ protected function getErrorCode(): ?string return GreaterThan::TOO_LOW_ERROR; } - public function provideValidComparisons(): array + public static function provideValidComparisons(): array { return [ [2, 1], @@ -48,14 +48,14 @@ public function provideValidComparisons(): array ]; } - public function provideValidComparisonsToPropertyPath(): array + public static function provideValidComparisonsToPropertyPath(): array { return [ [6], ]; } - public function provideInvalidComparisons(): array + public static function provideInvalidComparisons(): array { return [ [1, '1', 2, '2', 'int'], @@ -73,7 +73,7 @@ public function provideInvalidComparisons(): array ]; } - public function provideComparisonsToNullValueAtPropertyPath() + public static function provideComparisonsToNullValueAtPropertyPath() { return [ [5, '5', true], diff --git a/Tests/Constraints/GreaterThanValidatorWithPositiveConstraintTest.php b/Tests/Constraints/GreaterThanValidatorWithPositiveConstraintTest.php index 03fe28ffb..5ce59d129 100644 --- a/Tests/Constraints/GreaterThanValidatorWithPositiveConstraintTest.php +++ b/Tests/Constraints/GreaterThanValidatorWithPositiveConstraintTest.php @@ -21,12 +21,12 @@ */ class GreaterThanValidatorWithPositiveConstraintTest extends GreaterThanValidatorTest { - protected function createConstraint(array $options = null): Constraint + protected static function createConstraint(array $options = null): Constraint { return new Positive(); } - public function provideValidComparisons(): array + public static function provideValidComparisons(): array { return [ [2, 0], @@ -36,7 +36,7 @@ public function provideValidComparisons(): array ]; } - public function provideInvalidComparisons(): array + public static function provideInvalidComparisons(): array { return [ [0, '0', 0, '0', 'int'], diff --git a/Tests/Constraints/HostnameValidatorTest.php b/Tests/Constraints/HostnameValidatorTest.php index f8c5251cb..0af802b63 100644 --- a/Tests/Constraints/HostnameValidatorTest.php +++ b/Tests/Constraints/HostnameValidatorTest.php @@ -62,7 +62,7 @@ public function testValidTldDomainsPassValidationIfTldNotRequired($domain) $this->assertNoViolation(); } - public function getValidMultilevelDomains() + public static function getValidMultilevelDomains() { return [ ['symfony.com'], @@ -107,7 +107,7 @@ public function testInvalidDomainsRaiseViolationIfTldNotRequired($domain) ->assertRaised(); } - public function getInvalidDomains() + public static function getInvalidDomains() { return [ ['acme..com'], @@ -144,7 +144,7 @@ public function testReservedDomainsRaiseViolationIfTldRequired($domain) ->assertRaised(); } - public function getReservedDomains() + public static function getReservedDomains() { return [ ['example'], @@ -197,7 +197,7 @@ public function testTopLevelDomainsRaiseViolationIfTldRequired($domain) ->assertRaised(); } - public function getTopLevelDomains() + public static function getTopLevelDomains() { return [ ['com'], diff --git a/Tests/Constraints/IbanValidatorTest.php b/Tests/Constraints/IbanValidatorTest.php index 7d9c891f9..ef8f20875 100644 --- a/Tests/Constraints/IbanValidatorTest.php +++ b/Tests/Constraints/IbanValidatorTest.php @@ -48,7 +48,7 @@ public function testValidIbans($iban) $this->assertNoViolation(); } - public function getValidIbans() + public static function getValidIbans() { return [ ['CH9300762011623852957'], // Switzerland without spaces @@ -116,6 +116,17 @@ public function getValidIbans() ['AE07 0331 2345 6789 0123 456'], // UAE ['GB12 CPBK 0892 9965 0449 91'], // United Kingdom + ['DJ21 0001 0000 0001 5400 0100 186'], // Djibouti + ['EG38 0019 0005 0000 0000 2631 8000 2'], // Egypt + ['IQ98 NBIQ 8501 2345 6789 012'], // Iraq + ['LC55 HEMM 0001 0001 0012 0012 0002 3015'], // Saint Lucia + ['LY83 0020 4800 0020 1001 2036 1'], // Libya + ['RU02 0445 2560 0407 0281 0412 3456 7890 1'], // Russia + ['SC18 SSCB 1101 0000 0000 0000 1497 USD'], // Seychelles + ['SD21 2901 0501 2340 01'], // Sudan + ['ST23 0002 0000 0289 3557 1014 8'], // Sao Tome and Principe + ['SV62 CENR 0000 0000 0000 0070 0025'], // El Salvador + // Extended country list // http://www.nordea.com/Our+services/International+products+and+services/Cash+Management/IBAN+countries/908462.html // https://www.swift.com/sites/default/files/resources/iban_registry.pdf @@ -126,8 +137,8 @@ public function getValidIbans() ['BR9700360305000010009795493P1'], // Brazil ['BR1800000000141455123924100C2'], // Brazil ['VG96VPVG0000012345678901'], // British Virgin Islands - ['BF1030134020015400945000643'], // Burkina Faso - ['BI43201011067444'], // Burundi + ['BF42BF0840101300463574000390'], // Burkina Faso + ['BI4210000100010000332045181'], // Burundi ['CM2110003001000500000605306'], // Cameroon ['CV64000300004547069110176'], // Cape Verde ['FR7630007000110009970004942'], // Central African Republic @@ -152,7 +163,7 @@ public function getValidIbans() ['XK051212012345678906'], // Republic of Kosovo ['PT50000200000163099310355'], // Sao Tome and Principe ['SA0380000000608010167519'], // Saudi Arabia - ['SN12K00100152000025690007542'], // Senegal + ['SN08SN0100152000048500003035'], // Senegal ['TL380080012345678910157'], // Timor-Leste ['TN5914207207100707129648'], // Tunisia ['TR330006100519786457841326'], // Turkey @@ -170,7 +181,7 @@ public function testIbansWithInvalidFormat($iban) $this->assertViolationRaised($iban, Iban::INVALID_FORMAT_ERROR); } - public function getIbansWithInvalidFormat() + public static function getIbansWithInvalidFormat() { return [ ['AL47 2121 1009 0000 0002 3569 874'], // Albania @@ -244,13 +255,13 @@ public function getIbansWithInvalidFormat() ['BR9700360305000010009795493P11'], // Brazil ['BR1800000000141455123924100C21'], // Brazil ['VG96VPVG00000123456789011'], // British Virgin Islands - ['BF10301340200154009450006431'], // Burkina Faso + ['BF1030134020015400945000643'], // Burkina Faso ['BI432010110674441'], // Burundi ['CM21100030010005000006053061'], // Cameroon ['CV640003000045470691101761'], // Cape Verde ['FR76300070001100099700049421'], // Central African Republic ['CG52300110002021512345678901'], // Congo - ['CR05152020010262840661'], // Costa Rica + ['CR05A52020010262840661'], // Costa Rica ['CR0515202001026284066'], // Costa Rica ['DO28BAGR000000012124536113241'], // Dominican Republic ['GT82TRAJ010200000012100296901'], // Guatemala @@ -289,7 +300,7 @@ public function testIbansWithValidFormatButIncorrectChecksum($iban) $this->assertViolationRaised($iban, Iban::CHECKSUM_FAILED_ERROR); } - public function getIbansWithValidFormatButIncorrectChecksum() + public static function getIbansWithValidFormatButIncorrectChecksum() { return [ ['AL47 2121 1009 0000 0002 3569 8742'], // Albania @@ -357,8 +368,8 @@ public function getIbansWithValidFormatButIncorrectChecksum() ['BR9700360305000010009795493P2'], // Brazil ['BR1800000000141455123924100C3'], // Brazil ['VG96VPVG0000012345678902'], // British Virgin Islands - ['BF1030134020015400945000644'], // Burkina Faso - ['BI43201011067445'], // Burundi + ['BF41BF0840101300463574000390'], // Burkina Faso + ['BI3210000100010000332045181'], // Burundi ['CM2110003001000500000605307'], // Cameroon ['CV64000300004547069110177'], // Cape Verde ['FR7630007000110009970004943'], // Central African Republic @@ -383,7 +394,7 @@ public function getIbansWithValidFormatButIncorrectChecksum() ['XK051212012345678907'], // Republic of Kosovo ['PT50000200000163099310356'], // Sao Tome and Principe ['SA0380000000608010167518'], // Saudi Arabia - ['SN12K00100152000025690007543'], // Senegal + ['SN07SN0100152000048500003035'], // Senegal ['TL380080012345678910158'], // Timor-Leste ['TN5914207207100707129649'], // Tunisia ['TR330006100519786457841327'], // Turkey @@ -401,7 +412,7 @@ public function testIbansWithUnsupportedCountryCode($countryCode) $this->assertViolationRaised($countryCode.'260211000000230064016', Iban::NOT_SUPPORTED_COUNTRY_CODE_ERROR); } - public function getUnsupportedCountryCodes() + public static function getUnsupportedCountryCodes() { return [ ['AG'], @@ -440,7 +451,7 @@ public function testLoadFromAttribute() ->assertRaised(); } - public function getIbansWithInvalidCountryCode() + public static function getIbansWithInvalidCountryCode() { return [ ['0750447346'], diff --git a/Tests/Constraints/IdenticalToValidatorTest.php b/Tests/Constraints/IdenticalToValidatorTest.php index 514f8d255..334743c4b 100644 --- a/Tests/Constraints/IdenticalToValidatorTest.php +++ b/Tests/Constraints/IdenticalToValidatorTest.php @@ -25,7 +25,7 @@ protected function createValidator(): IdenticalToValidator return new IdenticalToValidator(); } - protected function createConstraint(array $options = null): Constraint + protected static function createConstraint(array $options = null): Constraint { return new IdenticalTo($options); } @@ -35,20 +35,21 @@ protected function getErrorCode(): ?string return IdenticalTo::NOT_IDENTICAL_ERROR; } - public function provideAllValidComparisons(): array + public static function provideAllValidComparisons(): array { - $this->setDefaultTimezone('UTC'); + $timezone = date_default_timezone_get(); + date_default_timezone_set('UTC'); // Don't call addPhp5Dot5Comparisons() automatically, as it does // not take care of identical objects - $comparisons = $this->provideValidComparisons(); + $comparisons = self::provideValidComparisons(); - $this->restoreDefaultTimezone(); + date_default_timezone_set($timezone); return $comparisons; } - public function provideValidComparisons(): array + public static function provideValidComparisons(): array { $date = new \DateTime('2000-01-01'); $object = new ComparisonTest_Class(2); @@ -67,14 +68,14 @@ public function provideValidComparisons(): array return $comparisons; } - public function provideValidComparisonsToPropertyPath(): array + public static function provideValidComparisonsToPropertyPath(): array { return [ [5], ]; } - public function provideInvalidComparisons(): array + public static function provideInvalidComparisons(): array { return [ [1, '1', 2, '2', 'int'], @@ -86,7 +87,7 @@ public function provideInvalidComparisons(): array ]; } - public function provideComparisonsToNullValueAtPropertyPath() + public static function provideComparisonsToNullValueAtPropertyPath() { return [ [5, '5', false], diff --git a/Tests/Constraints/ImageValidatorTest.php b/Tests/Constraints/ImageValidatorTest.php index c005c3426..8f26be2fa 100644 --- a/Tests/Constraints/ImageValidatorTest.php +++ b/Tests/Constraints/ImageValidatorTest.php @@ -86,7 +86,7 @@ public function testFileNotFound(Image $constraint) ->assertRaised(); } - public function provideConstraintsWithNotFoundMessage(): iterable + public static function provideConstraintsWithNotFoundMessage(): iterable { yield 'Doctrine style' => [new Image([ 'notFoundMessage' => 'myMessage', @@ -124,7 +124,7 @@ public function testWidthTooSmall(Image $constraint) ->assertRaised(); } - public function provideMinWidthConstraints(): iterable + public static function provideMinWidthConstraints(): iterable { yield 'Doctrine style' => [new Image([ 'minWidth' => 3, @@ -149,7 +149,7 @@ public function testWidthTooBig(Image $constraint) ->assertRaised(); } - public function provideMaxWidthConstraints(): iterable + public static function provideMaxWidthConstraints(): iterable { yield 'Doctrine style' => [new Image([ 'maxWidth' => 1, @@ -174,7 +174,7 @@ public function testHeightTooSmall(Image $constraint) ->assertRaised(); } - public function provideMinHeightConstraints(): iterable + public static function provideMinHeightConstraints(): iterable { yield 'Doctrine style' => [new Image([ 'minHeight' => 3, @@ -199,7 +199,7 @@ public function testHeightTooBig(Image $constraint) ->assertRaised(); } - public function provideMaxHeightConstraints(): iterable + public static function provideMaxHeightConstraints(): iterable { yield 'Doctrine style' => [new Image([ 'maxHeight' => 1, @@ -226,7 +226,7 @@ public function testPixelsTooFew(Image $constraint) ->assertRaised(); } - public function provideMinPixelsConstraints(): iterable + public static function provideMinPixelsConstraints(): iterable { yield 'Doctrine style' => [new Image([ 'minPixels' => 5, @@ -253,7 +253,7 @@ public function testPixelsTooMany(Image $constraint) ->assertRaised(); } - public function provideMaxPixelsConstraints(): iterable + public static function provideMaxPixelsConstraints(): iterable { yield 'Doctrine style' => [new Image([ 'maxPixels' => 3, @@ -338,7 +338,7 @@ public function testRatioTooSmall(Image $constraint) ->assertRaised(); } - public function provideMinRatioConstraints(): iterable + public static function provideMinRatioConstraints(): iterable { yield 'Doctrine style' => [new Image([ 'minRatio' => 2, @@ -363,7 +363,7 @@ public function testRatioTooBig(Image $constraint) ->assertRaised(); } - public function provideMaxRatioConstraints(): iterable + public static function provideMaxRatioConstraints(): iterable { yield 'Doctrine style' => [new Image([ 'maxRatio' => 0.5, @@ -441,7 +441,7 @@ public function testSquareNotAllowed(Image $constraint) ->assertRaised(); } - public function provideAllowSquareConstraints(): iterable + public static function provideAllowSquareConstraints(): iterable { yield 'Doctrine style' => [new Image([ 'allowSquare' => false, @@ -466,7 +466,7 @@ public function testLandscapeNotAllowed(Image $constraint) ->assertRaised(); } - public function provideAllowLandscapeConstraints(): iterable + public static function provideAllowLandscapeConstraints(): iterable { yield 'Doctrine style' => [new Image([ 'allowLandscape' => false, @@ -491,7 +491,7 @@ public function testPortraitNotAllowed(Image $constraint) ->assertRaised(); } - public function provideAllowPortraitConstraints(): iterable + public static function provideAllowPortraitConstraints(): iterable { yield 'Doctrine style' => [new Image([ 'allowPortrait' => false, @@ -537,7 +537,7 @@ public function testInvalidMimeType() ->assertRaised(); } - public function provideDetectCorruptedConstraints(): iterable + public static function provideDetectCorruptedConstraints(): iterable { yield 'Doctrine style' => [new Image([ 'detectCorrupted' => true, @@ -564,7 +564,7 @@ public function testInvalidMimeTypeWithNarrowedSet(Image $constraint) ->assertRaised(); } - public function provideInvalidMimeTypeWithNarrowedSet() + public static function provideInvalidMimeTypeWithNarrowedSet() { yield 'Doctrine style' => [new Image([ 'mimeTypes' => [ diff --git a/Tests/Constraints/IpValidatorTest.php b/Tests/Constraints/IpValidatorTest.php index 8ffd151a5..2a0bdcf70 100644 --- a/Tests/Constraints/IpValidatorTest.php +++ b/Tests/Constraints/IpValidatorTest.php @@ -64,7 +64,7 @@ public function testValidIpsV4($ip) $this->assertNoViolation(); } - public function getValidIpsV4() + public static function getValidIpsV4() { return [ ['0.0.0.0'], @@ -101,7 +101,7 @@ public function testValidIpV6WithWhitespacesNamed() $this->assertNoViolation(); } - public function getValidIpsV4WithWhitespaces() + public static function getValidIpsV4WithWhitespaces() { return [ ["\x200.0.0.0"], @@ -125,7 +125,7 @@ public function testValidIpsV6($ip) $this->assertNoViolation(); } - public function getValidIpsV6() + public static function getValidIpsV6() { return [ ['2001:0db8:85a3:0000:0000:8a2e:0370:7334'], @@ -162,9 +162,9 @@ public function testValidIpsAll($ip) $this->assertNoViolation(); } - public function getValidIpsAll() + public static function getValidIpsAll() { - return array_merge($this->getValidIpsV4(), $this->getValidIpsV6()); + return array_merge(self::getValidIpsV4(), self::getValidIpsV6()); } /** @@ -185,7 +185,7 @@ public function testInvalidIpsV4($ip) ->assertRaised(); } - public function getInvalidIpsV4() + public static function getInvalidIpsV4() { return [ ['0'], @@ -218,7 +218,7 @@ public function testInvalidPrivateIpsV4($ip) ->assertRaised(); } - public function getInvalidPrivateIpsV4() + public static function getInvalidPrivateIpsV4() { return [ ['10.0.0.0'], @@ -245,7 +245,7 @@ public function testInvalidReservedIpsV4($ip) ->assertRaised(); } - public function getInvalidReservedIpsV4() + public static function getInvalidReservedIpsV4() { return [ ['0.0.0.0'], @@ -272,9 +272,9 @@ public function testInvalidPublicIpsV4($ip) ->assertRaised(); } - public function getInvalidPublicIpsV4() + public static function getInvalidPublicIpsV4() { - return array_merge($this->getInvalidPrivateIpsV4(), $this->getInvalidReservedIpsV4()); + return array_merge(self::getInvalidPrivateIpsV4(), self::getInvalidReservedIpsV4()); } /** @@ -295,7 +295,7 @@ public function testInvalidIpsV6($ip) ->assertRaised(); } - public function getInvalidIpsV6() + public static function getInvalidIpsV6() { return [ ['z001:0db8:85a3:0000:0000:8a2e:0370:7334'], @@ -332,7 +332,7 @@ public function testInvalidPrivateIpsV6($ip) ->assertRaised(); } - public function getInvalidPrivateIpsV6() + public static function getInvalidPrivateIpsV6() { return [ ['fdfe:dcba:9876:ffff:fdc6:c46b:bb8f:7d4c'], @@ -359,12 +359,12 @@ public function testInvalidReservedIpsV6($ip) ->assertRaised(); } - public function getInvalidReservedIpsV6() + public static function getInvalidReservedIpsV6() { // Quoting after official filter documentation: // "FILTER_FLAG_NO_RES_RANGE = This flag does not apply to IPv6 addresses." // Full description: https://php.net/filter.filters.flags - return $this->getInvalidIpsV6(); + return self::getInvalidIpsV6(); } /** @@ -385,9 +385,9 @@ public function testInvalidPublicIpsV6($ip) ->assertRaised(); } - public function getInvalidPublicIpsV6() + public static function getInvalidPublicIpsV6() { - return array_merge($this->getInvalidPrivateIpsV6(), $this->getInvalidReservedIpsV6()); + return array_merge(self::getInvalidPrivateIpsV6(), self::getInvalidReservedIpsV6()); } /** @@ -408,9 +408,9 @@ public function testInvalidIpsAll($ip) ->assertRaised(); } - public function getInvalidIpsAll() + public static function getInvalidIpsAll() { - return array_merge($this->getInvalidIpsV4(), $this->getInvalidIpsV6()); + return array_merge(self::getInvalidIpsV4(), self::getInvalidIpsV6()); } /** @@ -431,9 +431,9 @@ public function testInvalidPrivateIpsAll($ip) ->assertRaised(); } - public function getInvalidPrivateIpsAll() + public static function getInvalidPrivateIpsAll() { - return array_merge($this->getInvalidPrivateIpsV4(), $this->getInvalidPrivateIpsV6()); + return array_merge(self::getInvalidPrivateIpsV4(), self::getInvalidPrivateIpsV6()); } /** @@ -454,9 +454,9 @@ public function testInvalidReservedIpsAll($ip) ->assertRaised(); } - public function getInvalidReservedIpsAll() + public static function getInvalidReservedIpsAll() { - return array_merge($this->getInvalidReservedIpsV4(), $this->getInvalidReservedIpsV6()); + return array_merge(self::getInvalidReservedIpsV4(), self::getInvalidReservedIpsV6()); } /** @@ -477,8 +477,8 @@ public function testInvalidPublicIpsAll($ip) ->assertRaised(); } - public function getInvalidPublicIpsAll() + public static function getInvalidPublicIpsAll() { - return array_merge($this->getInvalidPublicIpsV4(), $this->getInvalidPublicIpsV6()); + return array_merge(self::getInvalidPublicIpsV4(), self::getInvalidPublicIpsV6()); } } diff --git a/Tests/Constraints/IsFalseValidatorTest.php b/Tests/Constraints/IsFalseValidatorTest.php index f5b9e6cee..e59764764 100644 --- a/Tests/Constraints/IsFalseValidatorTest.php +++ b/Tests/Constraints/IsFalseValidatorTest.php @@ -49,7 +49,7 @@ public function testTrueIsInvalid(IsFalse $constraint) ->assertRaised(); } - public function provideInvalidConstraints(): iterable + public static function provideInvalidConstraints(): iterable { yield 'Doctrine style' => [new IsFalse([ 'message' => 'myMessage', diff --git a/Tests/Constraints/IsNullValidatorTest.php b/Tests/Constraints/IsNullValidatorTest.php index dd1b9eeb2..d1f1b4d0c 100644 --- a/Tests/Constraints/IsNullValidatorTest.php +++ b/Tests/Constraints/IsNullValidatorTest.php @@ -61,7 +61,7 @@ public function testInvalidValuesNamed($value, $valueAsString) ->assertRaised(); } - public function getInvalidValues() + public static function getInvalidValues() { return [ [0, '0'], diff --git a/Tests/Constraints/IsTrueValidatorTest.php b/Tests/Constraints/IsTrueValidatorTest.php index e7d4ecf22..1dc47f4b0 100644 --- a/Tests/Constraints/IsTrueValidatorTest.php +++ b/Tests/Constraints/IsTrueValidatorTest.php @@ -49,7 +49,7 @@ public function testFalseIsInvalid(IsTrue $constraint) ->assertRaised(); } - public function provideInvalidConstraints(): iterable + public static function provideInvalidConstraints(): iterable { yield 'Doctrine style' => [new IsTrue([ 'message' => 'myMessage', diff --git a/Tests/Constraints/IsbnValidatorTest.php b/Tests/Constraints/IsbnValidatorTest.php index 70a3c55d5..df985137c 100644 --- a/Tests/Constraints/IsbnValidatorTest.php +++ b/Tests/Constraints/IsbnValidatorTest.php @@ -26,7 +26,7 @@ protected function createValidator(): IsbnValidator return new IsbnValidator(); } - public function getValidIsbn10() + public static function getValidIsbn10() { return [ ['2723442284'], @@ -45,7 +45,7 @@ public function getValidIsbn10() ]; } - public function getInvalidIsbn10() + public static function getInvalidIsbn10() { return [ ['27234422841', Isbn::TOO_LONG_ERROR], @@ -65,7 +65,7 @@ public function getInvalidIsbn10() ]; } - public function getValidIsbn13() + public static function getValidIsbn13() { return [ ['978-2723442282'], @@ -83,7 +83,7 @@ public function getValidIsbn13() ]; } - public function getInvalidIsbn13() + public static function getInvalidIsbn13() { return [ ['978-27234422821', Isbn::TOO_LONG_ERROR], @@ -103,19 +103,19 @@ public function getInvalidIsbn13() ]; } - public function getValidIsbn() + public static function getValidIsbn() { return array_merge( - $this->getValidIsbn10(), - $this->getValidIsbn13() + self::getValidIsbn10(), + self::getValidIsbn13() ); } - public function getInvalidIsbn() + public static function getInvalidIsbn() { return array_merge( - $this->getInvalidIsbn10(), - $this->getInvalidIsbn13() + self::getInvalidIsbn10(), + self::getInvalidIsbn13() ); } diff --git a/Tests/Constraints/IsinValidatorTest.php b/Tests/Constraints/IsinValidatorTest.php index 63e4529fa..dca4a423f 100644 --- a/Tests/Constraints/IsinValidatorTest.php +++ b/Tests/Constraints/IsinValidatorTest.php @@ -47,7 +47,7 @@ public function testValidIsin($isin) $this->assertNoViolation(); } - public function getValidIsin() + public static function getValidIsin() { return [ ['XS2125535901'], // Goldman Sachs International @@ -71,7 +71,7 @@ public function testIsinWithInvalidFormat($isin) $this->assertViolationRaised($isin, Isin::INVALID_LENGTH_ERROR); } - public function getIsinWithInvalidLenghFormat() + public static function getIsinWithInvalidLenghFormat() { return [ ['X'], @@ -96,7 +96,7 @@ public function testIsinWithInvalidPattern($isin) $this->assertViolationRaised($isin, Isin::INVALID_PATTERN_ERROR); } - public function getIsinWithInvalidPattern() + public static function getIsinWithInvalidPattern() { return [ ['X12155696679'], @@ -115,7 +115,7 @@ public function testIsinWithValidFormatButIncorrectChecksum($isin) $this->assertViolationRaised($isin, Isin::INVALID_CHECKSUM_ERROR); } - public function getIsinWithValidFormatButIncorrectChecksum() + public static function getIsinWithValidFormatButIncorrectChecksum() { return [ ['XS2112212144'], diff --git a/Tests/Constraints/IssnValidatorTest.php b/Tests/Constraints/IssnValidatorTest.php index 67d1aaa91..9eece3eb9 100644 --- a/Tests/Constraints/IssnValidatorTest.php +++ b/Tests/Constraints/IssnValidatorTest.php @@ -26,7 +26,7 @@ protected function createValidator(): IssnValidator return new IssnValidator(); } - public function getValidLowerCasedIssn() + public static function getValidLowerCasedIssn() { return [ ['2162-321x'], @@ -39,7 +39,7 @@ public function getValidLowerCasedIssn() ]; } - public function getValidNonHyphenatedIssn() + public static function getValidNonHyphenatedIssn() { return [ ['2162321X'], @@ -52,7 +52,7 @@ public function getValidNonHyphenatedIssn() ]; } - public function getFullValidIssn() + public static function getFullValidIssn() { return [ ['1550-7416'], @@ -66,16 +66,16 @@ public function getFullValidIssn() ]; } - public function getValidIssn() + public static function getValidIssn() { return array_merge( - $this->getValidLowerCasedIssn(), - $this->getValidNonHyphenatedIssn(), - $this->getFullValidIssn() + self::getValidLowerCasedIssn(), + self::getValidNonHyphenatedIssn(), + self::getFullValidIssn() ); } - public function getInvalidIssn() + public static function getInvalidIssn() { return [ [0, Issn::TOO_SHORT_ERROR], diff --git a/Tests/Constraints/JsonValidatorTest.php b/Tests/Constraints/JsonValidatorTest.php index 6be66dc5c..92d8a20a7 100644 --- a/Tests/Constraints/JsonValidatorTest.php +++ b/Tests/Constraints/JsonValidatorTest.php @@ -49,7 +49,7 @@ public function testInvalidValues($value) ->assertRaised(); } - public function getValidValues() + public static function getValidValues() { return [ ['{"planet":"earth", "country": "Morocco","city": "Rabat" ,"postcode" : 10160, "is_great": true, @@ -65,7 +65,7 @@ public function getValidValues() ]; } - public function getInvalidValues() + public static function getInvalidValues() { return [ ['{"foo": 3 "bar": 4}'], diff --git a/Tests/Constraints/LanguageValidatorTest.php b/Tests/Constraints/LanguageValidatorTest.php index a17fde804..a88284189 100644 --- a/Tests/Constraints/LanguageValidatorTest.php +++ b/Tests/Constraints/LanguageValidatorTest.php @@ -70,7 +70,7 @@ public function testValidLanguages($language) $this->assertNoViolation(); } - public function getValidLanguages() + public static function getValidLanguages() { return [ ['en'], @@ -95,7 +95,7 @@ public function testInvalidLanguages($language) ->assertRaised(); } - public function getInvalidLanguages() + public static function getInvalidLanguages() { return [ ['EN'], @@ -115,7 +115,7 @@ public function testValidAlpha3Languages($language) $this->assertNoViolation(); } - public function getValidAlpha3Languages() + public static function getValidAlpha3Languages() { return [ ['deu'], @@ -142,7 +142,7 @@ public function testInvalidAlpha3Languages($language) ->assertRaised(); } - public function getInvalidAlpha3Languages() + public static function getInvalidAlpha3Languages() { return [ ['foobar'], diff --git a/Tests/Constraints/LengthValidatorTest.php b/Tests/Constraints/LengthValidatorTest.php index fdf91e43b..a1fdbf69b 100644 --- a/Tests/Constraints/LengthValidatorTest.php +++ b/Tests/Constraints/LengthValidatorTest.php @@ -52,7 +52,7 @@ public function testExpectsStringCompatibleType() $this->validator->validate(new \stdClass(), new Length(['value' => 5])); } - public function getThreeOrLessCharacters() + public static function getThreeOrLessCharacters() { return [ [12], @@ -66,7 +66,7 @@ public function getThreeOrLessCharacters() ]; } - public function getFourCharacters() + public static function getFourCharacters() { return [ [1234], @@ -76,7 +76,7 @@ public function getFourCharacters() ]; } - public function getFiveOrMoreCharacters() + public static function getFiveOrMoreCharacters() { return [ [12345], @@ -90,7 +90,7 @@ public function getFiveOrMoreCharacters() ]; } - public function getOneCharset() + public static function getOneCharset() { return [ ['é', 'utf8', true], @@ -100,7 +100,7 @@ public function getOneCharset() ]; } - public function getThreeCharactersWithWhitespaces() + public static function getThreeCharactersWithWhitespaces() { return [ ["\x20ccc"], diff --git a/Tests/Constraints/LessThanOrEqualValidatorTest.php b/Tests/Constraints/LessThanOrEqualValidatorTest.php index 43be31ab7..aec7edcb6 100644 --- a/Tests/Constraints/LessThanOrEqualValidatorTest.php +++ b/Tests/Constraints/LessThanOrEqualValidatorTest.php @@ -25,7 +25,7 @@ protected function createValidator(): LessThanOrEqualValidator return new LessThanOrEqualValidator(); } - protected function createConstraint(array $options = null): Constraint + protected static function createConstraint(array $options = null): Constraint { return new LessThanOrEqual($options); } @@ -35,7 +35,7 @@ protected function getErrorCode(): ?string return LessThanOrEqual::TOO_HIGH_ERROR; } - public function provideValidComparisons(): array + public static function provideValidComparisons(): array { return [ [1, 2], @@ -54,7 +54,7 @@ public function provideValidComparisons(): array ]; } - public function provideValidComparisonsToPropertyPath(): array + public static function provideValidComparisonsToPropertyPath(): array { return [ [4], @@ -62,7 +62,7 @@ public function provideValidComparisonsToPropertyPath(): array ]; } - public function provideInvalidComparisons(): array + public static function provideInvalidComparisons(): array { return [ [2, '2', 1, '1', 'int'], @@ -74,7 +74,7 @@ public function provideInvalidComparisons(): array ]; } - public function provideComparisonsToNullValueAtPropertyPath() + public static function provideComparisonsToNullValueAtPropertyPath() { return [ [5, '5', true], diff --git a/Tests/Constraints/LessThanOrEqualValidatorWithNegativeOrZeroConstraintTest.php b/Tests/Constraints/LessThanOrEqualValidatorWithNegativeOrZeroConstraintTest.php index 303f5ed78..f75364e1d 100644 --- a/Tests/Constraints/LessThanOrEqualValidatorWithNegativeOrZeroConstraintTest.php +++ b/Tests/Constraints/LessThanOrEqualValidatorWithNegativeOrZeroConstraintTest.php @@ -21,12 +21,12 @@ */ class LessThanOrEqualValidatorWithNegativeOrZeroConstraintTest extends LessThanOrEqualValidatorTest { - protected function createConstraint(array $options = null): Constraint + protected static function createConstraint(array $options = null): Constraint { return new NegativeOrZero(); } - public function provideValidComparisons(): array + public static function provideValidComparisons(): array { return [ [0, 0], @@ -37,7 +37,7 @@ public function provideValidComparisons(): array ]; } - public function provideInvalidComparisons(): array + public static function provideInvalidComparisons(): array { return [ [2, '2', 0, '0', 'int'], diff --git a/Tests/Constraints/LessThanValidatorTest.php b/Tests/Constraints/LessThanValidatorTest.php index 9c9844925..7721d812f 100644 --- a/Tests/Constraints/LessThanValidatorTest.php +++ b/Tests/Constraints/LessThanValidatorTest.php @@ -25,7 +25,7 @@ protected function createValidator(): LessThanValidator return new LessThanValidator(); } - protected function createConstraint(array $options = null): Constraint + protected static function createConstraint(array $options = null): Constraint { return new LessThan($options); } @@ -35,7 +35,7 @@ protected function getErrorCode(): ?string return LessThan::TOO_HIGH_ERROR; } - public function provideValidComparisons(): array + public static function provideValidComparisons(): array { return [ [1, 2], @@ -48,14 +48,14 @@ public function provideValidComparisons(): array ]; } - public function provideValidComparisonsToPropertyPath(): array + public static function provideValidComparisonsToPropertyPath(): array { return [ [4], ]; } - public function provideInvalidComparisons(): array + public static function provideInvalidComparisons(): array { return [ [3, '3', 2, '2', 'int'], @@ -72,7 +72,7 @@ public function provideInvalidComparisons(): array ]; } - public function provideComparisonsToNullValueAtPropertyPath() + public static function provideComparisonsToNullValueAtPropertyPath() { return [ [5, '5', true], diff --git a/Tests/Constraints/LessThanValidatorWithNegativeConstraintTest.php b/Tests/Constraints/LessThanValidatorWithNegativeConstraintTest.php index c8c9fe6a8..569e662b2 100644 --- a/Tests/Constraints/LessThanValidatorWithNegativeConstraintTest.php +++ b/Tests/Constraints/LessThanValidatorWithNegativeConstraintTest.php @@ -21,12 +21,12 @@ */ class LessThanValidatorWithNegativeConstraintTest extends LessThanValidatorTest { - protected function createConstraint(array $options = null): Constraint + protected static function createConstraint(array $options = null): Constraint { return new Negative(); } - public function provideValidComparisons(): array + public static function provideValidComparisons(): array { return [ [-1, 0], @@ -36,7 +36,7 @@ public function provideValidComparisons(): array ]; } - public function provideInvalidComparisons(): array + public static function provideInvalidComparisons(): array { return [ [0, '0', 0, '0', 'int'], diff --git a/Tests/Constraints/LocaleValidatorTest.php b/Tests/Constraints/LocaleValidatorTest.php index 710949c92..4eec91c63 100644 --- a/Tests/Constraints/LocaleValidatorTest.php +++ b/Tests/Constraints/LocaleValidatorTest.php @@ -53,7 +53,7 @@ public function testValidLocales($locale) $this->assertNoViolation(); } - public function getValidLocales() + public static function getValidLocales() { return [ ['en'], @@ -83,7 +83,7 @@ public function testInvalidLocales($locale) ->assertRaised(); } - public function getInvalidLocales() + public static function getInvalidLocales() { return [ ['baz'], @@ -151,7 +151,7 @@ public function testInvalidLocaleWithoutCanonicalizationNamed() ->assertRaised(); } - public function getUncanonicalizedLocales(): iterable + public static function getUncanonicalizedLocales(): iterable { return [ ['en-US'], diff --git a/Tests/Constraints/LuhnValidatorTest.php b/Tests/Constraints/LuhnValidatorTest.php index 75caffe32..b0571ebd0 100644 --- a/Tests/Constraints/LuhnValidatorTest.php +++ b/Tests/Constraints/LuhnValidatorTest.php @@ -47,7 +47,7 @@ public function testValidNumbers($number) $this->assertNoViolation(); } - public function getValidNumbers() + public static function getValidNumbers() { return [ ['42424242424242424242'], @@ -88,7 +88,7 @@ public function testInvalidNumbers($number, $code) ->assertRaised(); } - public function getInvalidNumbers() + public static function getInvalidNumbers() { return [ ['1234567812345678', Luhn::CHECKSUM_FAILED_ERROR], @@ -110,7 +110,7 @@ public function testInvalidTypes($number) $this->validator->validate($number, $constraint); } - public function getInvalidTypes() + public static function getInvalidTypes() { return [ [0], diff --git a/Tests/Constraints/NotBlankValidatorTest.php b/Tests/Constraints/NotBlankValidatorTest.php index dbe63e358..8d1ba3d0f 100644 --- a/Tests/Constraints/NotBlankValidatorTest.php +++ b/Tests/Constraints/NotBlankValidatorTest.php @@ -32,7 +32,7 @@ public function testValidValues($value) $this->assertNoViolation(); } - public function getValidValues() + public static function getValidValues() { return [ ['foobar'], @@ -143,7 +143,7 @@ public function testNormalizedStringIsInvalid($value) ->assertRaised(); } - public function getWhitespaces() + public static function getWhitespaces() { return [ ["\x20"], diff --git a/Tests/Constraints/NotCompromisedPasswordValidatorTest.php b/Tests/Constraints/NotCompromisedPasswordValidatorTest.php index 7e61bd32b..5c2991bc9 100644 --- a/Tests/Constraints/NotCompromisedPasswordValidatorTest.php +++ b/Tests/Constraints/NotCompromisedPasswordValidatorTest.php @@ -105,7 +105,7 @@ public function testThresholdNotReached(NotCompromisedPassword $constraint) $this->assertNoViolation(); } - public function provideConstraintsWithThreshold(): iterable + public static function provideConstraintsWithThreshold(): iterable { yield 'Doctrine style' => [new NotCompromisedPassword(['threshold' => 10])]; yield 'named arguments' => [new NotCompromisedPassword(threshold: 10)]; @@ -217,7 +217,7 @@ public function testApiErrorSkipped(NotCompromisedPassword $constraint) $this->assertTrue(true); // No exception have been thrown } - public function provideErrorSkippingConstraints(): iterable + public static function provideErrorSkippingConstraints(): iterable { yield 'Doctrine style' => [new NotCompromisedPassword(['skipOnError' => true])]; yield 'named arguments' => [new NotCompromisedPassword(skipOnError: true)]; diff --git a/Tests/Constraints/NotEqualToValidatorTest.php b/Tests/Constraints/NotEqualToValidatorTest.php index 96c38e5c7..de8249d8b 100644 --- a/Tests/Constraints/NotEqualToValidatorTest.php +++ b/Tests/Constraints/NotEqualToValidatorTest.php @@ -25,7 +25,7 @@ protected function createValidator(): NotEqualToValidator return new NotEqualToValidator(); } - protected function createConstraint(array $options = null): Constraint + protected static function createConstraint(array $options = null): Constraint { return new NotEqualTo($options); } @@ -35,7 +35,7 @@ protected function getErrorCode(): ?string return NotEqualTo::IS_EQUAL_ERROR; } - public function provideValidComparisons(): array + public static function provideValidComparisons(): array { return [ [1, 2], @@ -48,14 +48,14 @@ public function provideValidComparisons(): array ]; } - public function provideValidComparisonsToPropertyPath(): array + public static function provideValidComparisonsToPropertyPath(): array { return [ [0], ]; } - public function provideInvalidComparisons(): array + public static function provideInvalidComparisons(): array { return [ [3, '3', 3, '3', 'int'], @@ -68,7 +68,7 @@ public function provideInvalidComparisons(): array ]; } - public function provideComparisonsToNullValueAtPropertyPath() + public static function provideComparisonsToNullValueAtPropertyPath() { return [ [5, '5', true], diff --git a/Tests/Constraints/NotIdenticalToValidatorTest.php b/Tests/Constraints/NotIdenticalToValidatorTest.php index 6034b91e0..a594599c4 100644 --- a/Tests/Constraints/NotIdenticalToValidatorTest.php +++ b/Tests/Constraints/NotIdenticalToValidatorTest.php @@ -25,7 +25,7 @@ protected function createValidator(): NotIdenticalToValidator return new NotIdenticalToValidator(); } - protected function createConstraint(array $options = null): Constraint + protected static function createConstraint(array $options = null): Constraint { return new NotIdenticalTo($options); } @@ -35,7 +35,7 @@ protected function getErrorCode(): ?string return NotIdenticalTo::IS_IDENTICAL_ERROR; } - public function provideValidComparisons(): array + public static function provideValidComparisons(): array { return [ [1, 2], @@ -51,27 +51,28 @@ public function provideValidComparisons(): array ]; } - public function provideValidComparisonsToPropertyPath(): array + public static function provideValidComparisonsToPropertyPath(): array { return [ [0], ]; } - public function provideAllInvalidComparisons(): array + public static function provideAllInvalidComparisons(): array { - $this->setDefaultTimezone('UTC'); + $timezone = date_default_timezone_get(); + date_default_timezone_set('UTC'); // Don't call addPhp5Dot5Comparisons() automatically, as it does // not take care of identical objects - $comparisons = $this->provideInvalidComparisons(); + $comparisons = self::provideInvalidComparisons(); - $this->restoreDefaultTimezone(); + date_default_timezone_set($timezone); return $comparisons; } - public function provideInvalidComparisons(): array + public static function provideInvalidComparisons(): array { $date = new \DateTime('2000-01-01'); $object = new ComparisonTest_Class(2); @@ -86,7 +87,7 @@ public function provideInvalidComparisons(): array return $comparisons; } - public function provideComparisonsToNullValueAtPropertyPath() + public static function provideComparisonsToNullValueAtPropertyPath() { return [ [5, '5', true], diff --git a/Tests/Constraints/NotNullValidatorTest.php b/Tests/Constraints/NotNullValidatorTest.php index 3b7a9b9e6..82156e326 100644 --- a/Tests/Constraints/NotNullValidatorTest.php +++ b/Tests/Constraints/NotNullValidatorTest.php @@ -32,7 +32,7 @@ public function testValidValues($value) $this->assertNoViolation(); } - public function getValidValues() + public static function getValidValues() { return [ [0], @@ -55,7 +55,7 @@ public function testNullIsInvalid(NotNull $constraint) ->assertRaised(); } - public function provideInvalidConstraints(): iterable + public static function provideInvalidConstraints(): iterable { yield 'Doctrine style' => [new NotNull([ 'message' => 'myMessage', diff --git a/Tests/Constraints/RangeTest.php b/Tests/Constraints/RangeTest.php index 89c7cd368..132be131d 100644 --- a/Tests/Constraints/RangeTest.php +++ b/Tests/Constraints/RangeTest.php @@ -32,7 +32,7 @@ public function testThrowsConstraintExceptionIfBothMinLimitAndPropertyPathNamed( { $this->expectException(\Symfony\Component\Validator\Exception\ConstraintDefinitionException::class); $this->expectExceptionMessage('requires only one of the "min" or "minPropertyPath" options to be set, not both.'); - eval('new \Symfony\Component\Validator\Constraints\Range(min: "min", minPropertyPath: "minPropertyPath");'); + new Range(min: 'min', minPropertyPath: 'minPropertyPath'); } public function testThrowsConstraintExceptionIfBothMaxLimitAndPropertyPath() @@ -49,7 +49,7 @@ public function testThrowsConstraintExceptionIfBothMaxLimitAndPropertyPathNamed( { $this->expectException(\Symfony\Component\Validator\Exception\ConstraintDefinitionException::class); $this->expectExceptionMessage('requires only one of the "max" or "maxPropertyPath" options to be set, not both.'); - eval('new \Symfony\Component\Validator\Constraints\Range(max: "max", maxPropertyPath: "maxPropertyPath");'); + new Range(max: 'max', maxPropertyPath: 'maxPropertyPath'); } public function testThrowsConstraintExceptionIfNoLimitNorPropertyPath() @@ -69,6 +69,6 @@ public function testThrowsConstraintDefinitionExceptionIfBothMinAndMaxAndMinMess { $this->expectException(\Symfony\Component\Validator\Exception\ConstraintDefinitionException::class); $this->expectExceptionMessage('can not use "minMessage" and "maxMessage" when the "min" and "max" options are both set. Use "notInRangeMessage" instead.'); - eval('new \Symfony\Component\Validator\Constraints\Range(min: "min", max: "max", minMessage: "minMessage", maxMessage: "maxMessage");'); + new Range(min: 'min', max: 'max', minMessage: 'minMessage', maxMessage: 'maxMessage'); } } diff --git a/Tests/Constraints/RangeValidatorTest.php b/Tests/Constraints/RangeValidatorTest.php index e6ff49885..fffeeaffb 100644 --- a/Tests/Constraints/RangeValidatorTest.php +++ b/Tests/Constraints/RangeValidatorTest.php @@ -31,7 +31,7 @@ public function testNullIsValid() $this->assertNoViolation(); } - public function getTenToTwenty() + public static function getTenToTwenty() { return [ [10.00001], @@ -45,7 +45,7 @@ public function getTenToTwenty() ]; } - public function getLessThanTen() + public static function getLessThanTen() { return [ [9.99999, '9.99999'], @@ -55,7 +55,7 @@ public function getLessThanTen() ]; } - public function getMoreThanTwenty() + public static function getMoreThanTwenty() { return [ [20.000001, '20.000001'], @@ -277,11 +277,12 @@ public function testInvalidValuesCombinedMinNamed($value, $formattedValue) ->assertRaised(); } - public function getTenthToTwentiethMarch2014() + public static function getTenthToTwentiethMarch2014() { // The provider runs before setUp(), so we need to manually fix // the default timezone - $this->setDefaultTimezone('UTC'); + $timezone = date_default_timezone_get(); + date_default_timezone_set('UTC'); $tests = [ [new \DateTime('March 10, 2014')], @@ -293,16 +294,17 @@ public function getTenthToTwentiethMarch2014() $tests[] = [new \DateTimeImmutable('March 15, 2014')]; $tests[] = [new \DateTimeImmutable('March 20, 2014')]; - $this->restoreDefaultTimezone(); + date_default_timezone_set($timezone); return $tests; } - public function getSoonerThanTenthMarch2014() + public static function getSoonerThanTenthMarch2014() { // The provider runs before setUp(), so we need to manually fix // the default timezone - $this->setDefaultTimezone('UTC'); + $timezone = date_default_timezone_get(); + date_default_timezone_set('UTC'); $tests = [ [new \DateTime('March 20, 2013'), 'Mar 20, 2013, 12:00 AM'], @@ -312,16 +314,17 @@ public function getSoonerThanTenthMarch2014() $tests[] = [new \DateTimeImmutable('March 20, 2013'), 'Mar 20, 2013, 12:00 AM']; $tests[] = [new \DateTimeImmutable('March 9, 2014'), 'Mar 9, 2014, 12:00 AM']; - $this->restoreDefaultTimezone(); + date_default_timezone_set($timezone); return $tests; } - public function getLaterThanTwentiethMarch2014() + public static function getLaterThanTwentiethMarch2014() { // The provider runs before setUp(), so we need to manually fix // the default timezone - $this->setDefaultTimezone('UTC'); + $timezone = date_default_timezone_get(); + date_default_timezone_set('UTC'); $tests = [ [new \DateTime('March 21, 2014'), 'Mar 21, 2014, 12:00 AM'], @@ -331,7 +334,7 @@ public function getLaterThanTwentiethMarch2014() $tests[] = [new \DateTimeImmutable('March 21, 2014'), 'Mar 21, 2014, 12:00 AM']; $tests[] = [new \DateTimeImmutable('March 9, 2015'), 'Mar 9, 2015, 12:00 AM']; - $this->restoreDefaultTimezone(); + date_default_timezone_set($timezone); return $tests; } @@ -593,7 +596,7 @@ public function testThrowsOnInvalidStringDates($expectedMessage, $value, $min, $ ])); } - public function throwsOnInvalidStringDatesProvider(): array + public static function throwsOnInvalidStringDatesProvider(): array { return [ ['The min value "foo" could not be converted to a "DateTimeImmutable" instance in the "Symfony\Component\Validator\Constraints\Range" constraint.', new \DateTimeImmutable(), 'foo', null], @@ -1017,7 +1020,7 @@ public function testInvalidDatesCombinedMinPropertyPath($value, $dateTimeAsStrin ->assertRaised(); } - public function provideMessageIfMinAndMaxSet(): array + public static function provideMessageIfMinAndMaxSet(): array { $notInRangeMessage = (new Range(['min' => '']))->notInRangeMessage; diff --git a/Tests/Constraints/RegexTest.php b/Tests/Constraints/RegexTest.php index 90177b486..74fbec23b 100644 --- a/Tests/Constraints/RegexTest.php +++ b/Tests/Constraints/RegexTest.php @@ -29,7 +29,7 @@ public function testConstraintGetDefaultOption() $this->assertSame('/^[0-9]+$/', $constraint->pattern); } - public function provideHtmlPatterns() + public static function provideHtmlPatterns() { return [ // HTML5 wraps the pattern in ^(?:pattern)$ diff --git a/Tests/Constraints/RegexValidatorTest.php b/Tests/Constraints/RegexValidatorTest.php index 166de5aa9..e18b18856 100644 --- a/Tests/Constraints/RegexValidatorTest.php +++ b/Tests/Constraints/RegexValidatorTest.php @@ -76,7 +76,7 @@ public function testValidValuesWithWhitespacesNamed($value) $this->assertNoViolation(); } - public function getValidValues() + public static function getValidValues() { return [ [0], @@ -92,7 +92,7 @@ public function __toString(): string ]; } - public function getValidValuesWithWhitespaces() + public static function getValidValuesWithWhitespaces() { return [ ["\x207"], @@ -137,7 +137,7 @@ public function testInvalidValuesNamed($value) ->assertRaised(); } - public function getInvalidValues() + public static function getInvalidValues() { return [ ['abcd'], diff --git a/Tests/Constraints/TimeValidatorTest.php b/Tests/Constraints/TimeValidatorTest.php index efe1ed664..5995ae15d 100644 --- a/Tests/Constraints/TimeValidatorTest.php +++ b/Tests/Constraints/TimeValidatorTest.php @@ -53,7 +53,7 @@ public function testValidTimes($time) $this->assertNoViolation(); } - public function getValidTimes() + public static function getValidTimes() { return [ ['01:02:03'], @@ -79,7 +79,7 @@ public function testInvalidTimes($time, $code) ->assertRaised(); } - public function getInvalidTimes() + public static function getInvalidTimes() { return [ ['foobar', Time::INVALID_FORMAT_ERROR], diff --git a/Tests/Constraints/TimezoneTest.php b/Tests/Constraints/TimezoneTest.php index 8e5f48ac9..90291c576 100644 --- a/Tests/Constraints/TimezoneTest.php +++ b/Tests/Constraints/TimezoneTest.php @@ -59,7 +59,7 @@ public function testExceptionForInvalidGroupedTimezones(int $zone) new Timezone(['zone' => $zone]); } - public function provideInvalidZones(): iterable + public static function provideInvalidZones(): iterable { yield [-1]; yield [0]; diff --git a/Tests/Constraints/TimezoneValidatorTest.php b/Tests/Constraints/TimezoneValidatorTest.php index a7c417bf3..527b2a664 100644 --- a/Tests/Constraints/TimezoneValidatorTest.php +++ b/Tests/Constraints/TimezoneValidatorTest.php @@ -57,7 +57,7 @@ public function testValidTimezones(string $timezone) $this->assertNoViolation(); } - public function getValidTimezones(): iterable + public static function getValidTimezones(): iterable { // ICU standard (alias/BC in PHP) yield ['Etc/UTC']; @@ -73,7 +73,7 @@ public function getValidTimezones(): iterable yield ['EST5EDT']; yield ['MST7MDT']; yield ['PST8PDT']; - yield ['America/Montreal']; + yield ['America/Toronto']; // previously expired in ICU yield ['Europe/Saratov']; @@ -105,7 +105,7 @@ public function testValidGroupedTimezones(string $timezone, int $zone) $this->assertNoViolation(); } - public function getValidGroupedTimezones(): iterable + public static function getValidGroupedTimezones(): iterable { yield ['America/Buenos_Aires', \DateTimeZone::AMERICA | \DateTimeZone::AUSTRALIA]; // icu yield ['America/Argentina/Buenos_Aires', \DateTimeZone::AMERICA]; // php @@ -141,7 +141,7 @@ public function testInvalidTimezoneWithoutZone(string $timezone) ->assertRaised(); } - public function getInvalidTimezones(): iterable + public static function getInvalidTimezones(): iterable { yield ['Buenos_Aires/America']; yield ['Buenos_Aires/Argentina/America']; @@ -167,7 +167,7 @@ public function testInvalidGroupedTimezones(string $timezone, int $zone) ->assertRaised(); } - public function getInvalidGroupedTimezones(): iterable + public static function getInvalidGroupedTimezones(): iterable { yield ['America/Buenos_Aires', \DateTimeZone::ASIA | \DateTimeZone::AUSTRALIA]; // icu yield ['America/Argentina/Buenos_Aires', \DateTimeZone::EUROPE]; // php @@ -207,7 +207,7 @@ public function testValidGroupedTimezonesByCountry(string $timezone, string $cou $this->assertNoViolation(); } - public function getValidGroupedTimezonesByCountry(): iterable + public static function getValidGroupedTimezonesByCountry(): iterable { yield ['America/Buenos_Aires', 'AR']; // icu yield ['America/Argentina/Buenos_Aires', 'AR']; // php @@ -248,7 +248,7 @@ public function testInvalidGroupedTimezonesByCountry(string $timezone, string $c ->assertRaised(); } - public function getInvalidGroupedTimezonesByCountry(): iterable + public static function getInvalidGroupedTimezonesByCountry(): iterable { yield ['America/Argentina/Cordoba', 'FR']; yield ['America/Barbados', 'PT']; @@ -302,7 +302,7 @@ public function testDeprecatedTimezonesAreInvalidWithoutBC(string $timezone) ->assertRaised(); } - public function getDeprecatedTimezones(): iterable + public static function getDeprecatedTimezones(): iterable { yield ['Australia/ACT']; yield ['Australia/LHI']; diff --git a/Tests/Constraints/TypeValidatorTest.php b/Tests/Constraints/TypeValidatorTest.php index 5fc0b0a0c..07a112b11 100644 --- a/Tests/Constraints/TypeValidatorTest.php +++ b/Tests/Constraints/TypeValidatorTest.php @@ -70,10 +70,10 @@ public function testValidValues($value, $type) $this->assertNoViolation(); } - public function getValidValues() + public static function getValidValues() { $object = new \stdClass(); - $file = $this->createFile(); + $file = self::createFile(); return [ [true, 'Boolean'], @@ -126,10 +126,10 @@ public function testInvalidValues($value, $type, $valueAsString) ->assertRaised(); } - public function getInvalidValues() + public static function getInvalidValues() { $object = new \stdClass(); - $file = $this->createFile(); + $file = self::createFile(); return [ ['foobar', 'numeric', '"foobar"'], @@ -175,7 +175,7 @@ public function testValidValuesMultipleTypes($value, array $types) $this->assertNoViolation(); } - public function getValidValuesMultipleTypes() + public static function getValidValuesMultipleTypes() { return [ ['12345', ['array', 'string']], @@ -197,7 +197,7 @@ public function testInvalidValuesMultipleTypes(Type $constraint) ->assertRaised(); } - public function provideConstraintsWithMultipleTypes() + public static function provideConstraintsWithMultipleTypes() { yield 'Doctrine style' => [new Type([ 'type' => ['boolean', 'array'], @@ -206,20 +206,20 @@ public function provideConstraintsWithMultipleTypes() yield 'named arguments' => [new Type(type: ['boolean', 'array'], message: 'myMessage')]; } - protected function createFile() + protected static function createFile() { - if (!static::$file) { - static::$file = fopen(__FILE__, 'r'); + if (!self::$file) { + self::$file = fopen(__FILE__, 'r'); } - return static::$file; + return self::$file; } public static function tearDownAfterClass(): void { - if (static::$file) { - fclose(static::$file); - static::$file = null; + if (self::$file) { + fclose(self::$file); + self::$file = null; } } } diff --git a/Tests/Constraints/UlidValidatorTest.php b/Tests/Constraints/UlidValidatorTest.php index 50c452701..abe5490d1 100644 --- a/Tests/Constraints/UlidValidatorTest.php +++ b/Tests/Constraints/UlidValidatorTest.php @@ -11,7 +11,6 @@ namespace Symfony\Component\Validator\Tests\Constraints; -use stdClass; use Symfony\Component\Validator\Constraints\Ulid; use Symfony\Component\Validator\Constraints\UlidValidator; use Symfony\Component\Validator\Exception\UnexpectedValueException; @@ -44,7 +43,7 @@ public function testEmptyStringIsValid() public function testExpectsStringCompatibleType() { $this->expectException(UnexpectedValueException::class); - $this->validator->validate(new stdClass(), new Ulid()); + $this->validator->validate(new \stdClass(), new Ulid()); } public function testValidUlid() @@ -71,7 +70,7 @@ public function testInvalidUlid(string $ulid, string $code) ->assertRaised(); } - public function getInvalidUlids() + public static function getInvalidUlids() { return [ ['01ARZ3NDEKTSV4RRFFQ69G5FA', Ulid::TOO_SHORT_ERROR], diff --git a/Tests/Constraints/UniqueValidatorTest.php b/Tests/Constraints/UniqueValidatorTest.php index d4540dcc4..438a4e8d2 100644 --- a/Tests/Constraints/UniqueValidatorTest.php +++ b/Tests/Constraints/UniqueValidatorTest.php @@ -40,7 +40,7 @@ public function testValidValues($value) $this->assertNoViolation(); } - public function getValidValues() + public static function getValidValues() { return [ yield 'null' => [[null]], @@ -73,7 +73,7 @@ public function testInvalidValues($value) ->assertRaised(); } - public function getInvalidValues() + public static function getInvalidValues() { $object = new \stdClass(); @@ -154,7 +154,7 @@ public function testExpectsNonUniqueObjects($callback) ->assertRaised(); } - public function getCallback(): array + public static function getCallback(): array { return [ 'static function' => [static function (\stdClass $object) { @@ -241,7 +241,7 @@ public function testCollectionFieldNamesMustBeString(string $type, mixed $field) $this->validator->validate([['value' => 5], ['id' => 1, 'value' => 6]], new Unique(fields: [$field])); } - public function getInvalidFieldNames(): array + public static function getInvalidFieldNames(): array { return [ ['stdClass', new \stdClass()], @@ -265,7 +265,7 @@ public function testInvalidCollectionValues(array $value, array $fields) ->assertRaised(); } - public function getInvalidCollectionValues(): array + public static function getInvalidCollectionValues(): array { return [ 'unique string' => [[ diff --git a/Tests/Constraints/UrlValidatorTest.php b/Tests/Constraints/UrlValidatorTest.php index c4c137f86..18d6e9a49 100644 --- a/Tests/Constraints/UrlValidatorTest.php +++ b/Tests/Constraints/UrlValidatorTest.php @@ -85,7 +85,7 @@ public function testValidRelativeUrl($url) $this->assertNoViolation(); } - public function getValidRelativeUrls() + public static function getValidRelativeUrls() { return [ ['//example.com'], @@ -95,7 +95,7 @@ public function getValidRelativeUrls() ]; } - public function getValidUrls() + public static function getValidUrls() { return [ ['http://a.pl'], @@ -177,7 +177,7 @@ public function getValidUrls() ]; } - public function getValidUrlsWithWhitespaces() + public static function getValidUrlsWithWhitespaces() { return [ ["\x20http://www.example.com"], @@ -225,7 +225,7 @@ public function testInvalidRelativeUrl($url) ->assertRaised(); } - public function getInvalidRelativeUrls() + public static function getInvalidRelativeUrls() { return [ ['/example.com'], @@ -245,7 +245,7 @@ public function getInvalidRelativeUrls() ]; } - public function getInvalidUrls() + public static function getInvalidUrls() { return [ ['example.com'], @@ -303,7 +303,7 @@ public function testCustomProtocolIsValid($url) $this->assertNoViolation(); } - public function getValidCustomUrls() + public static function getValidCustomUrls() { return [ ['ftp://example.com'], diff --git a/Tests/Constraints/UuidValidatorTest.php b/Tests/Constraints/UuidValidatorTest.php index 2df1b2762..8f47d3ebc 100644 --- a/Tests/Constraints/UuidValidatorTest.php +++ b/Tests/Constraints/UuidValidatorTest.php @@ -72,7 +72,7 @@ public function testValidStrictUuids($uuid, $versions = null) $this->assertNoViolation(); } - public function getValidStrictUuids() + public static function getValidStrictUuids() { return [ ['216fff40-98d9-11e3-a5e2-0800200c9a66'], // Version 1 UUID in lowercase @@ -103,7 +103,7 @@ public function testValidStrictUuidsWithWhitespaces($uuid, $versions = null) $this->assertNoViolation(); } - public function getValidStrictUuidsWithWhitespaces() + public static function getValidStrictUuidsWithWhitespaces() { return [ ["\x20216fff40-98d9-11e3-a5e2-0800200c9a66"], // Version 1 UUID in lowercase @@ -146,7 +146,7 @@ public function testInvalidStrictUuids($uuid, $code, $versions = null) ->assertRaised(); } - public function getInvalidStrictUuids() + public static function getInvalidStrictUuids() { return [ ['216fff40-98d9-11e3-a5e2_0800200c9a66', Uuid::INVALID_CHARACTERS_ERROR], @@ -203,7 +203,7 @@ public function testValidNonStrictUuids($uuid) $this->assertNoViolation(); } - public function getValidNonStrictUuids() + public static function getValidNonStrictUuids() { return [ ['216fff40-98d9-11e3-a5e2-0800200c9a66'], // Version 1 UUID in lowercase @@ -238,7 +238,7 @@ public function testInvalidNonStrictUuids($uuid, $code) ->assertRaised(); } - public function getInvalidNonStrictUuids() + public static function getInvalidNonStrictUuids() { return [ ['216fff40-98d9-11e3-a5e2_0800200c9a66', Uuid::INVALID_CHARACTERS_ERROR], diff --git a/Tests/DependencyInjection/AddAutoMappingConfigurationPassTest.php b/Tests/DependencyInjection/AddAutoMappingConfigurationPassTest.php index 4571436c1..9a6817966 100644 --- a/Tests/DependencyInjection/AddAutoMappingConfigurationPassTest.php +++ b/Tests/DependencyInjection/AddAutoMappingConfigurationPassTest.php @@ -60,7 +60,7 @@ public function testProcess(string $namespace, array $services, string $expected $this->assertCount(\count($services), $container->getDefinition('validator.builder')->getMethodCalls()); } - public function mappingProvider(): array + public static function mappingProvider(): array { return [ ['Foo\\', ['foo', 'baz'], '{^App\\\\|^Foo\\\\}'], diff --git a/Tests/Fixtures/TestEnum.php b/Tests/Fixtures/TestEnum.php new file mode 100644 index 000000000..216d34835 --- /dev/null +++ b/Tests/Fixtures/TestEnum.php @@ -0,0 +1,18 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Validator\Tests\Fixtures; + +enum TestEnum +{ + case FirstCase; + case SecondCase; +} diff --git a/Tests/Mapping/Loader/AnnotationLoaderTest.php b/Tests/Mapping/Loader/AnnotationLoaderTest.php index 2a93287f9..544c32825 100644 --- a/Tests/Mapping/Loader/AnnotationLoaderTest.php +++ b/Tests/Mapping/Loader/AnnotationLoaderTest.php @@ -211,7 +211,7 @@ public function testLoadGroupSequenceProviderAnnotation(string $namespace) $this->assertEquals($expected, $metadata); } - public function provideNamespaces(): iterable + public static function provideNamespaces(): iterable { yield 'annotations' => ['Symfony\Component\Validator\Tests\Fixtures\Annotation']; yield 'attributes' => ['Symfony\Component\Validator\Tests\Fixtures\Attribute']; diff --git a/Tests/Mapping/Loader/PropertyInfoLoaderTest.php b/Tests/Mapping/Loader/PropertyInfoLoaderTest.php index 0965d8e13..f41d4c554 100644 --- a/Tests/Mapping/Loader/PropertyInfoLoaderTest.php +++ b/Tests/Mapping/Loader/PropertyInfoLoaderTest.php @@ -205,7 +205,7 @@ public function testClassValidator(bool $expected, string $classValidatorRegexp $this->assertSame($expected, $propertyInfoLoader->loadClassMetadata($classMetadata)); } - public function regexpProvider() + public static function regexpProvider() { return [ [false, null], diff --git a/Tests/Mapping/Loader/YamlFileLoaderTest.php b/Tests/Mapping/Loader/YamlFileLoaderTest.php index 42039dde1..cf3dd46d8 100644 --- a/Tests/Mapping/Loader/YamlFileLoaderTest.php +++ b/Tests/Mapping/Loader/YamlFileLoaderTest.php @@ -53,7 +53,7 @@ public function testInvalidYamlFiles($path) $loader->loadClassMetadata($metadata); } - public function provideInvalidYamlFiles() + public static function provideInvalidYamlFiles() { return [ ['nonvalid-mapping.yml'], diff --git a/Tests/Resources/TranslationFilesTest.php b/Tests/Resources/TranslationFilesTest.php index 9997cda3a..263f318df 100644 --- a/Tests/Resources/TranslationFilesTest.php +++ b/Tests/Resources/TranslationFilesTest.php @@ -42,7 +42,7 @@ public function testTranslationFileIsValidWithoutEntityLoader($filePath) $this->assertCount(0, $errors, sprintf('"%s" is invalid:%s', $filePath, \PHP_EOL.implode(\PHP_EOL, array_column($errors, 'message')))); } - public function provideTranslationFiles() + public static function provideTranslationFiles() { return array_map( function ($filePath) { return (array) $filePath; }, diff --git a/Tests/Util/PropertyPathTest.php b/Tests/Util/PropertyPathTest.php index 99bf9e6eb..f7f33d476 100644 --- a/Tests/Util/PropertyPathTest.php +++ b/Tests/Util/PropertyPathTest.php @@ -24,7 +24,7 @@ public function testAppend($basePath, $subPath, $expectedPath, $message) $this->assertSame($expectedPath, PropertyPath::append($basePath, $subPath), $message); } - public function provideAppendPaths() + public static function provideAppendPaths() { return [ ['foo', '', 'foo', 'It returns the basePath if subPath is empty'], diff --git a/Tests/Validator/RecursiveValidatorTest.php b/Tests/Validator/RecursiveValidatorTest.php index 0c14d7104..a72b65f25 100644 --- a/Tests/Validator/RecursiveValidatorTest.php +++ b/Tests/Validator/RecursiveValidatorTest.php @@ -1284,7 +1284,7 @@ public function testReplaceDefaultGroup($sequence, array $assertViolations) } } - public function getConstraintMethods() + public static function getConstraintMethods() { return [ ['addPropertyConstraint'], @@ -1292,7 +1292,7 @@ public function getConstraintMethods() ]; } - public function getTestReplaceDefaultGroup() + public static function getTestReplaceDefaultGroup() { return [ [ @@ -2085,7 +2085,7 @@ public function testEmptyGroupsArrayDoesNotTriggerDeprecation() $validator = $this ->getMockBuilder(RecursiveValidator::class) ->disableOriginalConstructor() - ->setMethods(['startContext']) + ->onlyMethods(['startContext']) ->getMock(); $validator ->expects($this->once()) @@ -2119,7 +2119,7 @@ public function testRelationBetweenChildAAndChildB() $validator = $this ->getMockBuilder(RecursiveValidator::class) ->disableOriginalConstructor() - ->setMethods(['startContext']) + ->onlyMethods(['startContext']) ->getMock(); $validator ->expects($this->once())