Skip to content

Commit 7c9d6cf

Browse files
committed
chore: improved country code validation
1 parent 404e5c3 commit 7c9d6cf

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/Endpoint/GeocodingEndpoint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function getByLocationName(string $locationName, int $numResults = self::
6767
public function getByZipCode(string $zipCode, string $countryCode): ZipCodeLocation
6868
{
6969
Validator::notBlank()->assert($zipCode, 'zipCode');
70-
Validator::notBlank()->assert($countryCode, 'countryCode');
70+
Validator::country()->assert($countryCode, 'countryCode');
7171

7272
$data = $this->sendRequest(
7373
method: 'GET',

tests/GeocodingEndpointTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,18 @@ public function testGeocodingGetByZipCode()
5454
$this->assertSame(-9.1333, $coordinate->getLongitude());
5555
}
5656

57-
#[DataProvider('provideGeocodingGetByZipCodeWithBlankValueData')]
58-
public function testGeocodingGetByZipCodeWithBlankValue(string $zipCode, string $countryCode)
57+
#[DataProvider('provideGeocodingGetByZipCodeWithInvalidValueData')]
58+
public function testGeocodingGetByZipCodeWithInvalidValue(string $zipCode, string $countryCode)
5959
{
6060
$this->expectException(ValidationException::class);
6161
$this->getApi()->getGeocoding()->getByZipCode($zipCode, $countryCode);
6262
}
6363

64-
public static function provideGeocodingGetByZipCodeWithBlankValueData(): \Generator
64+
public static function provideGeocodingGetByZipCodeWithInvalidValueData(): \Generator
6565
{
6666
yield 'blank zip code' => ['', 'pt'];
6767
yield 'blank country code' => ['1000-100', ''];
68+
yield 'invalid country code' => ['1000-100', 'invalid'];
6869
}
6970

7071
public function testGeocodingGetByCoordinate()

0 commit comments

Comments
 (0)