From 9f2e7163cde9e6da1ed94a42c4ee9f30681af1b0 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 24 Jan 2023 15:02:24 +0100 Subject: [PATCH 01/18] Update license years (last time) --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From f7bb940f11dc485b10d302dd79d7024f030bab5b Mon Sep 17 00:00:00 2001 From: gjuric Date: Fri, 3 Feb 2023 13:13:50 +0100 Subject: [PATCH 02/18] [Validator] Make ConstraintValidatorTestCase compatible with PHPUnit 10 --- Test/ConstraintValidatorTestCase.php | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/Test/ConstraintValidatorTestCase.php b/Test/ConstraintValidatorTestCase.php index bee4639b2..073dd17f7 100644 --- a/Test/ConstraintValidatorTestCase.php +++ b/Test/ConstraintValidatorTestCase.php @@ -130,16 +130,22 @@ 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', + ]; + // PHPUnit 10 removed MockBuilder::setMethods() + if (method_exists($contextualValidatorMockBuilder, 'onlyMethods')) { + $contextualValidatorMockBuilder->onlyMethods($contextualValidatorMethods); + } else { + $contextualValidatorMockBuilder->setMethods($contextualValidatorMethods); + } + $contextualValidator = $contextualValidatorMockBuilder->getMock(); $contextualValidator->expects($this->any()) ->method('atPath') ->willReturnCallback(function ($path) use ($contextualValidator) { From 157c0c025d5dd55dbd85db663fc7206ddbef1d77 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 7 Feb 2023 10:31:13 +0100 Subject: [PATCH 03/18] minor #49253 [PHPUnit 10] Use `TestCase` suffix for abstract tests in `/Tests/` (OskarStark) This PR was merged into the 6.3 branch. Discussion ---------- [PHPUnit 10] Use `TestCase` suffix for abstract tests in `/Tests/` | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | Refs https://github.com/symfony/symfony/pull/49233 | License | MIT | Doc PR | n/a Replaces #49234 Using `Test` suffix is deprecated since PHPUnit 10 Spotted in * https://github.com/symfony/symfony/pull/49233 Commits ------- cb3db968e4 [PHPUnit 10] Use `TestCase` suffix for abstract tests in `/Tests/` --- Tests/Constraints/CollectionValidatorArrayObjectTest.php | 2 +- Tests/Constraints/CollectionValidatorArrayTest.php | 2 +- Tests/Constraints/CollectionValidatorCustomArrayObjectTest.php | 2 +- ...lectionValidatorTest.php => CollectionValidatorTestCase.php} | 2 +- Tests/Constraints/CountValidatorArrayTest.php | 2 +- Tests/Constraints/CountValidatorCountableTest.php | 2 +- .../{CountValidatorTest.php => CountValidatorTestCase.php} | 2 +- Tests/Constraints/FileValidatorObjectTest.php | 2 +- Tests/Constraints/FileValidatorPathTest.php | 2 +- .../{FileValidatorTest.php => FileValidatorTestCase.php} | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) rename Tests/Constraints/{CollectionValidatorTest.php => CollectionValidatorTestCase.php} (99%) rename Tests/Constraints/{CountValidatorTest.php => CountValidatorTestCase.php} (99%) rename Tests/Constraints/{FileValidatorTest.php => FileValidatorTestCase.php} (99%) 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 64fa81f83..9fd396296 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() { diff --git a/Tests/Constraints/CountValidatorArrayTest.php b/Tests/Constraints/CountValidatorArrayTest.php index 5f562e744..cc258cfca 100644 --- a/Tests/Constraints/CountValidatorArrayTest.php +++ b/Tests/Constraints/CountValidatorArrayTest.php @@ -14,7 +14,7 @@ /** * @author Bernhard Schussek */ -class CountValidatorArrayTest extends CountValidatorTest +class CountValidatorArrayTest extends CountValidatorTestCase { protected function createCollection(array $content) { diff --git a/Tests/Constraints/CountValidatorCountableTest.php b/Tests/Constraints/CountValidatorCountableTest.php index 7d46967bd..276076e88 100644 --- a/Tests/Constraints/CountValidatorCountableTest.php +++ b/Tests/Constraints/CountValidatorCountableTest.php @@ -16,7 +16,7 @@ /** * @author Bernhard Schussek */ -class CountValidatorCountableTest extends CountValidatorTest +class CountValidatorCountableTest extends CountValidatorTestCase { protected function createCollection(array $content) { diff --git a/Tests/Constraints/CountValidatorTest.php b/Tests/Constraints/CountValidatorTestCase.php similarity index 99% rename from Tests/Constraints/CountValidatorTest.php rename to Tests/Constraints/CountValidatorTestCase.php index 11e83d368..f011f226c 100644 --- a/Tests/Constraints/CountValidatorTest.php +++ b/Tests/Constraints/CountValidatorTestCase.php @@ -20,7 +20,7 @@ /** * @author Bernhard Schussek */ -abstract class CountValidatorTest extends ConstraintValidatorTestCase +abstract class CountValidatorTestCase extends ConstraintValidatorTestCase { protected function createValidator() { 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 99% rename from Tests/Constraints/FileValidatorTest.php rename to Tests/Constraints/FileValidatorTestCase.php index 327cb963b..de58d6d87 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; From c103bb24054a55ee17a1487557e27789b02bfb4c Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Tue, 7 Feb 2023 21:09:05 +0100 Subject: [PATCH 04/18] [Tests] Migrate tests to static data providers --- .../AbstractComparisonValidatorTestCase.php | 34 ++++++++++--------- .../Constraints/DivisibleByValidatorTest.php | 12 +++---- Tests/Constraints/EqualToValidatorTest.php | 10 +++--- .../GreaterThanOrEqualValidatorTest.php | 10 +++--- ...idatorWithPositiveOrZeroConstraintTest.php | 6 ++-- .../Constraints/GreaterThanValidatorTest.php | 10 +++--- ...hanValidatorWithPositiveConstraintTest.php | 6 ++-- .../Constraints/IdenticalToValidatorTest.php | 19 ++++++----- .../LessThanOrEqualValidatorTest.php | 10 +++--- ...idatorWithNegativeOrZeroConstraintTest.php | 6 ++-- Tests/Constraints/LessThanValidatorTest.php | 10 +++--- ...hanValidatorWithNegativeConstraintTest.php | 6 ++-- Tests/Constraints/NotEqualToValidatorTest.php | 10 +++--- .../NotIdenticalToValidatorTest.php | 19 ++++++----- 14 files changed, 86 insertions(+), 82 deletions(-) diff --git a/Tests/Constraints/AbstractComparisonValidatorTestCase.php b/Tests/Constraints/AbstractComparisonValidatorTestCase.php index 4544e4668..0df1bae15 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], @@ -112,15 +112,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; } @@ -166,9 +167,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 @@ -233,9 +234,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', ]); @@ -273,27 +274,28 @@ 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(); /** * @param array|null $options Options for the constraint */ - 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/DivisibleByValidatorTest.php b/Tests/Constraints/DivisibleByValidatorTest.php index 4ce2723c0..0074d0a9f 100644 --- a/Tests/Constraints/DivisibleByValidatorTest.php +++ b/Tests/Constraints/DivisibleByValidatorTest.php @@ -26,7 +26,7 @@ protected function createValidator() return new DivisibleByValidator(); } - protected function createConstraint(array $options = null): Constraint + protected static function createConstraint(array $options = null): Constraint { return new DivisibleBy($options); } @@ -39,7 +39,7 @@ protected function getErrorCode(): ?string /** * {@inheritdoc} */ - public function provideValidComparisons(): array + public static function provideValidComparisons(): array { return [ [-7, 1], @@ -68,7 +68,7 @@ public function provideValidComparisons(): array /** * {@inheritdoc} */ - public function provideValidComparisonsToPropertyPath(): array + public static function provideValidComparisonsToPropertyPath(): array { return [ [25], @@ -78,7 +78,7 @@ public function provideValidComparisonsToPropertyPath(): array /** * {@inheritdoc} */ - public function provideInvalidComparisons(): array + public static function provideInvalidComparisons(): array { return [ [1, '1', 2, '2', 'int'], @@ -112,8 +112,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/EqualToValidatorTest.php b/Tests/Constraints/EqualToValidatorTest.php index db825543f..628bd2534 100644 --- a/Tests/Constraints/EqualToValidatorTest.php +++ b/Tests/Constraints/EqualToValidatorTest.php @@ -25,7 +25,7 @@ protected function createValidator() return new EqualToValidator(); } - protected function createConstraint(array $options = null): Constraint + protected static function createConstraint(array $options = null): Constraint { return new EqualTo($options); } @@ -38,7 +38,7 @@ protected function getErrorCode(): ?string /** * {@inheritdoc} */ - public function provideValidComparisons(): array + public static function provideValidComparisons(): array { return [ [3, 3], @@ -55,7 +55,7 @@ public function provideValidComparisons(): array /** * {@inheritdoc} */ - public function provideValidComparisonsToPropertyPath(): array + public static function provideValidComparisonsToPropertyPath(): array { return [ [5], @@ -65,7 +65,7 @@ public function provideValidComparisonsToPropertyPath(): array /** * {@inheritdoc} */ - public function provideInvalidComparisons(): array + public static function provideInvalidComparisons(): array { return [ [1, '1', 2, '2', 'int'], @@ -77,7 +77,7 @@ public function provideInvalidComparisons(): array ]; } - public function provideComparisonsToNullValueAtPropertyPath() + public static function provideComparisonsToNullValueAtPropertyPath() { return [ [5, '5', false], diff --git a/Tests/Constraints/GreaterThanOrEqualValidatorTest.php b/Tests/Constraints/GreaterThanOrEqualValidatorTest.php index 7484e9ff5..fd3622e87 100644 --- a/Tests/Constraints/GreaterThanOrEqualValidatorTest.php +++ b/Tests/Constraints/GreaterThanOrEqualValidatorTest.php @@ -25,7 +25,7 @@ protected function createValidator() return new GreaterThanOrEqualValidator(); } - protected function createConstraint(array $options = null): Constraint + protected static function createConstraint(array $options = null): Constraint { return new GreaterThanOrEqual($options); } @@ -38,7 +38,7 @@ protected function getErrorCode(): ?string /** * {@inheritdoc} */ - public function provideValidComparisons(): array + public static function provideValidComparisons(): array { return [ [3, 2], @@ -58,7 +58,7 @@ public function provideValidComparisons(): array /** * {@inheritdoc} */ - public function provideValidComparisonsToPropertyPath(): array + public static function provideValidComparisonsToPropertyPath(): array { return [ [5], @@ -69,7 +69,7 @@ public function provideValidComparisonsToPropertyPath(): array /** * {@inheritdoc} */ - public function provideInvalidComparisons(): array + public static function provideInvalidComparisons(): array { return [ [1, '1', 2, '2', 'int'], @@ -80,7 +80,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 3aea5554d..d6c6682fa 100644 --- a/Tests/Constraints/GreaterThanOrEqualValidatorWithPositiveOrZeroConstraintTest.php +++ b/Tests/Constraints/GreaterThanOrEqualValidatorWithPositiveOrZeroConstraintTest.php @@ -21,7 +21,7 @@ */ class GreaterThanOrEqualValidatorWithPositiveOrZeroConstraintTest extends GreaterThanOrEqualValidatorTest { - protected function createConstraint(array $options = null): Constraint + protected static function createConstraint(array $options = null): Constraint { return new PositiveOrZero(); } @@ -29,7 +29,7 @@ protected function createConstraint(array $options = null): Constraint /** * {@inheritdoc} */ - public function provideValidComparisons(): array + public static function provideValidComparisons(): array { return [ [0, 0], @@ -45,7 +45,7 @@ public function provideValidComparisons(): array /** * {@inheritdoc} */ - 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 7c6b693d3..5f68e6fe2 100644 --- a/Tests/Constraints/GreaterThanValidatorTest.php +++ b/Tests/Constraints/GreaterThanValidatorTest.php @@ -25,7 +25,7 @@ protected function createValidator() return new GreaterThanValidator(); } - protected function createConstraint(array $options = null): Constraint + protected static function createConstraint(array $options = null): Constraint { return new GreaterThan($options); } @@ -38,7 +38,7 @@ protected function getErrorCode(): ?string /** * {@inheritdoc} */ - public function provideValidComparisons(): array + public static function provideValidComparisons(): array { return [ [2, 1], @@ -54,7 +54,7 @@ public function provideValidComparisons(): array /** * {@inheritdoc} */ - public function provideValidComparisonsToPropertyPath(): array + public static function provideValidComparisonsToPropertyPath(): array { return [ [6], @@ -64,7 +64,7 @@ public function provideValidComparisonsToPropertyPath(): array /** * {@inheritdoc} */ - public function provideInvalidComparisons(): array + public static function provideInvalidComparisons(): array { return [ [1, '1', 2, '2', 'int'], @@ -82,7 +82,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 a16320c00..3b31ff4d0 100644 --- a/Tests/Constraints/GreaterThanValidatorWithPositiveConstraintTest.php +++ b/Tests/Constraints/GreaterThanValidatorWithPositiveConstraintTest.php @@ -21,7 +21,7 @@ */ class GreaterThanValidatorWithPositiveConstraintTest extends GreaterThanValidatorTest { - protected function createConstraint(array $options = null): Constraint + protected static function createConstraint(array $options = null): Constraint { return new Positive(); } @@ -29,7 +29,7 @@ protected function createConstraint(array $options = null): Constraint /** * {@inheritdoc} */ - public function provideValidComparisons(): array + public static function provideValidComparisons(): array { return [ [2, 0], @@ -42,7 +42,7 @@ public function provideValidComparisons(): array /** * {@inheritdoc} */ - public function provideInvalidComparisons(): array + public static function provideInvalidComparisons(): array { return [ [0, '0', 0, '0', 'int'], diff --git a/Tests/Constraints/IdenticalToValidatorTest.php b/Tests/Constraints/IdenticalToValidatorTest.php index 98c467bc7..f9cc83b51 100644 --- a/Tests/Constraints/IdenticalToValidatorTest.php +++ b/Tests/Constraints/IdenticalToValidatorTest.php @@ -25,7 +25,7 @@ protected function createValidator() return new IdenticalToValidator(); } - protected function createConstraint(array $options = null): Constraint + protected static function createConstraint(array $options = null): Constraint { return new IdenticalTo($options); } @@ -35,15 +35,16 @@ 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; } @@ -51,7 +52,7 @@ public function provideAllValidComparisons(): array /** * {@inheritdoc} */ - public function provideValidComparisons(): array + public static function provideValidComparisons(): array { $date = new \DateTime('2000-01-01'); $object = new ComparisonTest_Class(2); @@ -73,7 +74,7 @@ public function provideValidComparisons(): array /** * {@inheritdoc} */ - public function provideValidComparisonsToPropertyPath(): array + public static function provideValidComparisonsToPropertyPath(): array { return [ [5], @@ -83,7 +84,7 @@ public function provideValidComparisonsToPropertyPath(): array /** * {@inheritdoc} */ - public function provideInvalidComparisons(): array + public static function provideInvalidComparisons(): array { return [ [1, '1', 2, '2', 'int'], @@ -95,7 +96,7 @@ public function provideInvalidComparisons(): array ]; } - public function provideComparisonsToNullValueAtPropertyPath() + public static function provideComparisonsToNullValueAtPropertyPath() { return [ [5, '5', false], diff --git a/Tests/Constraints/LessThanOrEqualValidatorTest.php b/Tests/Constraints/LessThanOrEqualValidatorTest.php index 73c9a1d15..6072f6f22 100644 --- a/Tests/Constraints/LessThanOrEqualValidatorTest.php +++ b/Tests/Constraints/LessThanOrEqualValidatorTest.php @@ -25,7 +25,7 @@ protected function createValidator() return new LessThanOrEqualValidator(); } - protected function createConstraint(array $options = null): Constraint + protected static function createConstraint(array $options = null): Constraint { return new LessThanOrEqual($options); } @@ -38,7 +38,7 @@ protected function getErrorCode(): ?string /** * {@inheritdoc} */ - public function provideValidComparisons(): array + public static function provideValidComparisons(): array { return [ [1, 2], @@ -60,7 +60,7 @@ public function provideValidComparisons(): array /** * {@inheritdoc} */ - public function provideValidComparisonsToPropertyPath(): array + public static function provideValidComparisonsToPropertyPath(): array { return [ [4], @@ -71,7 +71,7 @@ public function provideValidComparisonsToPropertyPath(): array /** * {@inheritdoc} */ - public function provideInvalidComparisons(): array + public static function provideInvalidComparisons(): array { return [ [2, '2', 1, '1', 'int'], @@ -83,7 +83,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 24a2a3c9c..c5874ed5b 100644 --- a/Tests/Constraints/LessThanOrEqualValidatorWithNegativeOrZeroConstraintTest.php +++ b/Tests/Constraints/LessThanOrEqualValidatorWithNegativeOrZeroConstraintTest.php @@ -21,7 +21,7 @@ */ class LessThanOrEqualValidatorWithNegativeOrZeroConstraintTest extends LessThanOrEqualValidatorTest { - protected function createConstraint(array $options = null): Constraint + protected static function createConstraint(array $options = null): Constraint { return new NegativeOrZero(); } @@ -29,7 +29,7 @@ protected function createConstraint(array $options = null): Constraint /** * {@inheritdoc} */ - public function provideValidComparisons(): array + public static function provideValidComparisons(): array { return [ [0, 0], @@ -43,7 +43,7 @@ public function provideValidComparisons(): array /** * {@inheritdoc} */ - 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 7241203fc..acc815a04 100644 --- a/Tests/Constraints/LessThanValidatorTest.php +++ b/Tests/Constraints/LessThanValidatorTest.php @@ -25,7 +25,7 @@ protected function createValidator() return new LessThanValidator(); } - protected function createConstraint(array $options = null): Constraint + protected static function createConstraint(array $options = null): Constraint { return new LessThan($options); } @@ -38,7 +38,7 @@ protected function getErrorCode(): ?string /** * {@inheritdoc} */ - public function provideValidComparisons(): array + public static function provideValidComparisons(): array { return [ [1, 2], @@ -54,7 +54,7 @@ public function provideValidComparisons(): array /** * {@inheritdoc} */ - public function provideValidComparisonsToPropertyPath(): array + public static function provideValidComparisonsToPropertyPath(): array { return [ [4], @@ -64,7 +64,7 @@ public function provideValidComparisonsToPropertyPath(): array /** * {@inheritdoc} */ - public function provideInvalidComparisons(): array + public static function provideInvalidComparisons(): array { return [ [3, '3', 2, '2', 'int'], @@ -81,7 +81,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 aba9f78c4..5e7173c30 100644 --- a/Tests/Constraints/LessThanValidatorWithNegativeConstraintTest.php +++ b/Tests/Constraints/LessThanValidatorWithNegativeConstraintTest.php @@ -21,7 +21,7 @@ */ class LessThanValidatorWithNegativeConstraintTest extends LessThanValidatorTest { - protected function createConstraint(array $options = null): Constraint + protected static function createConstraint(array $options = null): Constraint { return new Negative(); } @@ -29,7 +29,7 @@ protected function createConstraint(array $options = null): Constraint /** * {@inheritdoc} */ - public function provideValidComparisons(): array + public static function provideValidComparisons(): array { return [ [-1, 0], @@ -42,7 +42,7 @@ public function provideValidComparisons(): array /** * {@inheritdoc} */ - public function provideInvalidComparisons(): array + public static function provideInvalidComparisons(): array { return [ [0, '0', 0, '0', 'int'], diff --git a/Tests/Constraints/NotEqualToValidatorTest.php b/Tests/Constraints/NotEqualToValidatorTest.php index 47cdcac96..465458b07 100644 --- a/Tests/Constraints/NotEqualToValidatorTest.php +++ b/Tests/Constraints/NotEqualToValidatorTest.php @@ -25,7 +25,7 @@ protected function createValidator() return new NotEqualToValidator(); } - protected function createConstraint(array $options = null): Constraint + protected static function createConstraint(array $options = null): Constraint { return new NotEqualTo($options); } @@ -38,7 +38,7 @@ protected function getErrorCode(): ?string /** * {@inheritdoc} */ - public function provideValidComparisons(): array + public static function provideValidComparisons(): array { return [ [1, 2], @@ -54,7 +54,7 @@ public function provideValidComparisons(): array /** * {@inheritdoc} */ - public function provideValidComparisonsToPropertyPath(): array + public static function provideValidComparisonsToPropertyPath(): array { return [ [0], @@ -64,7 +64,7 @@ public function provideValidComparisonsToPropertyPath(): array /** * {@inheritdoc} */ - public function provideInvalidComparisons(): array + public static function provideInvalidComparisons(): array { return [ [3, '3', 3, '3', 'int'], @@ -77,7 +77,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 41660bda5..49cff9912 100644 --- a/Tests/Constraints/NotIdenticalToValidatorTest.php +++ b/Tests/Constraints/NotIdenticalToValidatorTest.php @@ -25,7 +25,7 @@ protected function createValidator() return new NotIdenticalToValidator(); } - protected function createConstraint(array $options = null): Constraint + protected static function createConstraint(array $options = null): Constraint { return new NotIdenticalTo($options); } @@ -38,7 +38,7 @@ protected function getErrorCode(): ?string /** * {@inheritdoc} */ - public function provideValidComparisons(): array + public static function provideValidComparisons(): array { return [ [1, 2], @@ -57,22 +57,23 @@ public function provideValidComparisons(): array /** * {@inheritdoc} */ - 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; } @@ -80,7 +81,7 @@ public function provideAllInvalidComparisons(): array /** * {@inheritdoc} */ - public function provideInvalidComparisons(): array + public static function provideInvalidComparisons(): array { $date = new \DateTime('2000-01-01'); $object = new ComparisonTest_Class(2); @@ -95,7 +96,7 @@ public function provideInvalidComparisons(): array return $comparisons; } - public function provideComparisonsToNullValueAtPropertyPath() + public static function provideComparisonsToNullValueAtPropertyPath() { return [ [5, '5', true], From dffbaf49e846cfbd350b027e22778fd48cca99bf Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Wed, 8 Feb 2023 13:54:12 +0100 Subject: [PATCH 05/18] [Tests] Migrate tests to static data providers --- Tests/Constraints/CountValidatorArrayTest.php | 2 +- .../CountValidatorCountableTest.php | 2 +- Tests/Constraints/CountValidatorTestCase.php | 32 ++++++++----- Tests/Constraints/IpValidatorTest.php | 48 +++++++++---------- Tests/Constraints/IsbnValidatorTest.php | 20 ++++---- Tests/Constraints/IssnValidatorTest.php | 16 +++---- Tests/Constraints/RangeValidatorTest.php | 33 +++++++++---- Tests/Constraints/TypeValidatorTest.php | 22 ++++----- 8 files changed, 98 insertions(+), 77 deletions(-) diff --git a/Tests/Constraints/CountValidatorArrayTest.php b/Tests/Constraints/CountValidatorArrayTest.php index cc258cfca..1f441ea13 100644 --- a/Tests/Constraints/CountValidatorArrayTest.php +++ b/Tests/Constraints/CountValidatorArrayTest.php @@ -16,7 +16,7 @@ */ 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 276076e88..48a8063e5 100644 --- a/Tests/Constraints/CountValidatorCountableTest.php +++ b/Tests/Constraints/CountValidatorCountableTest.php @@ -18,7 +18,7 @@ */ class CountValidatorCountableTest extends CountValidatorTestCase { - protected function createCollection(array $content) + protected static function createCollection(array $content) { return new Countable($content); } diff --git a/Tests/Constraints/CountValidatorTestCase.php b/Tests/Constraints/CountValidatorTestCase.php index f011f226c..68b8766c5 100644 --- a/Tests/Constraints/CountValidatorTestCase.php +++ b/Tests/Constraints/CountValidatorTestCase.php @@ -27,7 +27,7 @@ protected function createValidator() 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])], ]; } @@ -82,6 +82,7 @@ public function testValidValuesMax($value) /** * @requires PHP 8 + * * @dataProvider getThreeOrLessElements */ public function testValidValuesMaxNamed($value) @@ -105,6 +106,7 @@ public function testValidValuesMin($value) /** * @requires PHP 8 + * * @dataProvider getFiveOrMoreElements */ public function testValidValuesMinNamed($value) @@ -128,6 +130,7 @@ public function testValidValuesExact($value) /** * @requires PHP 8 + * * @dataProvider getFourElements */ public function testValidValuesExactNamed($value) @@ -161,6 +164,7 @@ public function testTooManyValues($value) /** * @requires PHP 8 + * * @dataProvider getFiveOrMoreElements */ public function testTooManyValuesNamed($value) @@ -201,6 +205,7 @@ public function testTooFewValues($value) /** * @requires PHP 8 + * * @dataProvider getThreeOrLessElements */ public function testTooFewValuesNamed($value) @@ -242,6 +247,7 @@ public function testTooManyValuesExact($value) /** * @requires PHP 8 + * * @dataProvider getFiveOrMoreElements */ public function testTooManyValuesExactNamed($value) diff --git a/Tests/Constraints/IpValidatorTest.php b/Tests/Constraints/IpValidatorTest.php index f2cfa0a3f..b00f94244 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'], @@ -104,7 +104,7 @@ public function testValidIpV6WithWhitespacesNamed() $this->assertNoViolation(); } - public function getValidIpsV4WithWhitespaces() + public static function getValidIpsV4WithWhitespaces() { return [ ["\x200.0.0.0"], @@ -128,7 +128,7 @@ public function testValidIpsV6($ip) $this->assertNoViolation(); } - public function getValidIpsV6() + public static function getValidIpsV6() { return [ ['2001:0db8:85a3:0000:0000:8a2e:0370:7334'], @@ -165,9 +165,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()); } /** @@ -188,7 +188,7 @@ public function testInvalidIpsV4($ip) ->assertRaised(); } - public function getInvalidIpsV4() + public static function getInvalidIpsV4() { return [ ['0'], @@ -221,7 +221,7 @@ public function testInvalidPrivateIpsV4($ip) ->assertRaised(); } - public function getInvalidPrivateIpsV4() + public static function getInvalidPrivateIpsV4() { return [ ['10.0.0.0'], @@ -248,7 +248,7 @@ public function testInvalidReservedIpsV4($ip) ->assertRaised(); } - public function getInvalidReservedIpsV4() + public static function getInvalidReservedIpsV4() { return [ ['0.0.0.0'], @@ -275,9 +275,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()); } /** @@ -298,7 +298,7 @@ public function testInvalidIpsV6($ip) ->assertRaised(); } - public function getInvalidIpsV6() + public static function getInvalidIpsV6() { return [ ['z001:0db8:85a3:0000:0000:8a2e:0370:7334'], @@ -335,7 +335,7 @@ public function testInvalidPrivateIpsV6($ip) ->assertRaised(); } - public function getInvalidPrivateIpsV6() + public static function getInvalidPrivateIpsV6() { return [ ['fdfe:dcba:9876:ffff:fdc6:c46b:bb8f:7d4c'], @@ -362,12 +362,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(); } /** @@ -388,9 +388,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()); } /** @@ -411,9 +411,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()); } /** @@ -434,9 +434,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()); } /** @@ -457,9 +457,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()); } /** @@ -480,8 +480,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/IsbnValidatorTest.php b/Tests/Constraints/IsbnValidatorTest.php index 25889b077..fc872ad47 100644 --- a/Tests/Constraints/IsbnValidatorTest.php +++ b/Tests/Constraints/IsbnValidatorTest.php @@ -26,7 +26,7 @@ protected function createValidator() 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/IssnValidatorTest.php b/Tests/Constraints/IssnValidatorTest.php index ea2ca4ecd..287f8c144 100644 --- a/Tests/Constraints/IssnValidatorTest.php +++ b/Tests/Constraints/IssnValidatorTest.php @@ -26,7 +26,7 @@ protected function createValidator() 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/RangeValidatorTest.php b/Tests/Constraints/RangeValidatorTest.php index 7a34810bd..d67bbe526 100644 --- a/Tests/Constraints/RangeValidatorTest.php +++ b/Tests/Constraints/RangeValidatorTest.php @@ -78,6 +78,7 @@ public function testValidValuesMin($value) /** * @requires PHP 8 + * * @dataProvider getTenToTwenty */ public function testValidValuesMinNamed($value) @@ -101,6 +102,7 @@ public function testValidValuesMax($value) /** * @requires PHP 8 + * * @dataProvider getTenToTwenty */ public function testValidValuesMaxNamed($value) @@ -124,6 +126,7 @@ public function testValidValuesMinMax($value) /** * @requires PHP 8 + * * @dataProvider getTenToTwenty */ public function testValidValuesMinMaxNamed($value) @@ -155,6 +158,7 @@ public function testInvalidValuesMin($value, $formattedValue) /** * @requires PHP 8 + * * @dataProvider getLessThanTen */ public function testInvalidValuesMinNamed($value, $formattedValue) @@ -191,6 +195,7 @@ public function testInvalidValuesMax($value, $formattedValue) /** * @requires PHP 8 + * * @dataProvider getMoreThanTwenty */ public function testInvalidValuesMaxNamed($value, $formattedValue) @@ -229,6 +234,7 @@ public function testInvalidValuesCombinedMax($value, $formattedValue) /** * @requires PHP 8 + * * @dataProvider getMoreThanTwenty */ public function testInvalidValuesCombinedMaxNamed($value, $formattedValue) @@ -268,6 +274,7 @@ public function testInvalidValuesCombinedMin($value, $formattedValue) /** * @requires PHP 8 + * * @dataProvider getLessThanTen */ public function testInvalidValuesCombinedMinNamed($value, $formattedValue) @@ -284,11 +291,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')], @@ -300,16 +308,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'], @@ -319,16 +328,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'], @@ -338,7 +348,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; } @@ -639,6 +649,7 @@ public function testValidValuesMinPropertyPath($value) /** * @requires PHP 8 + * * @dataProvider getTenToTwenty */ public function testValidValuesMinPropertyPathNamed($value) @@ -666,6 +677,7 @@ public function testValidValuesMaxPropertyPath($value) /** * @requires PHP 8 + * * @dataProvider getTenToTwenty */ public function testValidValuesMaxPropertyPathNamed($value) @@ -763,6 +775,7 @@ public function testInvalidValuesCombinedMaxPropertyPath($value, $formattedValue /** * @requires PHP 8 + * * @dataProvider getMoreThanTwenty */ public function testInvalidValuesCombinedMaxPropertyPathNamed($value, $formattedValue) @@ -814,6 +827,7 @@ public function testInvalidValuesCombinedMinPropertyPath($value, $formattedValue /** * @requires PHP 8 + * * @dataProvider getLessThanTen */ public function testInvalidValuesCombinedMinPropertyPathNamed($value, $formattedValue) @@ -1074,6 +1088,7 @@ public function provideMessageIfMinAndMaxSet(): array /** * @group legacy + * * @dataProvider provideMessageIfMinAndMaxSet */ public function testMessageIfMinAndMaxSet(array $constraintExtraOptions, int $value, string $expectedMessage, string $expectedCode) diff --git a/Tests/Constraints/TypeValidatorTest.php b/Tests/Constraints/TypeValidatorTest.php index 024de4553..088bb40c7 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"'], @@ -209,20 +209,20 @@ public function provideConstraintsWithMultipleTypes() } } - 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; } } } From 1b94a1cc9a416cb14a4c1c2cec6f09950d70dafd Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Wed, 14 Dec 2022 15:42:16 +0100 Subject: [PATCH 06/18] Migrate to `static` data providers using `rector/rector` --- Tests/ConstraintValidatorTest.php | 2 +- Tests/ConstraintViolationListTest.php | 2 +- Tests/Constraints/AllValidatorTest.php | 2 +- .../Constraints/AtLeastOneOfValidatorTest.php | 4 +- Tests/Constraints/BicValidatorTest.php | 6 +-- Tests/Constraints/BlankValidatorTest.php | 2 +- Tests/Constraints/CardSchemeValidatorTest.php | 4 +- Tests/Constraints/ChoiceValidatorTest.php | 14 +++---- Tests/Constraints/CidrTest.php | 4 +- Tests/Constraints/CidrValidatorTest.php | 12 +++--- Tests/Constraints/CountryValidatorTest.php | 8 ++-- Tests/Constraints/CssColorValidatorTest.php | 38 +++++++++---------- Tests/Constraints/CurrencyValidatorTest.php | 4 +- Tests/Constraints/DateTimeValidatorTest.php | 4 +- Tests/Constraints/DateValidatorTest.php | 4 +- .../Constraints/DivisibleByValidatorTest.php | 2 +- Tests/Constraints/EmailValidatorTest.php | 12 +++--- .../ExpressionLanguageSyntaxTest.php | 2 +- Tests/Constraints/FileTest.php | 6 +-- Tests/Constraints/FileValidatorTestCase.php | 12 +++--- Tests/Constraints/HostnameValidatorTest.php | 8 ++-- Tests/Constraints/IbanValidatorTest.php | 10 ++--- Tests/Constraints/ImageValidatorTest.php | 26 ++++++------- Tests/Constraints/IsFalseValidatorTest.php | 2 +- Tests/Constraints/IsNullValidatorTest.php | 2 +- Tests/Constraints/IsTrueValidatorTest.php | 2 +- Tests/Constraints/IsinValidatorTest.php | 8 ++-- Tests/Constraints/JsonValidatorTest.php | 4 +- Tests/Constraints/LanguageValidatorTest.php | 8 ++-- Tests/Constraints/LengthTest.php | 2 +- Tests/Constraints/LengthValidatorTest.php | 10 ++--- Tests/Constraints/LocaleValidatorTest.php | 6 +-- Tests/Constraints/LuhnValidatorTest.php | 6 +-- Tests/Constraints/NotBlankValidatorTest.php | 4 +- .../NotCompromisedPasswordValidatorTest.php | 4 +- Tests/Constraints/NotNullValidatorTest.php | 4 +- Tests/Constraints/RangeTest.php | 4 +- Tests/Constraints/RangeValidatorTest.php | 10 ++--- Tests/Constraints/RegexTest.php | 2 +- Tests/Constraints/RegexValidatorTest.php | 6 +-- Tests/Constraints/TimeValidatorTest.php | 4 +- Tests/Constraints/TimezoneTest.php | 2 +- Tests/Constraints/TimezoneValidatorTest.php | 14 +++---- Tests/Constraints/TypeValidatorTest.php | 4 +- Tests/Constraints/UlidValidatorTest.php | 2 +- Tests/Constraints/UniqueValidatorTest.php | 6 +-- Tests/Constraints/UrlValidatorTest.php | 12 +++--- Tests/Constraints/UuidValidatorTest.php | 10 ++--- .../AddAutoMappingConfigurationPassTest.php | 2 +- Tests/Mapping/Loader/AnnotationLoaderTest.php | 2 +- .../Mapping/Loader/PropertyInfoLoaderTest.php | 2 +- Tests/Mapping/Loader/YamlFileLoaderTest.php | 2 +- Tests/Resources/TranslationFilesTest.php | 2 +- Tests/Util/PropertyPathTest.php | 2 +- Tests/Validator/RecursiveValidatorTest.php | 4 +- 55 files changed, 171 insertions(+), 171 deletions(-) diff --git a/Tests/ConstraintValidatorTest.php b/Tests/ConstraintValidatorTest.php index aeaef472f..128a41c06 100644 --- a/Tests/ConstraintValidatorTest.php +++ b/Tests/ConstraintValidatorTest.php @@ -27,7 +27,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 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/AllValidatorTest.php b/Tests/Constraints/AllValidatorTest.php index 0daa82498..ff884d43a 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 0fb735a84..3685a67b6 100644 --- a/Tests/Constraints/AtLeastOneOfValidatorTest.php +++ b/Tests/Constraints/AtLeastOneOfValidatorTest.php @@ -56,7 +56,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 +125,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', [ diff --git a/Tests/Constraints/BicValidatorTest.php b/Tests/Constraints/BicValidatorTest.php index 20c9d7c54..97239ab71 100644 --- a/Tests/Constraints/BicValidatorTest.php +++ b/Tests/Constraints/BicValidatorTest.php @@ -197,7 +197,7 @@ public function testValidBics($bic) $this->assertNoViolation(); } - public function getValidBics() + public static function getValidBics() { // http://formvalidation.io/validators/bic/ return [ @@ -243,7 +243,7 @@ public function testInvalidBicsNamed($bic, $code) ->assertRaised(); } - public function getInvalidBics() + public static function getInvalidBics() { return [ ['DEUTD', Bic::INVALID_LENGTH_ERROR], @@ -287,7 +287,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']; diff --git a/Tests/Constraints/BlankValidatorTest.php b/Tests/Constraints/BlankValidatorTest.php index 1d138348a..95f5bc8f7 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 100a3811b..dcb40c9e7 100644 --- a/Tests/Constraints/CardSchemeValidatorTest.php +++ b/Tests/Constraints/CardSchemeValidatorTest.php @@ -90,7 +90,7 @@ public function testInvalidNumberNamedArguments() ->assertRaised(); } - public function getValidNumbers() + public static function getValidNumbers() { return [ ['AMEX', '378282246310005'], @@ -145,7 +145,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 262e8654f..5c3bcc472 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']])]; @@ -105,7 +105,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([ @@ -156,7 +156,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'], @@ -185,7 +185,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'])]; @@ -227,7 +227,7 @@ public function testInvalidChoiceMultiple(Choice $constraint) ->assertRaised(); } - public function provideConstraintsWithMultipleMessage(): iterable + public static function provideConstraintsWithMultipleMessage(): iterable { yield 'Doctrine style' => [new Choice([ 'choices' => ['foo', 'bar'], @@ -263,7 +263,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'], @@ -301,7 +301,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 571cdbf27..dc41ae1f0 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/CountryValidatorTest.php b/Tests/Constraints/CountryValidatorTest.php index 71cb41c46..be80a9e63 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 dcca9e0ed..6a0773ac6 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'], @@ -128,7 +128,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 aa956c143..4438d2f48 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 af1652589..b2e9fdf5e 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'], @@ -94,7 +94,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 0074d0a9f..ebcf9b849 100644 --- a/Tests/Constraints/DivisibleByValidatorTest.php +++ b/Tests/Constraints/DivisibleByValidatorTest.php @@ -104,7 +104,7 @@ public function testThrowsOnNonNumericValues(string $expectedGivenType, $value, ])); } - public function throwsOnNonNumericValuesProvider() + public static function throwsOnNonNumericValuesProvider() { return [ [\stdClass::class, 2, new \stdClass()], diff --git a/Tests/Constraints/EmailValidatorTest.php b/Tests/Constraints/EmailValidatorTest.php index 3fff0c35d..fa829e77b 100644 --- a/Tests/Constraints/EmailValidatorTest.php +++ b/Tests/Constraints/EmailValidatorTest.php @@ -70,7 +70,7 @@ public function testValidEmails($email) $this->assertNoViolation(); } - public function getValidEmails() + public static function getValidEmails() { return [ ['fabien@symfony.com'], @@ -94,7 +94,7 @@ public function testValidNormalizedEmails($email) $this->assertNoViolation(); } - public function getValidEmailsWithWhitespaces() + public static function getValidEmailsWithWhitespaces() { return [ ["\x20example@example.co.uk\x20"], @@ -116,7 +116,7 @@ public function testValidEmailsHtml5($email) $this->assertNoViolation(); } - public function getValidEmailsHtml5() + public static function getValidEmailsHtml5() { return [ ['fabien@symfony.com'], @@ -143,7 +143,7 @@ public function testInvalidEmails($email) ->assertRaised(); } - public function getInvalidEmails() + public static function getInvalidEmails() { return [ ['example'], @@ -171,7 +171,7 @@ public function testInvalidHtml5Emails($email) ->assertRaised(); } - public function getInvalidHtml5Emails() + public static function getInvalidHtml5Emails() { return [ ['example'], @@ -255,7 +255,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/ExpressionLanguageSyntaxTest.php b/Tests/Constraints/ExpressionLanguageSyntaxTest.php index 1c57d56f0..3894269a9 100644 --- a/Tests/Constraints/ExpressionLanguageSyntaxTest.php +++ b/Tests/Constraints/ExpressionLanguageSyntaxTest.php @@ -34,7 +34,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/FileTest.php b/Tests/Constraints/FileTest.php index 31227bb73..d12c1ad96 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/FileValidatorTestCase.php b/Tests/Constraints/FileValidatorTestCase.php index de58d6d87..cd16f8b4b 100644 --- a/Tests/Constraints/FileValidatorTestCase.php +++ b/Tests/Constraints/FileValidatorTestCase.php @@ -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 @@ -182,7 +182,7 @@ public function testMaxSizeExceeded($bytesWritten, $limit, $sizeAsString, $limit ->assertRaised(); } - public function provideMaxSizeNotExceededTests() + public static function provideMaxSizeNotExceededTests() { return [ // 0 has no effect @@ -237,7 +237,7 @@ public function testInvalidMaxSize() $this->validator->validate($this->path, $constraint); } - public function provideBinaryFormatTests() + public static function provideBinaryFormatTests() { return [ [11, 10, null, '11', '10', 'bytes'], @@ -386,7 +386,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'], @@ -447,7 +447,7 @@ public function testDisallowEmpty(File $constraint) ->assertRaised(); } - public function provideDisallowEmptyConstraints(): iterable + public static function provideDisallowEmptyConstraints(): iterable { yield 'Doctrine style' => [new File([ 'disallowEmptyMessage' => 'myMessage', @@ -480,7 +480,7 @@ public function testUploadedFileError($error, $message, array $params = [], $max ->assertRaised(); } - public function uploadedFileErrorProvider() + public static function uploadedFileErrorProvider() { $tests = [ [(string) \UPLOAD_ERR_FORM_SIZE, 'uploadFormSizeErrorMessage'], diff --git a/Tests/Constraints/HostnameValidatorTest.php b/Tests/Constraints/HostnameValidatorTest.php index 16c312170..4ac197039 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'], @@ -200,7 +200,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 6274a41cd..257f47b03 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 @@ -170,7 +170,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 @@ -289,7 +289,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 @@ -401,7 +401,7 @@ public function testIbansWithUnsupportedCountryCode($countryCode) $this->assertViolationRaised($countryCode.'260211000000230064016', Iban::NOT_SUPPORTED_COUNTRY_CODE_ERROR); } - public function getUnsupportedCountryCodes() + public static function getUnsupportedCountryCodes() { return [ ['AG'], @@ -443,7 +443,7 @@ public function testLoadFromAttribute() ->assertRaised(); } - public function getIbansWithInvalidCountryCode() + public static function getIbansWithInvalidCountryCode() { return [ ['0750447346'], diff --git a/Tests/Constraints/ImageValidatorTest.php b/Tests/Constraints/ImageValidatorTest.php index b43e76559..862876a0b 100644 --- a/Tests/Constraints/ImageValidatorTest.php +++ b/Tests/Constraints/ImageValidatorTest.php @@ -91,7 +91,7 @@ public function testFileNotFound(Image $constraint) ->assertRaised(); } - public function provideConstraintsWithNotFoundMessage(): iterable + public static function provideConstraintsWithNotFoundMessage(): iterable { yield 'Doctrine style' => [new Image([ 'notFoundMessage' => 'myMessage', @@ -132,7 +132,7 @@ public function testWidthTooSmall(Image $constraint) ->assertRaised(); } - public function provideMinWidthConstraints(): iterable + public static function provideMinWidthConstraints(): iterable { yield 'Doctrine style' => [new Image([ 'minWidth' => 3, @@ -160,7 +160,7 @@ public function testWidthTooBig(Image $constraint) ->assertRaised(); } - public function provideMaxWidthConstraints(): iterable + public static function provideMaxWidthConstraints(): iterable { yield 'Doctrine style' => [new Image([ 'maxWidth' => 1, @@ -188,7 +188,7 @@ public function testHeightTooSmall(Image $constraint) ->assertRaised(); } - public function provideMinHeightConstraints(): iterable + public static function provideMinHeightConstraints(): iterable { yield 'Doctrine style' => [new Image([ 'minHeight' => 3, @@ -216,7 +216,7 @@ public function testHeightTooBig(Image $constraint) ->assertRaised(); } - public function provideMaxHeightConstraints(): iterable + public static function provideMaxHeightConstraints(): iterable { yield 'Doctrine style' => [new Image([ 'maxHeight' => 1, @@ -246,7 +246,7 @@ public function testPixelsTooFew(Image $constraint) ->assertRaised(); } - public function provideMinPixelsConstraints(): iterable + public static function provideMinPixelsConstraints(): iterable { yield 'Doctrine style' => [new Image([ 'minPixels' => 5, @@ -276,7 +276,7 @@ public function testPixelsTooMany(Image $constraint) ->assertRaised(); } - public function provideMaxPixelsConstraints(): iterable + public static function provideMaxPixelsConstraints(): iterable { yield 'Doctrine style' => [new Image([ 'maxPixels' => 3, @@ -364,7 +364,7 @@ public function testRatioTooSmall(Image $constraint) ->assertRaised(); } - public function provideMinRatioConstraints(): iterable + public static function provideMinRatioConstraints(): iterable { yield 'Doctrine style' => [new Image([ 'minRatio' => 2, @@ -392,7 +392,7 @@ public function testRatioTooBig(Image $constraint) ->assertRaised(); } - public function provideMaxRatioConstraints(): iterable + public static function provideMaxRatioConstraints(): iterable { yield 'Doctrine style' => [new Image([ 'maxRatio' => 0.5, @@ -473,7 +473,7 @@ public function testSquareNotAllowed(Image $constraint) ->assertRaised(); } - public function provideAllowSquareConstraints(): iterable + public static function provideAllowSquareConstraints(): iterable { yield 'Doctrine style' => [new Image([ 'allowSquare' => false, @@ -501,7 +501,7 @@ public function testLandscapeNotAllowed(Image $constraint) ->assertRaised(); } - public function provideAllowLandscapeConstraints(): iterable + public static function provideAllowLandscapeConstraints(): iterable { yield 'Doctrine style' => [new Image([ 'allowLandscape' => false, @@ -529,7 +529,7 @@ public function testPortraitNotAllowed(Image $constraint) ->assertRaised(); } - public function provideAllowPortraitConstraints(): iterable + public static function provideAllowPortraitConstraints(): iterable { yield 'Doctrine style' => [new Image([ 'allowPortrait' => false, @@ -578,7 +578,7 @@ public function testInvalidMimeType() ->assertRaised(); } - public function provideDetectCorruptedConstraints(): iterable + public static function provideDetectCorruptedConstraints(): iterable { yield 'Doctrine style' => [new Image([ 'detectCorrupted' => true, diff --git a/Tests/Constraints/IsFalseValidatorTest.php b/Tests/Constraints/IsFalseValidatorTest.php index 1ec75dcb8..567ddfe99 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 f3128eb23..875773eb6 100644 --- a/Tests/Constraints/IsNullValidatorTest.php +++ b/Tests/Constraints/IsNullValidatorTest.php @@ -62,7 +62,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 e12cbdde3..81c6067ea 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/IsinValidatorTest.php b/Tests/Constraints/IsinValidatorTest.php index 9f1949393..44c55d9fc 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/JsonValidatorTest.php b/Tests/Constraints/JsonValidatorTest.php index 6c94c1d8d..a336e680d 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 23df11387..15f7ddc42 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/LengthTest.php b/Tests/Constraints/LengthTest.php index 90c57bed6..2d7d12576 100644 --- a/Tests/Constraints/LengthTest.php +++ b/Tests/Constraints/LengthTest.php @@ -57,7 +57,7 @@ public function testDeprecatedAllowEmptyStringOption(bool $value) new Length(['allowEmptyString' => $value, 'max' => 5]); } - public function allowEmptyStringOptionData() + public static function allowEmptyStringOptionData() { return [ [true], diff --git a/Tests/Constraints/LengthValidatorTest.php b/Tests/Constraints/LengthValidatorTest.php index 5772d6e0a..babe2737e 100644 --- a/Tests/Constraints/LengthValidatorTest.php +++ b/Tests/Constraints/LengthValidatorTest.php @@ -62,7 +62,7 @@ public function testExpectsStringCompatibleType() $this->validator->validate(new \stdClass(), new Length(['value' => 5])); } - public function getThreeOrLessCharacters() + public static function getThreeOrLessCharacters() { return [ [12], @@ -76,7 +76,7 @@ public function getThreeOrLessCharacters() ]; } - public function getFourCharacters() + public static function getFourCharacters() { return [ [1234], @@ -86,7 +86,7 @@ public function getFourCharacters() ]; } - public function getFiveOrMoreCharacters() + public static function getFiveOrMoreCharacters() { return [ [12345], @@ -100,7 +100,7 @@ public function getFiveOrMoreCharacters() ]; } - public function getOneCharset() + public static function getOneCharset() { return [ ['é', 'utf8', true], @@ -110,7 +110,7 @@ public function getOneCharset() ]; } - public function getThreeCharactersWithWhitespaces() + public static function getThreeCharactersWithWhitespaces() { return [ ["\x20ccc"], diff --git a/Tests/Constraints/LocaleValidatorTest.php b/Tests/Constraints/LocaleValidatorTest.php index 7c3746f5c..91153cad4 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'], @@ -154,7 +154,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 5dc15b41a..17f38bee4 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 3bf322052..1437c0109 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 4209c45c7..8a3d343b2 100644 --- a/Tests/Constraints/NotCompromisedPasswordValidatorTest.php +++ b/Tests/Constraints/NotCompromisedPasswordValidatorTest.php @@ -103,7 +103,7 @@ public function testThresholdNotReached(NotCompromisedPassword $constraint) $this->assertNoViolation(); } - public function provideConstraintsWithThreshold(): iterable + public static function provideConstraintsWithThreshold(): iterable { yield 'Doctrine style' => [new NotCompromisedPassword(['threshold' => 10])]; @@ -218,7 +218,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])]; diff --git a/Tests/Constraints/NotNullValidatorTest.php b/Tests/Constraints/NotNullValidatorTest.php index abaa7f874..1b54c420d 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 542cb3996..0982254b7 100644 --- a/Tests/Constraints/RangeTest.php +++ b/Tests/Constraints/RangeTest.php @@ -74,7 +74,7 @@ public function testThrowsNoDefaultOptionConfiguredException() new Range('value'); } - public function provideDeprecationTriggeredIfMinMaxAndMinMessageOrMaxMessageSet(): array + public static function provideDeprecationTriggeredIfMinMaxAndMinMessageOrMaxMessageSet(): array { return [ [['min' => 1, 'max' => 10, 'minMessage' => 'my_min_message'], true, false], @@ -96,7 +96,7 @@ public function testDeprecationTriggeredIfMinMaxAndMinMessageOrMaxMessageSet(arr $this->assertEquals($expectedDeprecatedMaxMessageSet, $sut->deprecatedMaxMessageSet); } - public function provideDeprecationNotTriggeredIfNotMinMaxOrNotMinMessageNorMaxMessageSet(): array + public static function provideDeprecationNotTriggeredIfNotMinMaxOrNotMinMessageNorMaxMessageSet(): array { return [ [['min' => 1, 'minMessage' => 'my_min_message', 'maxMessage' => 'my_max_message']], diff --git a/Tests/Constraints/RangeValidatorTest.php b/Tests/Constraints/RangeValidatorTest.php index d67bbe526..2f7da2417 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'], @@ -610,7 +610,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], @@ -1042,7 +1042,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 1b9f25c36..384e53fe7 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 63645ca04..e46a53efa 100644 --- a/Tests/Constraints/RegexValidatorTest.php +++ b/Tests/Constraints/RegexValidatorTest.php @@ -77,7 +77,7 @@ public function testValidValuesWithWhitespacesNamed($value) $this->assertNoViolation(); } - public function getValidValues() + public static function getValidValues() { return [ [0], @@ -93,7 +93,7 @@ public function __toString(): string ]; } - public function getValidValuesWithWhitespaces() + public static function getValidValuesWithWhitespaces() { return [ ["\x207"], @@ -139,7 +139,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 0e0a23fbb..80d21d5c2 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 271b17174..e5a0cd366 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 3b00b75ac..3e0b23f04 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']; @@ -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 @@ -210,7 +210,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 @@ -251,7 +251,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']; @@ -305,7 +305,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 088bb40c7..e7687da58 100644 --- a/Tests/Constraints/TypeValidatorTest.php +++ b/Tests/Constraints/TypeValidatorTest.php @@ -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'], diff --git a/Tests/Constraints/UlidValidatorTest.php b/Tests/Constraints/UlidValidatorTest.php index 8948cbabd..c7b94fdde 100644 --- a/Tests/Constraints/UlidValidatorTest.php +++ b/Tests/Constraints/UlidValidatorTest.php @@ -71,7 +71,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 6b892cb0a..417050bd8 100644 --- a/Tests/Constraints/UniqueValidatorTest.php +++ b/Tests/Constraints/UniqueValidatorTest.php @@ -39,7 +39,7 @@ public function testValidValues($value) $this->assertNoViolation(); } - public function getValidValues() + public static function getValidValues() { return [ yield 'null' => [[null]], @@ -72,7 +72,7 @@ public function testInvalidValues($value) ->assertRaised(); } - public function getInvalidValues() + public static function getInvalidValues() { $object = new \stdClass(); @@ -156,7 +156,7 @@ public function testExpectsNonUniqueObjects($callback) ->assertRaised(); } - public function getCallback() + public static function getCallback() { return [ yield 'static function' => [static function (\stdClass $object) { diff --git a/Tests/Constraints/UrlValidatorTest.php b/Tests/Constraints/UrlValidatorTest.php index 8227cd73f..e7bd83d07 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 672a594e9..d6d6e8069 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 @@ -101,7 +101,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 @@ -147,7 +147,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], @@ -206,7 +206,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 @@ -241,7 +241,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/Mapping/Loader/AnnotationLoaderTest.php b/Tests/Mapping/Loader/AnnotationLoaderTest.php index ab0f79663..020b554ac 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']; 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 1813019b4..8ddcd02f1 100644 --- a/Tests/Mapping/Loader/YamlFileLoaderTest.php +++ b/Tests/Mapping/Loader/YamlFileLoaderTest.php @@ -52,7 +52,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 7fa81d9fe..68f7e9b11 100644 --- a/Tests/Resources/TranslationFilesTest.php +++ b/Tests/Resources/TranslationFilesTest.php @@ -45,7 +45,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 c78eb7544..2bb212eaa 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 [ [ From e34c97598a7d9b2c2b662e619e8e46748ed31ff7 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 14 Feb 2023 09:53:37 +0100 Subject: [PATCH 07/18] Fix merge --- Tests/Constraints/ExpressionSyntaxTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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'])]; From 535d93fe0572bba5cacb6475c0d32cd46bebc12f Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 16 Feb 2023 10:33:00 +0100 Subject: [PATCH 08/18] CS fix --- Tests/Constraints/BicValidatorTest.php | 1 + Tests/Constraints/CssColorTest.php | 1 + Tests/Constraints/CurrencyValidatorTest.php | 1 + Tests/Constraints/IsNullValidatorTest.php | 1 + Tests/Constraints/LengthTest.php | 1 + Tests/Constraints/LengthValidatorTest.php | 3 +++ Tests/Constraints/RangeTest.php | 2 ++ Tests/Constraints/RegexValidatorTest.php | 2 ++ Tests/Constraints/UlidValidatorTest.php | 3 +-- 9 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Tests/Constraints/BicValidatorTest.php b/Tests/Constraints/BicValidatorTest.php index 97239ab71..564fa30c9 100644 --- a/Tests/Constraints/BicValidatorTest.php +++ b/Tests/Constraints/BicValidatorTest.php @@ -229,6 +229,7 @@ public function testInvalidBics($bic, $code) /** * @requires PHP 8 + * * @dataProvider getInvalidBics */ public function testInvalidBicsNamed($bic, $code) diff --git a/Tests/Constraints/CssColorTest.php b/Tests/Constraints/CssColorTest.php index fcf58b85b..aba40a875 100644 --- a/Tests/Constraints/CssColorTest.php +++ b/Tests/Constraints/CssColorTest.php @@ -18,6 +18,7 @@ /** * @author Mathieu Santostefano + * * @requires PHP 8 */ final class CssColorTest extends TestCase diff --git a/Tests/Constraints/CurrencyValidatorTest.php b/Tests/Constraints/CurrencyValidatorTest.php index 6a0773ac6..c5d2ddb62 100644 --- a/Tests/Constraints/CurrencyValidatorTest.php +++ b/Tests/Constraints/CurrencyValidatorTest.php @@ -114,6 +114,7 @@ public function testInvalidCurrencies($currency) /** * @requires PHP 8 + * * @dataProvider getInvalidCurrencies */ public function testInvalidCurrenciesNamed($currency) diff --git a/Tests/Constraints/IsNullValidatorTest.php b/Tests/Constraints/IsNullValidatorTest.php index 875773eb6..ce8d89362 100644 --- a/Tests/Constraints/IsNullValidatorTest.php +++ b/Tests/Constraints/IsNullValidatorTest.php @@ -48,6 +48,7 @@ public function testInvalidValues($value, $valueAsString) /** * @requires PHP 8 + * * @dataProvider getInvalidValues */ public function testInvalidValuesNamed($value, $valueAsString) diff --git a/Tests/Constraints/LengthTest.php b/Tests/Constraints/LengthTest.php index 2d7d12576..2a30dca14 100644 --- a/Tests/Constraints/LengthTest.php +++ b/Tests/Constraints/LengthTest.php @@ -48,6 +48,7 @@ public function testInvalidNormalizerObjectThrowsException() /** * @group legacy + * * @dataProvider allowEmptyStringOptionData */ public function testDeprecatedAllowEmptyStringOption(bool $value) diff --git a/Tests/Constraints/LengthValidatorTest.php b/Tests/Constraints/LengthValidatorTest.php index babe2737e..f8ce33143 100644 --- a/Tests/Constraints/LengthValidatorTest.php +++ b/Tests/Constraints/LengthValidatorTest.php @@ -189,6 +189,7 @@ public function testInvalidValuesMin($value) /** * @requires PHP 8 + * * @dataProvider getThreeOrLessCharacters */ public function testInvalidValuesMinNamed($value) @@ -229,6 +230,7 @@ public function testInvalidValuesMax($value) /** * @requires PHP 8 + * * @dataProvider getFiveOrMoreCharacters */ public function testInvalidValuesMaxNamed($value) @@ -270,6 +272,7 @@ public function testInvalidValuesExactLessThanFour($value) /** * @requires PHP 8 + * * @dataProvider getThreeOrLessCharacters */ public function testInvalidValuesExactLessThanFourNamed($value) diff --git a/Tests/Constraints/RangeTest.php b/Tests/Constraints/RangeTest.php index 0982254b7..4dcd77ca9 100644 --- a/Tests/Constraints/RangeTest.php +++ b/Tests/Constraints/RangeTest.php @@ -85,6 +85,7 @@ public static function provideDeprecationTriggeredIfMinMaxAndMinMessageOrMaxMess /** * @group legacy + * * @dataProvider provideDeprecationTriggeredIfMinMaxAndMinMessageOrMaxMessageSet */ public function testDeprecationTriggeredIfMinMaxAndMinMessageOrMaxMessageSet(array $options, bool $expectedDeprecatedMinMessageSet, bool $expectedDeprecatedMaxMessageSet) @@ -107,6 +108,7 @@ public static function provideDeprecationNotTriggeredIfNotMinMaxOrNotMinMessageN /** * @doesNotPerformAssertions + * * @dataProvider provideDeprecationNotTriggeredIfNotMinMaxOrNotMinMessageNorMaxMessageSet */ public function testDeprecationNotTriggeredIfNotMinMaxOrNotMinMessageNorMaxMessageSet(array $options) diff --git a/Tests/Constraints/RegexValidatorTest.php b/Tests/Constraints/RegexValidatorTest.php index e46a53efa..7589b3d60 100644 --- a/Tests/Constraints/RegexValidatorTest.php +++ b/Tests/Constraints/RegexValidatorTest.php @@ -67,6 +67,7 @@ public function testValidValuesWithWhitespaces($value) /** * @requires PHP 8 + * * @dataProvider getValidValuesWithWhitespaces */ public function testValidValuesWithWhitespacesNamed($value) @@ -125,6 +126,7 @@ public function testInvalidValues($value) /** * @requires PHP 8 + * * @dataProvider getInvalidValues */ public function testInvalidValuesNamed($value) diff --git a/Tests/Constraints/UlidValidatorTest.php b/Tests/Constraints/UlidValidatorTest.php index c7b94fdde..626b6bbce 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() From 323a243890bd6bf37aa4b4c32d47d68c33b420f0 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 17 Feb 2023 14:21:16 +0100 Subject: [PATCH 09/18] improve deprecation message --- Constraints/Email.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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)) { From a0b226b9be88a5cdd76202362fd0cc642f045aec Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 21 Feb 2023 17:15:44 +0100 Subject: [PATCH 10/18] Fix merge --- Constraints/EmailValidator.php | 2 +- Tests/Constraints/EmailValidatorTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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/Tests/Constraints/EmailValidatorTest.php b/Tests/Constraints/EmailValidatorTest.php index cdf2bafc6..6bf8fec6c 100644 --- a/Tests/Constraints/EmailValidatorTest.php +++ b/Tests/Constraints/EmailValidatorTest.php @@ -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]); From 59d90667aec818417a6112553c7842b796bac7c3 Mon Sep 17 00:00:00 2001 From: Sergey Melesh Date: Mon, 16 Jan 2023 18:41:52 +0300 Subject: [PATCH 11/18] [Validator] Sync IBAN formats with Swift IBAN registry --- .gitattributes | 1 + Constraints/IbanValidator.php | 116 ++++++++------ Resources/bin/sync-iban-formats.php | 204 ++++++++++++++++++++++++ Tests/Constraints/IbanValidatorTest.php | 27 +++- 4 files changed, 295 insertions(+), 53 deletions(-) create mode 100755 Resources/bin/sync-iban-formats.php 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/Constraints/IbanValidator.php b/Constraints/IbanValidator.php index 215eb16f1..173cb6678 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 ]; /** 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/Tests/Constraints/IbanValidatorTest.php b/Tests/Constraints/IbanValidatorTest.php index 257f47b03..70994f509 100644 --- a/Tests/Constraints/IbanValidatorTest.php +++ b/Tests/Constraints/IbanValidatorTest.php @@ -116,6 +116,17 @@ public static 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 static 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 static 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 @@ -244,13 +255,13 @@ public static 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 @@ -357,8 +368,8 @@ public static 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 static 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 From 8db1049a9fd82f94a8e855cb2258f1338515c987 Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Tue, 21 Feb 2023 21:40:23 +0100 Subject: [PATCH 12/18] [Validator] Fix translation of AtLeastOneOf constraint message --- Constraints/AtLeastOneOfValidator.php | 6 ++- .../Constraints/AtLeastOneOfValidatorTest.php | 38 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/Constraints/AtLeastOneOfValidator.php b/Constraints/AtLeastOneOfValidator.php index 888f583eb..692b1176b 100644 --- a/Constraints/AtLeastOneOfValidator.php +++ b/Constraints/AtLeastOneOfValidator.php @@ -31,7 +31,11 @@ public function validate($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/Tests/Constraints/AtLeastOneOfValidatorTest.php b/Tests/Constraints/AtLeastOneOfValidatorTest.php index 3685a67b6..961607b4b 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 @@ -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 From ec684e007a4db8ea807834b118e40f5cc0c8b5c0 Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Mon, 6 Mar 2023 21:48:01 +0100 Subject: [PATCH 13/18] [Tests] Replace `setMethods()` by `onlyMethods()` and `addMethods()` --- Test/ConstraintValidatorTestCase.php | 8 ++------ Tests/Validator/RecursiveValidatorTest.php | 4 ++-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/Test/ConstraintValidatorTestCase.php b/Test/ConstraintValidatorTestCase.php index 073dd17f7..9cc6f0ab8 100644 --- a/Test/ConstraintValidatorTestCase.php +++ b/Test/ConstraintValidatorTestCase.php @@ -139,12 +139,8 @@ protected function createContext() 'validatePropertyValue', 'getViolations', ]; - // PHPUnit 10 removed MockBuilder::setMethods() - if (method_exists($contextualValidatorMockBuilder, 'onlyMethods')) { - $contextualValidatorMockBuilder->onlyMethods($contextualValidatorMethods); - } else { - $contextualValidatorMockBuilder->setMethods($contextualValidatorMethods); - } + + $contextualValidatorMockBuilder->onlyMethods($contextualValidatorMethods); $contextualValidator = $contextualValidatorMockBuilder->getMock(); $contextualValidator->expects($this->any()) ->method('atPath') diff --git a/Tests/Validator/RecursiveValidatorTest.php b/Tests/Validator/RecursiveValidatorTest.php index 2bb212eaa..926fba7e6 100644 --- a/Tests/Validator/RecursiveValidatorTest.php +++ b/Tests/Validator/RecursiveValidatorTest.php @@ -2091,7 +2091,7 @@ public function testEmptyGroupsArrayDoesNotTriggerDeprecation() $validator = $this ->getMockBuilder(RecursiveValidator::class) ->disableOriginalConstructor() - ->setMethods(['startContext']) + ->onlyMethods(['startContext']) ->getMock(); $validator ->expects($this->once()) @@ -2125,7 +2125,7 @@ public function testRelationBetweenChildAAndChildB() $validator = $this ->getMockBuilder(RecursiveValidator::class) ->disableOriginalConstructor() - ->setMethods(['startContext']) + ->onlyMethods(['startContext']) ->getMock(); $validator ->expects($this->once()) From b8e05031be2031de5a910e7cc21e7527c7e9538b Mon Sep 17 00:00:00 2001 From: Maximilian Beckers Date: Thu, 16 Mar 2023 08:57:07 +0100 Subject: [PATCH 14/18] [Validator] Update BIC validator IBAN mappings --- Constraints/BicValidator.php | 17 +++++++++++++---- Tests/Constraints/BicValidatorTest.php | 9 +++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Constraints/BicValidator.php b/Constraints/BicValidator.php index 37e922de7..6c038067b 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; @@ -104,7 +112,8 @@ public function validate($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) @@ -137,7 +146,7 @@ public function validate($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/Tests/Constraints/BicValidatorTest.php b/Tests/Constraints/BicValidatorTest.php index 564fa30c9..0acfb67a6 100644 --- a/Tests/Constraints/BicValidatorTest.php +++ b/Tests/Constraints/BicValidatorTest.php @@ -299,6 +299,8 @@ public static 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']; @@ -307,6 +309,13 @@ public static 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']; } } From 3da7428acbe64c85fc9e03585698f74dfd33f32d Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 17 Mar 2023 09:03:06 +0100 Subject: [PATCH 15/18] add translations for the filename max length validator option --- Resources/translations/validators.de.xlf | 4 ++++ Resources/translations/validators.en.xlf | 4 ++++ 2 files changed, 8 insertions(+) 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. + From 8700f0dc9d9089755f916c3c3db09b0be5d6db36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Thu, 13 Apr 2023 11:11:50 +0200 Subject: [PATCH 16/18] [Intl] Update the ICU data to 73.1 --- Tests/Constraints/TimezoneValidatorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Constraints/TimezoneValidatorTest.php b/Tests/Constraints/TimezoneValidatorTest.php index 3e0b23f04..f4e387607 100644 --- a/Tests/Constraints/TimezoneValidatorTest.php +++ b/Tests/Constraints/TimezoneValidatorTest.php @@ -73,7 +73,7 @@ public static function getValidTimezones(): iterable yield ['EST5EDT']; yield ['MST7MDT']; yield ['PST8PDT']; - yield ['America/Montreal']; + yield ['America/Toronto']; // previously expired in ICU yield ['Europe/Saratov']; From cf05adcbfc6af29be096c9a7da989e1c3ad3b76f Mon Sep 17 00:00:00 2001 From: Javier Alfonso Bellota de Frutos Date: Fri, 14 Apr 2023 13:26:38 +0200 Subject: [PATCH 17/18] [Validator] Fix support of Enum to `ConstraintValidator::formatValue` --- ConstraintValidator.php | 4 ++++ Tests/ConstraintValidatorTest.php | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/ConstraintValidator.php b/ConstraintValidator.php index 1473c6935..4a22dc112 100644 --- a/ConstraintValidator.php +++ b/ConstraintValidator.php @@ -99,6 +99,10 @@ protected function formatValue($value, int $format = 0) 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) && method_exists($value, '__toString')) { return $value->__toString(); diff --git a/Tests/ConstraintValidatorTest.php b/Tests/ConstraintValidatorTest.php index 128a41c06..c9dc517ec 100644 --- a/Tests/ConstraintValidatorTest.php +++ b/Tests/ConstraintValidatorTest.php @@ -41,6 +41,7 @@ public static function formatValueProvider() ['array', []], ['object', $toString = new TestToStringObject()], ['ccc', $toString, ConstraintValidator::OBJECT_TO_STRING], + ['FirstCase', $toString = TestEnum::FirstCase], ['object', $dateTime = new \DateTimeImmutable('1971-02-02T08:00:00UTC')], [class_exists(\IntlDateFormatter::class) ? 'Oct 4, 2019, 11:02 AM' : '2019-10-04 11:02:03', new \DateTimeImmutable('2019-10-04T11:02:03+09:00'), ConstraintValidator::PRETTY_DATE], [class_exists(\IntlDateFormatter::class) ? 'Feb 2, 1971, 8:00 AM' : '1971-02-02 08:00:00', $dateTime, ConstraintValidator::PRETTY_DATE], @@ -73,3 +74,9 @@ public function __toString() return 'ccc'; } } + +enum TestEnum +{ + case FirstCase; + case SecondCase; +} From ca71f5562a3876a153250f638124b6b95452985f Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 19 Apr 2023 09:52:21 +0200 Subject: [PATCH 18/18] Fix tests --- Tests/ConstraintValidatorTest.php | 12 +++++------- Tests/Fixtures/TestEnum.php | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 Tests/Fixtures/TestEnum.php diff --git a/Tests/ConstraintValidatorTest.php b/Tests/ConstraintValidatorTest.php index c9dc517ec..7fb4a91c6 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 { @@ -41,7 +42,6 @@ public static function formatValueProvider() ['array', []], ['object', $toString = new TestToStringObject()], ['ccc', $toString, ConstraintValidator::OBJECT_TO_STRING], - ['FirstCase', $toString = TestEnum::FirstCase], ['object', $dateTime = new \DateTimeImmutable('1971-02-02T08:00:00UTC')], [class_exists(\IntlDateFormatter::class) ? 'Oct 4, 2019, 11:02 AM' : '2019-10-04 11:02:03', new \DateTimeImmutable('2019-10-04T11:02:03+09:00'), ConstraintValidator::PRETTY_DATE], [class_exists(\IntlDateFormatter::class) ? 'Feb 2, 1971, 8:00 AM' : '1971-02-02 08:00:00', $dateTime, ConstraintValidator::PRETTY_DATE], @@ -49,6 +49,10 @@ public static 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; @@ -74,9 +78,3 @@ public function __toString() return 'ccc'; } } - -enum TestEnum -{ - case FirstCase; - case SecondCase; -} 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; +}