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

Commit

Permalink
Merge pull request #1158 from jgwong/peruvian-dni
Browse files Browse the repository at this point in the history
Add Peruvian DNI generator
  • Loading branch information
fzaninotto authored Mar 13, 2017
2 parents 470cf6f + c853bea commit ee69d90
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
9 changes: 9 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,15 @@ echo $faker->dni; // '77446565E'
echo $faker->vat; // "A35864370"
```

### `Faker\Provider\es_PE\Person`

```php
<?php

// Generates a Peruvian Documento Nacional de Identidad (DNI) number
echo $faker->dni; // '83367512'
```

### `Faker\Provider\fi_FI\Payment`

```php
Expand Down
16 changes: 16 additions & 0 deletions src/Faker/Provider/es_PE/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,20 @@ public static function suffix()
{
return static::randomElement(static::$suffix);
}


/**
* Generate a Documento Nacional de Identidad (DNI) number
*
* Doesn't include a checksum, as peruvians commonly use only the first
* 8 digits.
*
* @example '83367512'
*
* @link http://www2.sunat.gob.pe/pdt/pdtModulos/independientes/p695/TipoDoc.htm
*/
public static function dni()
{
return static::numerify('########');
}
}
28 changes: 28 additions & 0 deletions test/Faker/Provider/es_PE/PersonTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Faker\Test\Provider\es_PE;

use Faker\Generator;
use Faker\Provider\es_PE\Person;

class PersonTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Generator
*/
private $faker;

public function setUp()
{
$faker = new Generator();
$faker->seed(1);
$faker->addProvider(new Person($faker));
$this->faker = $faker;
}

public function testDNI()
{
$dni = $this->faker->dni;
$this->assertRegExp('/\A[0-9]{8}\Z/', $dni);
}
}

0 comments on commit ee69d90

Please sign in to comment.