From 6d80a47d2d69357dc08af7ed5bb01b0bebb00872 Mon Sep 17 00:00:00 2001 From: David Parry Date: Sat, 14 Dec 2024 14:09:20 +1100 Subject: [PATCH] add state abbreviation for Australian addresses --- src/Faker/Provider/en_AU/Address.php | 12 ++++++++++++ test/Faker/Provider/en_AU/AddressTest.php | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/src/Faker/Provider/en_AU/Address.php b/src/Faker/Provider/en_AU/Address.php index dec249044f..54396ab4d2 100644 --- a/src/Faker/Provider/en_AU/Address.php +++ b/src/Faker/Provider/en_AU/Address.php @@ -109,4 +109,16 @@ public static function state() { return static::randomElement(static::$state); } + + /** + * Returns a sane state abbreviation + * + * @example NSW + * + * @return string + */ + public static function stateAbbr() + { + return static::randomElement(static::$stateAbbr); + } } diff --git a/test/Faker/Provider/en_AU/AddressTest.php b/test/Faker/Provider/en_AU/AddressTest.php index 35a5853cc7..d31e03c3a6 100644 --- a/test/Faker/Provider/en_AU/AddressTest.php +++ b/test/Faker/Provider/en_AU/AddressTest.php @@ -33,6 +33,14 @@ public function testState(): void self::assertMatchesRegularExpression('/[A-Z][a-z]+/', $state); } + public function testStateAbbr(): void + { + $stateAbbr = $this->faker->stateAbbr(); + self::assertNotEmpty($stateAbbr); + self::assertIsString($stateAbbr); + self::assertMatchesRegularExpression('/^[A-Z]{2,3}$/', $stateAbbr); + } + protected function getProviders(): iterable { yield new Address($this->faker);