Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

South African licence codes #1315

Merged
merged 1 commit into from
Oct 9, 2017
Merged
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
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);
}
}