Skip to content

Commit

Permalink
add state abbreviation for Australian addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
devbobo committed Dec 14, 2024
1 parent a1f1c0e commit 6d80a47
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Faker/Provider/en_AU/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
8 changes: 8 additions & 0 deletions test/Faker/Provider/en_AU/AddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 6d80a47

Please sign in to comment.