Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add zh_TW cell phone and county / dist #884

Open
wants to merge 5 commits into
base: 2.0
Choose a base branch
from
Open
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
27 changes: 25 additions & 2 deletions src/Provider/zh_TW/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,33 @@ public static function localLongitude()
return static::randomFloat(6, 120, 122);
}

public function county()
{
return static::randomElement(array_keys(static::$city));
}

public function distOf(string $county)
{
$dist = static::$city[$county] ?? [];

if ($dist === []) {
return null;
}

return static::randomElement($dist);
}

public function dist()
{
$county = $this->county();

return $this->distOf($county);
}

public function city()
{
$county = static::randomElement(array_keys(static::$city));
$city = static::randomElement(static::$city[$county]);
$county = $this->county();
$city = $this->distOf($county);

return $county . $city;
}
Expand Down
43 changes: 43 additions & 0 deletions src/Provider/zh_TW/PhoneNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,47 @@ class PhoneNumber extends \Faker\Provider\PhoneNumber
'(0##)######',
'(0##)###-###',
];

public function cellPhoneNumber(bool $addDashes = false)
{
if ($addDashes) {
return self::numerify('09##-###-###');
}

return self::numerify('09########');
}

public function intlCellPhoneNumber(bool $addDashes = false)
{
if ($addDashes) {
return self::numerify('+886-9##-###-###');
}

return self::numerify('+8869########');
}

public function localPhoneNumber(bool $addDashes = false)
{
if ($addDashes) {
return self::numerify(
self::randomElement(
[
'(02)####-####',
'(0#)###-####',
'(0##)###-###',
],
),
);
}

return self::numerify(
self::randomElement(
[
'(02)########',
'(0#)#######',
'(0##)######',
],
),
);
}
}
58 changes: 58 additions & 0 deletions test/Provider/zh_TW/AddressTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace Faker\Provider\zh_TW;

use Faker\Test\TestCase;

/**
* @group legacy
*/
final class AddressTest extends TestCase
{
public function testCounty(): void
{
$classRef = new \ReflectionClass(Address::class);
$property = $classRef->getProperty('city');
$city = array_keys($property->getValue());

$county = $this->faker->county();

self::assertTrue(in_array($county, $city, true));
}

public function testDistOf(): void
{
$classRef = new \ReflectionClass(Address::class);
$property = $classRef->getProperty('city');
$city = $property->getValue();

$county = $this->faker->county();
$dist = $this->faker->distOf($county);

self::assertTrue(in_array($dist, $city[$county], true));
}

public function testDist(): void
{
$classRef = new \ReflectionClass(Address::class);
$property = $classRef->getProperty('city');
$city = $property->getValue();

$distSet = [];

foreach ($city as $distList) {
foreach ($distList as $distItem) {
$distSet[] = $distItem;
}
}

$dist = $this->faker->dist();

self::assertTrue(in_array($dist, $distSet, true));
}

protected function getProviders(): iterable
{
yield new Address($this->faker);
}
}
49 changes: 49 additions & 0 deletions test/Provider/zh_TW/PhoneNumberTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Faker\Provider\zh_TW;

use Faker\Test\TestCase;

/**
* @group legacy
*/
final class PhoneNumberTest extends TestCase
{
public function testCellPhoneNumber()
{
$no = $this->faker->cellPhoneNumber();

self::assertMatchesRegularExpression('/^09\d{8}$/', $no);

$no = $this->faker->cellPhoneNumber(true);

self::assertMatchesRegularExpression('/^09\d{2}-?\d{3}-?\d{3}$/', $no);
}

public function testIntlCellPhoneNumber()
{
$no = $this->faker->intlCellPhoneNumber();

self::assertMatchesRegularExpression('/^\+8869\d{8}$/', $no);

$no = $this->faker->intlCellPhoneNumber(true);

self::assertMatchesRegularExpression('/^\+886-9\d{2}-?\d{3}-?\d{3}$/', $no);
}

public function testLocalPhoneNumber()
{
$no = $this->faker->localPhoneNumber();

self::assertMatchesRegularExpression('/^\(\d{2,3}\)\d{7,8}$/', $no);

$no = $this->faker->localPhoneNumber(true);

self::assertMatchesRegularExpression('/^\(\d{2,3}\)\d{3,4}-?\d{3,4}$/', $no);
}

protected function getProviders(): iterable
{
yield new PhoneNumber($this->faker);
}
}