From 4c996c84da184c952de8ebbc8483ba99b98a73ee Mon Sep 17 00:00:00 2001 From: Bram Ceulemans Date: Tue, 1 Dec 2020 23:57:55 +0100 Subject: [PATCH] Fix en_GB national insurance number test (#98) * Fixed en_GB national insurance number test * Lowered chance of national insurance number generation looping again --- src/Faker/Provider/en_GB/Person.php | 16 +++++++--------- test/Faker/Provider/en_GB/PersonTest.php | 2 +- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/Faker/Provider/en_GB/Person.php b/src/Faker/Provider/en_GB/Person.php index 9dbe290db0..38c156671b 100644 --- a/src/Faker/Provider/en_GB/Person.php +++ b/src/Faker/Provider/en_GB/Person.php @@ -97,18 +97,16 @@ class Person extends \Faker\Provider\Person */ public function nino(): string { + $prefixAllowList = ['A', 'B', 'C', 'E', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'R', 'S', 'T', 'W', 'X', 'Y', 'Z']; + $prefixBanList = ['BG', 'GB', 'KN', 'NK', 'NT', 'TN', 'ZZ']; + do { - $prefixLetters = strtoupper(static::lexify('??')); - } while ( - in_array($prefixLetters[0], ['D', 'F', 'I', 'Q', 'U', 'V']) - || in_array($prefixLetters[1], ['D', 'F', 'I', 'Q', 'U', 'V']) - || in_array($prefixLetters, ['BG', 'GB', 'NK', 'KN', 'TN', 'NT', 'ZZ']) - || $prefixLetters[1] == 'O'); + $prefix = implode('', self::randomElements($prefixAllowList, 2, true)); + } while (in_array($prefix, $prefixBanList) || $prefix[1] == 'O'); $digits = static::numerify('######'); + $suffix = static::randomElement(['A', 'B', 'C', 'D']); - $suffixLetter = static::randomElement(['A', 'B', 'C', 'D']); - - return sprintf('%s%s%s', $prefixLetters, $digits, $suffixLetter); + return sprintf('%s%s%s', $prefix, $digits, $suffix); } } diff --git a/test/Faker/Provider/en_GB/PersonTest.php b/test/Faker/Provider/en_GB/PersonTest.php index 77573b8fa1..7ab285d1c6 100644 --- a/test/Faker/Provider/en_GB/PersonTest.php +++ b/test/Faker/Provider/en_GB/PersonTest.php @@ -29,6 +29,6 @@ public function testNationalInsuranceNumber() $this->assertFalse(in_array($result[0], ['D', 'F', 'I', 'Q', 'U', 'V'])); $this->assertFalse(in_array($result[1], ['D', 'F', 'I', 'Q', 'U', 'V'])); $this->assertFalse(in_array($result, ['BG', 'GB', 'NK', 'KN', 'TN', 'NT', 'ZZ'])); - $this->assertFalse($result[0] === 'O'); + $this->assertFalse($result[1] === 'O'); } }