Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"php-http/client-common": "^2.7",
"php-http/discovery": "^1.18",
"php-http/logger-plugin": "^1.3",
"programmatordev/yet-another-php-validator": "^0.1.1",
"programmatordev/yet-another-php-validator": "^0.2",
"psr/cache": "^2.0 || ^3.0",
"psr/http-client": "^1.0",
"psr/http-factory": "^1.0",
Expand Down
10 changes: 6 additions & 4 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ class Config

public function __construct(array $options = [])
{
$resolver = new OptionsResolver();
$this->configureOptions($resolver);
$this->options = $resolver->resolve($options);
$this->options = $this->resolveOptions($options);
}

private function configureOptions(OptionsResolver $resolver): void
private function resolveOptions(array $options): array
{
$resolver = new OptionsResolver();

$resolver->setDefaults([
'unitSystem' => UnitSystem::METRIC,
'language' => Language::ENGLISH,
Expand All @@ -46,6 +46,8 @@ private function configureOptions(OptionsResolver $resolver): void
});
$resolver->setAllowedValues('unitSystem', UnitSystem::getList());
$resolver->setAllowedValues('language', Language::getList());

return $resolver->resolve($options);
}

public function getApplicationKey(): string
Expand Down
2 changes: 1 addition & 1 deletion src/Endpoint/AbstractEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private function buildUrl(UriInterface|string $baseUrl, array $query): string

// Add application key to all requests
$query = $query + [
'appid' => $this->api->getConfig()->getApplicationKey()
'appid' => $this->config->getApplicationKey()
];

return \sprintf('%s?%s', $baseUrl, http_build_query($query));
Expand Down
2 changes: 1 addition & 1 deletion src/Endpoint/GeocodingEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function getByLocationName(string $locationName, int $numResults = self::
public function getByZipCode(string $zipCode, string $countryCode): ZipCodeLocation
{
Validator::notBlank()->assert($zipCode, 'zipCode');
Validator::notBlank()->assert($countryCode, 'countryCode');
Validator::country()->assert($countryCode, 'countryCode');

$data = $this->sendRequest(
method: 'GET',
Expand Down
7 changes: 4 additions & 3 deletions tests/GeocodingEndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,18 @@ public function testGeocodingGetByZipCode()
$this->assertSame(-9.1333, $coordinate->getLongitude());
}

#[DataProvider('provideGeocodingGetByZipCodeWithBlankValueData')]
public function testGeocodingGetByZipCodeWithBlankValue(string $zipCode, string $countryCode)
#[DataProvider('provideGeocodingGetByZipCodeWithInvalidValueData')]
public function testGeocodingGetByZipCodeWithInvalidValue(string $zipCode, string $countryCode)
{
$this->expectException(ValidationException::class);
$this->getApi()->getGeocoding()->getByZipCode($zipCode, $countryCode);
}

public static function provideGeocodingGetByZipCodeWithBlankValueData(): \Generator
public static function provideGeocodingGetByZipCodeWithInvalidValueData(): \Generator
{
yield 'blank zip code' => ['', 'pt'];
yield 'blank country code' => ['1000-100', ''];
yield 'invalid country code' => ['1000-100', 'invalid'];
}

public function testGeocodingGetByCoordinate()
Expand Down