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 #512 from ronanguilloux/vat_bg
Browse files Browse the repository at this point in the history
+1 per-country VAT number, for bg_BG
  • Loading branch information
fzaninotto committed Jan 26, 2015
2 parents b1167d9 + 36d8294 commit 9b9ec8d
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
9 changes: 9 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,15 @@ echo $faker->vat(false); // "BE0123456789" - unspaced Belgian Value Added Tax

```

### `Faker\Provider\bg_BG\Payment`
```php
<?php

echo $faker->vat; // "BG 0123456789" - Bulgarian Value Added Tax number
echo $faker->vat(false); // "BG0123456789" - unspaced Bulgarian Value Added Tax number

```

### `Faker\Provider\cs_CZ\Address`
```php
<?php
Expand Down
24 changes: 24 additions & 0 deletions src/Faker/Provider/bg_BG/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,28 @@ public static function bankAccountNumber($prefix = '', $countryCode = 'BG', $len
{
return static::iban($countryCode, $prefix, $length);
}

/**
* Value Added Tax (VAT)
*
* @example 'BG1234567890', ('spaced') 'BG 1234567890'
*
* @see http://ec.europa.eu/taxation_customs/vies/faq.html?locale=en#item_11
* @see http://en.wikipedia.org/wiki/VAT_identification_number
*
* @param bool $spacedNationalPrefix
*
* @return string VAT Number
*/
public static function vat($spacedNationalPrefix = true)
{
$prefix = ($spacedNationalPrefix) ? "BG " : "BG";

return sprintf(
"%s%d%d",
$prefix,
self::randomNumber(5, true), // workaround for mt_getrandmax() limitation
self::randomNumber(self::randomElement(array(4, 5)), true)
);
}
}
30 changes: 30 additions & 0 deletions test/Faker/Provider/bg_BG/PaymentTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Faker\Test\Provider\bg_BG;

use Faker\Generator;
use Faker\Provider\bg_BG\Payment;

class PaymentTest extends \PHPUnit_Framework_TestCase
{

/**
* @var Generator
*/
private $faker;

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

public function testVatIsValid()
{
$vat = $this->faker->vat();
$unspacedVat = $this->faker->vat(false);
$this->assertRegExp('/^(BG \d{9,10})$/', $vat);
$this->assertRegExp('/^(BG\d{9,10})$/', $unspacedVat);
}
}

0 comments on commit 9b9ec8d

Please sign in to comment.