diff --git a/CHANGELOG.md b/CHANGELOG.md index a8e08cbd39..407f01ff9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,8 @@ - Removed domain `gmail.com.au` from `Provider\en_AU\Internet` (#886) - Refreshed ISO currencies (#919) -- +- Add support for stateAddr() to `Provider\en_AU\Address` (#927) + ## [2024-11-09, v1.24.0](https://github.com/FakerPHP/Faker/compare/v1.23.1..v1.24.0) - Fix internal deprecations in Doctrine's populator by @gnutix in (#889) 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);