diff --git a/composer.json b/composer.json index 74b27de..183004a 100755 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "nyholm/psr7": "^1.0", "php-http/curl-client": "^2.2", "php-http/mock-client": "^1.2", - "phpunit/phpunit": "^9.5", + "phpunit/phpunit": "^9.6.17 || ^10.5 || ^11.0.4", "psr/http-client": "^1.0" }, "require-dev": { diff --git a/src/ProviderIntegrationTest.php b/src/ProviderIntegrationTest.php index 94ca1c0..227edab 100644 --- a/src/ProviderIntegrationTest.php +++ b/src/ProviderIntegrationTest.php @@ -25,6 +25,7 @@ use Geocoder\Query\ReverseQuery; use Http\Discovery\Psr18ClientDiscovery; use Nyholm\Psr7\Response; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\Http\Client\ClientInterface; @@ -40,11 +41,11 @@ abstract class ProviderIntegrationTest extends TestCase */ protected array $skippedTests = []; - protected bool $testAddress = true; - protected bool $testReverse = true; - protected bool $testIpv4 = true; - protected bool $testIpv6 = true; - protected bool $testHttpProvider = true; + protected static bool $testAddress = true; + protected static bool $testReverse = true; + protected static bool $testIpv4 = true; + protected static bool $testIpv6 = true; + protected static bool $testHttpProvider = true; /** * @return Provider that is used in the tests. @@ -102,7 +103,7 @@ public function testGeocodeQuery(): void if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } - if (!$this->testAddress) { + if (!static::$testAddress) { $this->markTestSkipped('Geocoding address is not supported by this provider'); } @@ -132,7 +133,7 @@ public function testGeocodeQueryWithNoResults(): void if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } - if (!$this->testAddress) { + if (!static::$testAddress) { $this->markTestSkipped('Geocoding address is not supported by this provider'); } @@ -148,7 +149,7 @@ public function testReverseQuery(): void if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } - if (!$this->testReverse) { + if (!static::$testReverse) { $this->markTestSkipped('Reverse geocoding address is not supported by this provider'); } @@ -165,7 +166,7 @@ public function testReverseQueryWithNoResults(): void $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } - if (!$this->testReverse) { + if (!static::$testReverse) { $this->markTestSkipped('Reverse geocoding address is not supported by this provider'); } @@ -181,7 +182,7 @@ public function testGeocodeIpv4(): void $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } - if (!$this->testIpv4) { + if (!static::$testIpv4) { $this->markTestSkipped('Geocoding IPv4 is not supported by this provider'); } @@ -196,7 +197,7 @@ public function testGeocodeIpv6(): void $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } - if (!$this->testIpv6) { + if (!static::$testIpv6) { $this->markTestSkipped('Geocoding IPv6 is not supported by this provider'); } @@ -213,6 +214,7 @@ public function testGeocodeIpv6(): void * @param ResponseInterface|null $response * @param string $message */ + #[DataProvider('exceptionDataProvider')] public function testExceptions($query, string $exceptionClass, ResponseInterface $response = null, string $message = ''): void { if (isset($this->skippedTests[__FUNCTION__])) { @@ -236,15 +238,15 @@ public function testExceptions($query, string $exceptionClass, ResponseInterface /** * @return array, Response, string}> */ - public function exceptionDataProvider(): array + public static function exceptionDataProvider(): array { $testData = []; - if (!$this->testHttpProvider) { + if (!static::$testHttpProvider) { return $testData; } - if ($this->testAddress) { + if (static::$testAddress) { $q = GeocodeQuery::create('foo'); $testData[] = [$q, InvalidServerResponse::class, new Response(500), 'Server 500']; $testData[] = [$q, InvalidServerResponse::class, new Response(400), 'Server 400']; @@ -253,7 +255,7 @@ public function exceptionDataProvider(): array $testData[] = [$q, InvalidServerResponse::class, new Response(200), 'Empty response']; } - if ($this->testReverse) { + if (static::$testReverse) { $q = ReverseQuery::fromCoordinates(0, 0); $testData[] = [$q, InvalidServerResponse::class, new Response(500), 'Server 500']; $testData[] = [$q, InvalidServerResponse::class, new Response(400), 'Server 400']; @@ -262,7 +264,7 @@ public function exceptionDataProvider(): array $testData[] = [$q, QuotaExceeded::class, new Response(429), 'Quota exceeded response']; } - if ($this->testIpv4) { + if (static::$testIpv4) { $q = GeocodeQuery::create('123.123.123.123'); $testData[] = [$q, InvalidServerResponse::class, new Response(500), 'Server 500']; $testData[] = [$q, InvalidServerResponse::class, new Response(400), 'Server 400']; @@ -271,7 +273,7 @@ public function exceptionDataProvider(): array $testData[] = [$q, QuotaExceeded::class, new Response(429), 'Quota exceeded response']; } - if ($this->testIpv6) { + if (static::$testIpv6) { $q = GeocodeQuery::create('2001:0db8:0000:0042:0000:8a2e:0370:7334'); $testData[] = [$q, InvalidServerResponse::class, new Response(500), 'Server 500']; $testData[] = [$q, InvalidServerResponse::class, new Response(400), 'Server 400']; diff --git a/tests/NominatimTest.php b/tests/NominatimTest.php index 51a98fd..55779d4 100644 --- a/tests/NominatimTest.php +++ b/tests/NominatimTest.php @@ -19,8 +19,8 @@ */ class NominatimTest extends ProviderIntegrationTest { - protected bool $testIpv4 = false; - protected bool $testIpv6 = false; + protected static bool $testIpv4 = false; + protected static bool $testIpv6 = false; protected function createProvider(ClientInterface $httpClient) {