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

Add licenceCode method in the to es_ES person provider #1392

Merged
merged 2 commits into from
Dec 30, 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 @@ -995,6 +995,9 @@ echo $faker->mobileNumber; // 082 123 5555

// Generates a Documento Nacional de Identidad (DNI) number
echo $faker->dni; // '77446565E'

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

### `Faker\Provider\es_ES\Payment`
Expand Down
12 changes: 12 additions & 0 deletions src/Faker/Provider/es_ES/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class Person extends \Faker\Provider\Person

private static $suffix = array('Hijo', 'Segundo', 'Tercero');

protected static $licenceCodes = array('AM', 'A1', 'A2', 'A','B', 'B+E', 'C1', 'C1+E', 'C', 'C+E', 'D1', 'D1+E', 'D', 'D+E');

/**
* @example 'Hijo'
*/
Expand All @@ -85,4 +87,14 @@ public static function dni()

return $number . $letter;
}

/**
* @see https://sede.dgt.gob.es/es/tramites-y-multas/permiso-de-conduccion/obtencion-permiso-licencia-conduccion/clases-permiso-conduccion-edad.shtml
*
* @return string
*/
public function licenceCode()
{
return static::randomElement(static::$licenceCodes);
}
}
7 changes: 7 additions & 0 deletions test/Faker/Provider/es_ES/PersonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,11 @@ public function isValidDNI($string)

return strtoupper($letter) === $map[((int) $number) % 23];
}

public function testLicenceCode()
{
$validLicenceCodes = array('AM', 'A1', 'A2', 'A','B', 'B+E', 'C1', 'C1+E', 'C', 'C+E', 'D1', 'D1+E', 'D', 'D+E');

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