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

+1 per-country VAT number, for at_AT #470

Merged
merged 2 commits into from
Jan 4, 2015
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
9 changes: 9 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,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);
}
}