Skip to content

Fix standard en_GB VAT numbers being generated with an incorrect digit length #970

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 1.24
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 en_GB standard VAT numbers having an incorrect length if the check digit has a leading zero

## [2024-11-09, v1.24.0](https://github.com/FakerPHP/Faker/compare/v1.23.1..v1.24.0)

Expand Down
6 changes: 3 additions & 3 deletions src/Faker/Provider/en_GB/Company.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private static function generateStandardVatNumber(): string
$secondBlock = static::randomNumber(4, true);

return sprintf(
'%s%d %d %d',
'%s%s %s %s',
static::VAT_PREFIX,
$firstBlock,
$secondBlock,
Expand All @@ -64,7 +64,7 @@ private static function generateStandardVatNumber(): string
private static function generateHealthAuthorityVatNumber(): string
{
return sprintf(
'%sHA%d',
'%sHA%s',
static::VAT_PREFIX,
static::numberBetween(500, 999),
);
Expand All @@ -77,7 +77,7 @@ private static function generateHealthAuthorityVatNumber(): string
private static function generateBranchTraderVatNumber(): string
{
return sprintf(
'%s %d',
'%s %s',
static::generateStandardVatNumber(),
static::randomNumber(3, true),
);
Expand Down
9 changes: 9 additions & 0 deletions test/Faker/Provider/en_GB/CompanyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ public function testVatHealthAuthorityType(): void
self::assertTrue($matches[1] < 1000);
}

public function testLeadingZeroInModulus97BlockRemainsAfterFormatting(): void
{
// Force Faker to generate VAT number GB216 5727 07
$this->faker->seed(297957);
$number = $this->faker->vat();
$this->assertDefaultVatFormat($number);
self::assertStringEndsWith('07', substr($number, -2));
}

protected function getProviders(): iterable
{
yield new Company($this->faker);
Expand Down