From 7ca4d5cc58cf8f5e484936465b8bdd10f3a44f8a Mon Sep 17 00:00:00 2001 From: Domingo Oropeza Date: Thu, 3 Mar 2016 00:32:00 -0400 Subject: [PATCH 1/4] Fixed person national id for foreigners and new function for companies' TIN (RIF in Venezuela) --- readme.md | 54 ++++++++++++++++++++++++++++ src/Faker/Provider/es_VE/Company.php | 9 +++++ src/Faker/Provider/es_VE/Person.php | 9 ++--- 3 files changed, 65 insertions(+), 7 deletions(-) diff --git a/readme.md b/readme.md index f4d9fcb00a..b5b44624fd 100644 --- a/readme.md +++ b/readme.md @@ -1051,6 +1051,60 @@ echo $faker->vat; // "BE 0123456789" - Belgian Value Added Tax number echo $faker->vat(false); // "BE0123456789" - unspaced Belgian Value Added Tax number ``` +### `Faker\Provider\es_VE\Person` + +```php +nationalId; // 'V-11223344' +``` + +### `Faker\Provider\es_VE\Company` + +```php +taxpayerIdentificationNumber; // 'J-123456789-1' +``` + +### `Faker\Provider\es_VE\Person` + +```php +nationalId; // 'V-11223344' +``` + +### `Faker\Provider\es_VE\Company` + +```php +taxpayerIdentificationNumber; // 'J-123456789-1' +``` + +### `Faker\Provider\es_VE\Person` + +```php +nationalId; // 'V-11223344' +``` + +### `Faker\Provider\es_VE\Company` + +```php +taxpayerIdentificationNumber; // 'J-123456789-1' +``` + ### `Faker\Provider\fr_FR\Address` ```php diff --git a/src/Faker/Provider/es_VE/Company.php b/src/Faker/Provider/es_VE/Company.php index 7793842df6..946454f891 100644 --- a/src/Faker/Provider/es_VE/Company.php +++ b/src/Faker/Provider/es_VE/Company.php @@ -27,4 +27,13 @@ public static function companyPrefix() { return static::randomElement(static::$companyPrefix); } + + /** + * Generate random Taxpayer Identification Number (RIF in Venezuela). Ex J-123456789-1 + * @return string + */ + public function taxpayerIdentificationNumber() + { + return static::randomElement(array('J', 'G', 'V', 'E', 'P', 'C')) . '-' . static::numerify('#########') . '-' . static::numerify('#'); + } } diff --git a/src/Faker/Provider/es_VE/Person.php b/src/Faker/Provider/es_VE/Person.php index b1da57c16d..e67a1c836a 100644 --- a/src/Faker/Provider/es_VE/Person.php +++ b/src/Faker/Provider/es_VE/Person.php @@ -149,18 +149,13 @@ public static function suffix() } /** - * Generate random national identification number including nationalized foreigns. Ex V-8756432 or E-82803827 + * Generate random national identification number (cédula de identidad). Ex V-8756432 * @return string * CNE is the official national election registry org. * @link http://www.cne.gob.ve/web/registro_electoral/ciudadanos_111_129_2011.php */ public function nationalId() { - $id = static::randomElement(static::$nationalityId); - if ($id == 'V') { - return $id.$this->numberBetween(10000, 100000000); - } else { - return $id.$this->numberBetween(80000000, 100000000); - } + return static::randomElement(array('V','E')).'-'.static::numberBetween(10000, 100000000); } } From a49797fed86428a4865877a58a7ae0d3a42e4eb0 Mon Sep 17 00:00:00 2001 From: Domingo Oropeza Date: Thu, 31 Aug 2017 23:33:27 -0400 Subject: [PATCH 2/4] Added a separator for national ID because some times is optional to have this. --- src/Faker/Provider/es_VE/Company.php | 5 +++-- src/Faker/Provider/es_VE/Person.php | 12 +++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Faker/Provider/es_VE/Company.php b/src/Faker/Provider/es_VE/Company.php index 946454f891..acf0bc8aee 100644 --- a/src/Faker/Provider/es_VE/Company.php +++ b/src/Faker/Provider/es_VE/Company.php @@ -30,10 +30,11 @@ public static function companyPrefix() /** * Generate random Taxpayer Identification Number (RIF in Venezuela). Ex J-123456789-1 + * @param string $separator * @return string */ - public function taxpayerIdentificationNumber() + public function taxpayerIdentificationNumber($separator = '') { - return static::randomElement(array('J', 'G', 'V', 'E', 'P', 'C')) . '-' . static::numerify('#########') . '-' . static::numerify('#'); + return static::randomElement(array('J', 'G', 'V', 'E', 'P', 'C')) . $separator . static::numerify('#########') . $separator . static::numerify('#'); } } diff --git a/src/Faker/Provider/es_VE/Person.php b/src/Faker/Provider/es_VE/Person.php index e67a1c836a..8c9395210e 100644 --- a/src/Faker/Provider/es_VE/Person.php +++ b/src/Faker/Provider/es_VE/Person.php @@ -150,12 +150,18 @@ public static function suffix() /** * Generate random national identification number (cédula de identidad). Ex V-8756432 - * @return string + * @param string $separator + * @return string CNE is the official national election registry org. * CNE is the official national election registry org. * @link http://www.cne.gob.ve/web/registro_electoral/ciudadanos_111_129_2011.php */ - public function nationalId() + public function nationalId($separator = '') { - return static::randomElement(array('V','E')).'-'.static::numberBetween(10000, 100000000); + $id = static::randomElement(static::$nationalityId); + if ($id == 'V') { + return $id . $separator . $this->numberBetween(10000, 100000000); + } else { + return $id . $separator . $this->numberBetween(80000000, 100000000); + } } } From 9d98d8d4d9e7162efc701e21c19caa1ffdaf6a8c Mon Sep 17 00:00:00 2001 From: Domingo Oropeza Date: Fri, 1 Sep 2017 00:19:31 -0400 Subject: [PATCH 3/4] fixed documentation for README --- readme.md | 44 ++++---------------------------------------- 1 file changed, 4 insertions(+), 40 deletions(-) diff --git a/readme.md b/readme.md index b5b44624fd..ec0a0a28a4 100644 --- a/readme.md +++ b/readme.md @@ -1056,8 +1056,8 @@ echo $faker->vat(false); // "BE0123456789" - unspaced Belgian Value Added Tax ```php nationalId; // 'V-11223344' +// Generate a Cédula de identidad number, you can pass one argument to add separator +echo $faker->nationalId; // 'V11223344' ``` ### `Faker\Provider\es_VE\Company` @@ -1065,44 +1065,8 @@ echo $faker->nationalId; // 'V-11223344' ```php taxpayerIdentificationNumber; // 'J-123456789-1' -``` - -### `Faker\Provider\es_VE\Person` - -```php -nationalId; // 'V-11223344' -``` - -### `Faker\Provider\es_VE\Company` - -```php -taxpayerIdentificationNumber; // 'J-123456789-1' -``` - -### `Faker\Provider\es_VE\Person` - -```php -nationalId; // 'V-11223344' -``` - -### `Faker\Provider\es_VE\Company` - -```php -taxpayerIdentificationNumber; // 'J-123456789-1' +// Generates a R.I.F. number, you can pass one argument to add separators +echo $faker->taxpayerIdentificationNumber; // 'J1234567891' ``` ### `Faker\Provider\fr_FR\Address` From 39f9195e3fc6b2e1bb05b4dbd793e13bbb9b3599 Mon Sep 17 00:00:00 2001 From: Domingo Oropeza Date: Sat, 2 Sep 2017 13:13:43 -0400 Subject: [PATCH 4/4] tests added for es_VE provider and fixed es_VE/Company for assert the test. --- src/Faker/Provider/es_VE/Company.php | 2 +- test/Faker/Provider/es_VE/CompanyTest.php | 43 +++++++++++++++++++++++ test/Faker/Provider/es_VE/PersonTest.php | 43 +++++++++++++++++++++++ 3 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 test/Faker/Provider/es_VE/CompanyTest.php create mode 100644 test/Faker/Provider/es_VE/PersonTest.php diff --git a/src/Faker/Provider/es_VE/Company.php b/src/Faker/Provider/es_VE/Company.php index acf0bc8aee..e2e5738375 100644 --- a/src/Faker/Provider/es_VE/Company.php +++ b/src/Faker/Provider/es_VE/Company.php @@ -35,6 +35,6 @@ public static function companyPrefix() */ public function taxpayerIdentificationNumber($separator = '') { - return static::randomElement(array('J', 'G', 'V', 'E', 'P', 'C')) . $separator . static::numerify('#########') . $separator . static::numerify('#'); + return static::randomElement(array('J', 'G', 'V', 'E', 'P', 'C')) . $separator . static::numerify('########') . $separator . static::numerify('#'); } } diff --git a/test/Faker/Provider/es_VE/CompanyTest.php b/test/Faker/Provider/es_VE/CompanyTest.php new file mode 100644 index 0000000000..2ee22fd1d8 --- /dev/null +++ b/test/Faker/Provider/es_VE/CompanyTest.php @@ -0,0 +1,43 @@ + for Faker + * Date: 01/09/2017 + * Time: 09:45 PM + */ + +namespace Faker\Test\Provider\es_VE; + + +use Faker\Generator; +use Faker\Provider\es_VE\Company; + +class CompanyTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var Generator + */ + private $faker; + + public function setUp() + { + $faker = new Generator(); + $faker->seed(1); + $faker->addProvider(new Company($faker)); + $this->faker = $faker; + } + + /** + * national Id format validator + */ + public function testNationalId() + { + $pattern = '/^[VJGECP]-?\d{8}-?\d$/'; + $rif = $this->faker->taxpayerIdentificationNumber; + $this->assertRegExp($pattern, $rif); + + $rif = $this->faker->taxpayerIdentificationNumber('-'); + $this->assertRegExp($pattern, $rif); + } + + +} diff --git a/test/Faker/Provider/es_VE/PersonTest.php b/test/Faker/Provider/es_VE/PersonTest.php new file mode 100644 index 0000000000..b74b9bd34e --- /dev/null +++ b/test/Faker/Provider/es_VE/PersonTest.php @@ -0,0 +1,43 @@ +seed(1); + $faker->addProvider(new Person($faker)); + $this->faker = $faker; + } + + /** + * national Id format validator + */ + public function testNationalId() + { + $pattern = '/(?:^V-?\d{5,9}$)|(?:^E-?\d{8,9}$)/'; + + $cedula = $this->faker->nationalId; + $this->assertRegExp($pattern, $cedula); + + $cedula = $this->faker->nationalId('-'); + $this->assertRegExp($pattern, $cedula); + } +}