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 support for PHP 8 #6

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
vendor/
composer.lock
phpunit.xml
.phpunit.result.cache
16 changes: 5 additions & 11 deletions Geo6.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
use Geocoder\Query\GeocodeQuery;
use Geocoder\Query\ReverseQuery;
use Jose\Component\Core\AlgorithmManager;
use Jose\Component\Core\Converter\StandardConverter;
use Jose\Component\Core\JWK;
use Jose\Component\Signature\Algorithm\HS512;
use Jose\Component\Signature\JWSBuilder;
Expand Down Expand Up @@ -325,37 +324,32 @@ private function getGeo6Token(string $path): array
*/
private function getJWT(): string
{
$algorithmManager = AlgorithmManager::create([
$algorithmManager = new AlgorithmManager([
new HS512(),
]);

$jwk = JWK::create([
$jwk = new JWK([
'kty' => 'oct',
'k' => $this->privateKey,
'use' => 'sig',
]);

$jsonConverter = new StandardConverter();

$payload = $jsonConverter->encode([
$payload = json_encode([
'aud' => 'GEO-6 API',
'iat' => time(),
'iss' => sprintf('geocoder-php-%s', $this->getName()),
'sub' => $this->clientId,
]);

$jwsBuilder = new JWSBuilder(
$jsonConverter,
$algorithmManager
);
$jwsBuilder = new JWSBuilder($algorithmManager);

$jws = $jwsBuilder
->create()
->withPayload($payload)
->addSignature($jwk, ['alg' => 'HS512', 'typ' => 'JWT'])
->build();

return (new CompactSerializer($jsonConverter))->serialize($jws);
return (new CompactSerializer())->serialize($jws);
}

/**
Expand Down
21 changes: 9 additions & 12 deletions Tests/Geo6Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,29 @@ protected function getCacheDir()
return __DIR__.'/.cached_responses';
}

/**
* @expectedException \Geocoder\Exception\UnsupportedOperation
* @expectedExceptionMessage The Geo-6 provider does not support IP addresses, only street addresses.
*/
public function testGeocodeWithLocalhostIPv4()
{
$this->expectException(\Geocoder\Exception\UnsupportedOperation::class);
$this->expectExceptionMessage('The Geo-6 provider does not support IP addresses, only street addresses.');

$provider = new Geo6($this->getMockedHttpClient(), '', '');
$provider->geocodeQuery(GeocodeQuery::create('127.0.0.1'));
}

/**
* @expectedException \Geocoder\Exception\UnsupportedOperation
* @expectedExceptionMessage The Geo-6 provider does not support IP addresses, only street addresses.
*/
public function testGeocodeWithLocalhostIPv6()
{
$this->expectException(\Geocoder\Exception\UnsupportedOperation::class);
$this->expectExceptionMessage('The Geo-6 provider does not support IP addresses, only street addresses.');

$provider = new Geo6($this->getMockedHttpClient(), '', '');
$provider->geocodeQuery(GeocodeQuery::create('::1'));
}

/**
* @expectedException \Geocoder\Exception\UnsupportedOperation
* @expectedExceptionMessage The Geo-6 provider does not support IP addresses, only street addresses.
*/
public function testGeocodeWithRealIPv6()
{
$this->expectException(\Geocoder\Exception\UnsupportedOperation::class);
$this->expectExceptionMessage('The Geo-6 provider does not support IP addresses, only street addresses.');

$provider = new Geo6($this->getMockedHttpClient(), '', '');
$provider->geocodeQuery(GeocodeQuery::create('::ffff:88.188.221.14'));
}
Expand Down
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
}
],
"require": {
"php": "^7.0",
"php": "^7.4 || ^8.0",
"geocoder-php/common-http": "^4.1",
"web-token/jwt-key-mgmt": "^1.2",
"web-token/jwt-signature": "^1.2",
"web-token/jwt-key-mgmt": "^2.0",
"web-token/jwt-signature": "^2.0",
"web-token/jwt-signature-algorithm-hmac": "^2.0",
"willdurand/geocoder": "^4.0"
},
"provide": {
Expand All @@ -24,7 +25,7 @@
"geocoder-php/provider-integration-tests": "^1.0",
"php-http/curl-client": "^1.7 || ^2.0",
"php-http/message": "^1.0",
"phpunit/phpunit": "^6.5 || ^7.5"
"phpunit/phpunit": "^9.5"
},
"config": {
"sort-packages": true
Expand Down
48 changes: 20 additions & 28 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php"
>
<php>
<server name="GEO6_CUSTOMER_ID" value="" />
<server name="GEO6_API_KEY" value="" />
<server name="USE_CACHED_RESPONSES" value="true" />
</php>

<testsuites>
<testsuite name="Geocoder Test Suite">
<directory>./Tests/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>./</directory>
<exclude>
<directory>./Tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false" colors="true" bootstrap="vendor/autoload.php">
<coverage>
<include>
<directory>./</directory>
</include>
<exclude>
<directory>./Tests</directory>
<directory>./vendor</directory>
</exclude>
</coverage>
<php>
<server name="GEO6_CUSTOMER_ID" value=""/>
<server name="GEO6_API_KEY" value=""/>
<server name="USE_CACHED_RESPONSES" value="true"/>
</php>
<testsuites>
<testsuite name="Geocoder Test Suite">
<directory>./Tests/</directory>
</testsuite>
</testsuites>
</phpunit>