Skip to content

Commit

Permalink
Enable PHPStan Level 6 (#1194)
Browse files Browse the repository at this point in the history
* Update phpstan.neon

* Update YandexTest.php

* Update TomTomTest.php

* Update PickPointTest.php

* Update PickPoint.php

* Update PhotonTest.php

* Update PeliasTest.php

* Update OpenRouteServiceTest.php

* Update OpenCageTest.php

* Update OpenCage.php

* Update NominatimTest.php

* Update MaxMindBinaryTest.php

* Update MaxMindTest.php

* [WIP] Apply PHPStan fixes

* Apply PHPCSFixer fixes

* [WIP] Apply PHPStan fixes

* [WIP] Apply PHPStan fixes

* Revert "[WIP] Apply PHPStan fixes"

This reverts commit 734c5c52fbcba4bc12cbda07b58d902a79d47891.

* [WIP] Apply PHPStan fixes

* [WIP] Apply PHPStan fixes

* Update phpstan-baseline.neon
  • Loading branch information
jbelien committed Jul 31, 2023
1 parent cb4ac07 commit da3c092
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions Tests/MaxMindBinaryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@

class MaxMindBinaryTest extends BaseTestCase
{
private $binaryFile;
private string $binaryFile;

public function setUp(): void
{
$this->binaryFile = __DIR__.'/fixtures/GeoLiteCity.dat';
}

protected function getCacheDir()
protected function getCacheDir(): string
{
return __DIR__.'/.cached_responses';
}
Expand All @@ -44,23 +44,26 @@ public static function setUpBeforeClass(): void
}
}

public static function provideIps()
/**
* @return array<string, string[]>
*/
public static function provideIps(): array
{
return [
'24.24.24.24' => ['24.24.24.24', 'East Syracuse', 'United States'],
'80.24.24.24' => ['80.24.24.24', 'Sabadell', 'Spain'],
];
}

public function testThrowIfNotExistBinaryFileGiven()
public function testThrowIfNotExistBinaryFileGiven(): void
{
$this->expectException(\Geocoder\Exception\InvalidArgument::class);
$this->expectExceptionMessage('Given MaxMind dat file "not_exist.dat" does not exist.');

new MaxMindBinary('not_exist.dat');
}

public function testLocationResultContainsExpectedFieldsForAnAmericanIp()
public function testLocationResultContainsExpectedFieldsForAnAmericanIp(): void
{
$provider = new MaxMindBinary($this->binaryFile);
$results = $provider->geocodeQuery(GeocodeQuery::create('24.24.24.24'));
Expand Down Expand Up @@ -88,7 +91,7 @@ public function testLocationResultContainsExpectedFieldsForAnAmericanIp()
$this->assertNull($result->getTimezone());
}

public function testLocationResultContainsExpectedFieldsForASpanishIp()
public function testLocationResultContainsExpectedFieldsForASpanishIp(): void
{
$provider = new MaxMindBinary($this->binaryFile);
$results = $provider->geocodeQuery(GeocodeQuery::create('80.24.24.24'));
Expand Down Expand Up @@ -119,7 +122,7 @@ public function testLocationResultContainsExpectedFieldsForASpanishIp()
/**
* @dataProvider provideIps
*/
public function testFindLocationByIp($ip, $expectedCity, $expectedCountry)
public function testFindLocationByIp(string $ip, ?string $expectedCity, ?string $expectedCountry): void
{
$provider = new MaxMindBinary($this->binaryFile);
$results = $provider->geocodeQuery(GeocodeQuery::create($ip));
Expand All @@ -134,7 +137,7 @@ public function testFindLocationByIp($ip, $expectedCity, $expectedCountry)
$this->assertEquals($expectedCountry, $result->getCountry()->getName());
}

public function testShouldReturnResultsAsUtf8Encoded()
public function testShouldReturnResultsAsUtf8Encoded(): void
{
$provider = new MaxMindBinary($this->binaryFile);
$results = $provider->geocodeQuery(GeocodeQuery::create('212.51.181.237'));
Expand All @@ -145,14 +148,14 @@ public function testShouldReturnResultsAsUtf8Encoded()
$this->assertSame('Châlette-sur-loing', $result->getLocality());
}

public function testGetName()
public function testGetName(): void
{
$provider = new MaxMindBinary($this->binaryFile);

$this->assertEquals('maxmind_binary', $provider->getName());
}

public function testThrowIfIpAddressCouldNotBeLocated()
public function testThrowIfIpAddressCouldNotBeLocated(): void
{
$provider = new MaxMindBinary($this->binaryFile);
$result = $provider->geocodeQuery(GeocodeQuery::create('127.0.0.1'));
Expand All @@ -161,7 +164,7 @@ public function testThrowIfIpAddressCouldNotBeLocated()
$this->assertEquals(0, $result->count());
}

public function testThrowIfIpAddressIsNotIpV4()
public function testThrowIfIpAddressIsNotIpV4(): void
{
$this->expectException(\Geocoder\Exception\UnsupportedOperation::class);
$this->expectExceptionMessage('The MaxMindBinary provider does not support IPv6 addresses.');
Expand All @@ -171,7 +174,7 @@ public function testThrowIfIpAddressIsNotIpV4()
$provider->geocodeQuery(GeocodeQuery::create('2002:5018:1818:0:0:0:0:0'));
}

public function testThrowIfInvalidIpAddressGiven()
public function testThrowIfInvalidIpAddressGiven(): void
{
$this->expectException(\Geocoder\Exception\UnsupportedOperation::class);
$this->expectExceptionMessage('The MaxMindBinary provider does not support street addresses.');
Expand All @@ -181,7 +184,7 @@ public function testThrowIfInvalidIpAddressGiven()
$provider->geocodeQuery(GeocodeQuery::create('invalidIp'));
}

public function testThrowOnReverseMethodUsage()
public function testThrowOnReverseMethodUsage(): void
{
$this->expectException(\Geocoder\Exception\UnsupportedOperation::class);
$this->expectExceptionMessage('The MaxMindBinary is not able to do reverse geocoding.');
Expand Down

0 comments on commit da3c092

Please sign in to comment.