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

Add more PhoneNumber options for es_ES #1219

Merged
merged 1 commit into from
Aug 27, 2019
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
12 changes: 12 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,18 @@ echo $faker->dni; // '77446565E'
echo $faker->vat; // "A35864370"
```

### `Faker\Provider\es_ES\PhoneNumber`

```php
<?php

// Generates a special rate toll free phone number
echo $faker->tollFreeNumber; // 900 123 456

// Generates a mobile phone number
echo $faker->mobileNumber; // +34 612 12 24
```

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

```php
Expand Down
18 changes: 18 additions & 0 deletions src/Faker/Provider/es_ES/PhoneNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class PhoneNumber extends \Faker\Provider\PhoneNumber
'9########',
'9##-##-####',
'9##-######',
);

protected static $mobileFormats = array(
'+34 6## ## ####',
'+34 6## ######',
'+34 6########',
Expand All @@ -26,4 +29,19 @@ class PhoneNumber extends \Faker\Provider\PhoneNumber
'6##-##-####',
'6##-######',
);

protected static $tollFreeFormats = array(
'900 ### ###',
'800 ### ###',
);

public static function mobileNumber()
{
return static::numerify(static::randomElement(static::$mobileFormats));
}

public static function tollFreeNumber()
{
return static::numerify(static::randomElement(static::$tollFreeFormats));
}
}
26 changes: 26 additions & 0 deletions test/Faker/Provider/es_ES/PhoneNumberTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Faker\Test\Provider\es_ES;

use Faker\Generator;
use Faker\Provider\es_ES\PhoneNumber;

class PhoneNumberTest extends \PHPUnit_Framework_TestCase
{
public function setUp()
{
$faker = new Generator();
$faker->addProvider(new PhoneNumber($faker));
$this->faker = $faker;
}

public function testMobileNumber()
{
$this->assertNotEquals('', $this->faker->mobileNumber());
}

public function testTollFreeNumber()
{
$this->assertEquals(11, strlen($this->faker->tollFreeNumber()));
}
}