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 stateAbbr() method for en_AU #927

Open
wants to merge 3 commits into
base: 1.24
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
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