Skip to content

Commit

Permalink
Fix en_GB national insurance number test (#98)
Browse files Browse the repository at this point in the history
* Fixed en_GB national insurance number test

* Lowered chance of national insurance number generation looping again
  • Loading branch information
Bram Ceulemans authored Dec 1, 2020
1 parent b542e97 commit 4c996c8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
16 changes: 7 additions & 9 deletions src/Faker/Provider/en_GB/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion test/Faker/Provider/en_GB/PersonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}

0 comments on commit 4c996c8

Please sign in to comment.