diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f99eb8427..3d8c3aa57c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Removed domain `gmail.com.au` from `Provider\en_AU\Internet` (#886) - Refreshed ISO currencies (#919) - Improved italian phone number formats +- Fixed BIC generation for `Provider\Payment` ## [2024-11-09, v1.24.0](https://github.com/FakerPHP/Faker/compare/v1.23.1..v1.24.0) diff --git a/src/Faker/Provider/Payment.php b/src/Faker/Provider/Payment.php index 707ef059b8..b1ca734913 100644 --- a/src/Faker/Provider/Payment.php +++ b/src/Faker/Provider/Payment.php @@ -302,11 +302,12 @@ public static function iban($countryCode = null, $prefix = '', $length = null) * @example 'RZTIAT22263' * * @see http://en.wikipedia.org/wiki/ISO_9362 + * @see http://www.iso20022.org * * @return string Swift/Bic number */ - public static function swiftBicNumber() + public static function swiftBicNumber(): string { - return self::regexify('^([A-Z]){4}([A-Z]){2}([0-9A-Z]){2}([0-9A-Z]{3})?$'); + return self::regexify('^([A-Z]{6,6}[A-Z2-9][A-NP-Z0-9][A-Z0-9]{3,3}){0,1}$'); } } diff --git a/test/Faker/Provider/PaymentTest.php b/test/Faker/Provider/PaymentTest.php index 1e90da0d9e..5d51eebd1d 100644 --- a/test/Faker/Provider/PaymentTest.php +++ b/test/Faker/Provider/PaymentTest.php @@ -187,6 +187,14 @@ public function testIban($countryCode, $regex): void self::assertTrue(Iban::isValid($iban), "Checksum for $iban is invalid"); } + public function testSwitchBicNumber(): void + { + $bic = $this->faker->swiftBicNumber(); + + // Test format + self::assertMatchesRegularExpression('~^[A-Z]{6,6}[A-Z2-9][A-NP-Z0-9]([A-Z0-9]{3,3}){0,1}$~', $bic, "Bic for $bic is invalid"); + } + protected function getProviders(): iterable { yield new BaseProvider($this->faker);