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

Improve address provider for en_NG locale #807

Closed
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
107 changes: 82 additions & 25 deletions src/Provider/en_NG/Address.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
<?php

Check failure on line 1 in src/Provider/en_NG/Address.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4)

Ignored error pattern #^Unsafe access to private property Faker\\Provider\\en_NG\\Address\:\:\$county through static\:\:\.$# in path /home/runner/work/Faker/Faker/src/Provider/en_NG/Address.php was not matched in reported errors.

Check failure on line 1 in src/Provider/en_NG/Address.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4)

Ignored error pattern #^Unsafe access to private property Faker\\Provider\\en_NG\\Address\:\:\$regions through static\:\:\.$# in path /home/runner/work/Faker/Faker/src/Provider/en_NG/Address.php was not matched in reported errors.

namespace Faker\Provider\en_NG;

class Address extends \Faker\Provider\Address
{
protected static $postcode = ['#####', '## ###'];
protected static $citySuffix = [];

private static $county = [
'Abuja', 'Abia', 'Adamawa', 'Akwa Ibom', 'Anambra',
protected static $streetPrefix = ['Chief', 'Dr.', 'Alhaji', 'General', 'Bishop', 'Rev.'];

protected static $streetSuffix = ['Street', 'Avenue', 'Close', 'Boulevard', 'Way'];

protected static $postcode = ['######'];

protected static $cityFormats = [
'{{cityName}}',
];

protected static $streetNameFormats = [
'{{lastName}} {{streetSuffix}}',
'{{streetPrefix}} {{lastName}} {{streetSuffix}}',
];

protected static $state = [
'Abia', 'Adamawa', 'Akwa Ibom', 'Anambra',
'Bauchi', 'Bayelsa', 'Benue', 'Borno',
'Cross River',
'Delta',
'Ebonyi', 'Edo', 'Ekiti', 'Enugu', 'Gombe',
'Federal Capital Territory',
'Imo', 'Jigawa',
'Kaduna', 'Kano', 'Katsina', 'Kebbi', 'Kogi', 'Kwara',
'Lagos',
Expand Down Expand Up @@ -53,46 +69,87 @@
'Zambia', 'Zimbabwe',
];

private static $regions = [
'Abakaliki', 'Abeokuta', 'Akure', 'Asaba', 'Awka',
'Bauchi',
'Calabar', 'City',
'Damaturu', 'Dutse',
'Ekiti', 'Enugu',
'Gombe', 'Gusau',
'Ibadan', 'Ikeja', 'Ilorin',
'Jalingo', 'Jos',
'Kaduna', 'Kano', 'Katsina', 'Kebbi',
'Lafia', 'Lokoja',
'Maiduguri', 'Makurdi', 'Minna',
'Oshogbo', 'Owerri',
'Port-Harcourt',
'Sokoto',
'Umuahia', 'Uyo',
protected static $cityName = [
'Aba', 'Abakaliki', 'Abeokuta', 'Abuja', 'Ado Ekiti', 'Akure', 'Arochukwu', 'Asaba', 'Awka', 'Azare',
'Badagry', 'Bama', 'Bauchi', 'Benin', 'Bida', 'Birnin Kebbi', 'Biu', 'Bonny Island', 'Brass', 'Bukuru', 'Buguma', 'Burutu', 'Bwari',
'Calabar',
'Damaturu', 'Deba Habe', 'Degema', 'Dikwa', 'Dutse',
'Effom-Alaiye', 'Ekiti', 'Eleme', 'Enugu', 'Epe',
'Garki', 'Gashua', 'Gboko', 'Gombe', 'Gusau', 'Gwagwalada',
'Ibadan', 'Idah', 'Ijebu-Ode', 'Ikare', 'Ikeja', 'Ikorodu', 'Ikot Abasi', 'Ikot Ekpene', 'Ilaro', 'Ile-Ife', 'Ilesa', 'Ilorin',
'Jalingo', "Jama'are", 'Jebba', 'Jimeta', 'Jos',
'Kabba', 'Kaduna', 'Kano', 'Katagum', 'Katsina', 'Kaura Namoda', 'Kebbi', 'Keffi', 'Koko', 'Kontagora', 'Kukawa', 'Kuje', 'Kwali',
'Lafia', 'Lapai', 'Lekki', 'Lokoja',
'Maiduguri', 'Makurdi', 'Mubi', 'Minna', 'Misau', 'Mushin',
'Nsukka', 'Numan',
'Obafemi-Owode', 'Oka-Akoko', 'Okene', 'Okrika', 'Okpoko', 'Ogbomosho', 'Ogoja', 'Ondo', 'Onitsha', 'Oron', 'Oshogbo', 'Otukpo', 'Owerri', 'Owo',
'Port-Harcourt', 'Pategi',
'Sagamu', 'Sapele', 'Sokoto', 'Suleja',
'Ugep', 'Ughelli', 'Umuahia', 'Uromi', 'Uyo',
'Victoria Island', 'Vom',
'Warri', 'Wase',
'Yenagoa', 'Yola',
'Zaria',
];

protected static $region = [
'North-Central', 'North-East', 'North-West',
'South-East', 'South-South', 'South-West',
];

/**
* Randomly returns a Nigerian state or county.
* @example 'Chief'
*
* @example 'Lagos'
* @return string
*/
public static function streetPrefix()
{
return static::randomElement(static::$streetPrefix);
}

/**
* Randomly returns a Nigerian city.
*
* @example 'Ikeja'
*
* @return string
*/
public static function cityName()
{
return static::randomElement(static::$cityName);
}

/**
* Alias for <code>self::state()</code>
*
* @return string
*/
public static function county()
{
return static::randomElement(static::$county);
return self::state();
}

/**
* Randomly returns a Nigerian region of a state.
* Randomly returns a Nigerian state.
*
* @example 'Ikeja'
* @example 'Lagos'
*
* @return string
*/
public static function state()
{
return static::randomElement(static::$state);
}

/**
* Randomly returns a Nigerian region.
*
* @example 'South-South'
*
* @return string
*/
public static function region()
{
return static::randomElement(static::$regions);
return static::randomElement(static::$region);
}
}
35 changes: 28 additions & 7 deletions test/Provider/en_NG/AddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

declare(strict_types=1);

namespace Faker\Provider\en_NG;
namespace Faker\Test\Provider\en_NG;

use Faker\Provider\en_NG\Address;
use Faker\Provider\en_NG\Person;
use Faker\Test\TestCase;

/**
Expand All @@ -17,25 +19,42 @@ public function testPostcodeIsNotEmptyAndIsValid(): void

self::assertNotEmpty($postcode);
self::assertIsString($postcode);
self::assertEquals(6, strlen($postcode));
}

public function testStreetNameIsAValidString(): void
{
$streetName = $this->faker->streetName();

self::assertNotEmpty($streetName);
self::assertIsString($streetName);
}

public function testCityNameIsAValidString(): void
{
$city = $this->faker->city();

self::assertNotEmpty($city);
self::assertIsString($city);
}

/**
* Test the name of the Nigerian State/County
* Test the name of the Nigerian State
*/
public function testCountyIsAValidString(): void
public function testStateIsAValidString(): void
{
$county = $this->faker->county;
$state = $this->faker->state();

self::assertNotEmpty($county);
self::assertIsString($county);
self::assertNotEmpty($state);
self::assertIsString($state);
}

/**
* Test the name of the Nigerian Region in a State.
*/
public function testRegionIsAValidString(): void
{
$region = $this->faker->region;
$region = $this->faker->region();

self::assertNotEmpty($region);
self::assertIsString($region);
Expand All @@ -44,5 +63,7 @@ public function testRegionIsAValidString(): void
protected function getProviders(): iterable
{
yield new Address($this->faker);

yield new Person($this->faker);
}
}
Loading