Skip to content

Commit

Permalink
Feature/south african licence codes (fzaninotto#1)
Browse files Browse the repository at this point in the history
* Added licenceCode method in the en_ZA person provider, that generates a valid South African licence code
  • Loading branch information
royalmitten authored Oct 5, 2017
1 parent 2a1e077 commit fda1963
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,9 @@ echo $faker->companyNumber; // 1999/789634/01

// Generates a random national identification number
echo $faker->idNumber; // 6606192211041

// Generates a random valid licence code
echo $faker->licenceCode; // EB
```

### `Faker\Provider\en_ZA\PhoneNumber`
Expand Down
19 changes: 15 additions & 4 deletions src/Faker/Provider/en_ZA/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,14 @@ class Person extends \Faker\Provider\Person
'Pule', 'Hlophe', 'Miya', 'Moagi',
);

protected static $licenceCodes = array('A', 'A1', 'B', 'C', 'C1', 'C2', 'EB', 'EC', 'EC1', 'I', 'L', 'L1');

/**
* @link https://en.wikipedia.org/wiki/National_identification_number#South_Africa
*
* @param int $minAge
* @param int $maxAge
* @param bool $citizen
* @param string $gender
* @param \DateTime $birthdate
* @param bool $citizen
* @param string $gender
*
* @return string
*/
Expand Down Expand Up @@ -161,4 +162,14 @@ public function idNumber(\DateTime $birthdate = null, $citizen = true, $gender =

return $partialIdNumber . Luhn::computeCheckDigit($partialIdNumber);
}

/**
* @see https://en.wikipedia.org/wiki/Driving_licence_in_South_Africa
*
* @return string
*/
public function licenceCode()
{
return static::randomElement(static::$licenceCodes);
}
}
7 changes: 7 additions & 0 deletions test/Faker/Provider/en_ZA/PersonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,11 @@ public function testIdNumberForFemales()

$this->assertContains($genderDigit, array('0', '1', '2', '3', '4'));
}

public function testLicenceCode()
{
$validLicenceCodes = array('A', 'A1', 'B', 'C', 'C1', 'C2', 'EB', 'EC', 'EC1', 'I', 'L', 'L1');

$this->assertContains($this->faker->licenceCode, $validLicenceCodes);
}
}

0 comments on commit fda1963

Please sign in to comment.