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 #470 from ronanguilloux/ronan2
Browse files Browse the repository at this point in the history
+1 per-country VAT number, for at_AT
  • Loading branch information
fzaninotto committed Jan 4, 2015
2 parents 1d17554 + 3502860 commit 8bab235
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
9 changes: 9 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,15 @@ Fugiat non in itaque sunt nobis totam. Sed nesciunt est deleniti cumque alias. R

## Language specific formatters

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

echo $faker->vat; // "AT U12345678" - Austrian Value Added Tax number
echo $faker->vat(false); // "ATU12345678" - unspaced Austrian Value Added Tax number

```

### `Faker\Provider\cs_CZ\Address`
```php
<?php
Expand Down
1 change: 1 addition & 0 deletions src/Faker/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
* @property string $creditCardDetails
* @property string $bankAccountNumber
* @property string $swiftBicNumber
* @property string $vat
*
* @property string $word
* @method string words()
Expand Down
31 changes: 31 additions & 0 deletions src/Faker/Provider/at_AT/Payment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Faker\Provider\at_AT;

/**
* Class Payment
*
* @package Faker\Provider\at_AT
*/
class Payment extends \Faker\Provider\Payment
{
/**
* Value Added Tax (VAT)
*
* @example 'ATU12345678', ('spaced') 'AT U12345678'
*
* @see http://ec.europa.eu/taxation_customs/vies/faq.html?locale=en#item_11
* @see http://www.iecomputersystems.com/ordering/eu_vat_numbers.htm
* @see http://en.wikipedia.org/wiki/VAT_identification_number
*
* @param bool $spacedNationalPrefix
*
* @return string VAT Number
*/
public static function vat($spacedNationalPrefix = true)
{
$prefix = ($spacedNationalPrefix) ? "AT U" : "ATU";

return sprintf("%s%d", $prefix, self::randomNumber(8, true));
}
}
30 changes: 30 additions & 0 deletions test/Faker/Provider/at_AT/PaymentTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Faker\Test\Provider\at_AT;

use Faker\Generator;
use Faker\Provider\at_AT\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('/^(AT U\d{8})$/', $vat);
$this->assertRegExp('/^(ATU\d{8})$/', $unspacedVat);
}
}

0 comments on commit 8bab235

Please sign in to comment.