diff --git a/README.md b/README.md index 7f441f5..4f02a6b 100644 --- a/README.md +++ b/README.md @@ -18,13 +18,13 @@ composer require --dev geocoder-php/provider-integration-tests:dev-master Create a test that looks like this: ```php -use Http\Client\HttpClient; use Geocoder\IntegrationTest\ProviderIntegrationTest; use Geocoder\Provider\GoogleMaps\GoogleMaps; +use Psr\Http\Client\ClientInterface; class IntegrationTest extends ProviderIntegrationTest { - protected function createProvider(HttpClient $httpClient) + protected function createProvider(ClientInterface $httpClient) { return new GoogleMaps($httpClient); } diff --git a/composer.json b/composer.json index 0ac9595..7dd12dd 100755 --- a/composer.json +++ b/composer.json @@ -17,6 +17,7 @@ "php": "^7.3 || ^8.0", "phpunit/phpunit": "^9.5", "php-http/mock-client": "^1.2", + "psr/http-client": "^1.0", "nyholm/psr7": "^1.0" }, "require-dev": { diff --git a/src/BaseTestCase.php b/src/BaseTestCase.php index 7f4be35..7e9f3db 100644 --- a/src/BaseTestCase.php +++ b/src/BaseTestCase.php @@ -11,10 +11,10 @@ namespace Geocoder\IntegrationTest; use Http\Client\Curl\Client as HttplugClient; -use Http\Client\HttpClient; use Http\Mock\Client as MockedHttpClient; use Nyholm\Psr7\Response; use PHPUnit\Framework\TestCase; +use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -31,7 +31,7 @@ abstract protected function getCacheDir(); /** * Get a real HTTP client. If a cache dir is set to a path it will use cached responses. * - * @return HttpClient + * @return ClientInterface */ protected function getHttpClient($apiKey = null) { @@ -48,7 +48,7 @@ protected function getHttpClient($apiKey = null) * @param string|null $body * @param int $statusCode * - * @return HttpClient + * @return ClientInterface */ protected function getMockedHttpClient($body = null, $statusCode = 200) { @@ -64,11 +64,11 @@ protected function getMockedHttpClient($body = null, $statusCode = 200) * @param string|null $body * @param int $statusCode * - * @return HttpClient + * @return ClientInterface */ protected function getMockedHttpClientCallback(callable $requestCallback) { - $client = $this->getMockBuilder(HttpClient::class)->getMock(); + $client = $this->getMockBuilder(ClientInterface::class)->getMock(); $client ->expects($this->once()) diff --git a/src/CachedResponseClient.php b/src/CachedResponseClient.php index 7968e01..4e12db3 100644 --- a/src/CachedResponseClient.php +++ b/src/CachedResponseClient.php @@ -10,22 +10,21 @@ namespace Geocoder\IntegrationTest; -use Http\Client\HttpClient; use Nyholm\Psr7\Factory\HttplugFactory; use Nyholm\Psr7\Response; +use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestInterface; +use Psr\Http\Message\ResponseInterface; /** * Serve responses from local file cache. * * @author Tobias Nyholm */ -class CachedResponseClient implements HttpClient +class CachedResponseClient implements ClientInterface { - use HttpClientTrait; - /** - * @var HttpClient + * @var ClientInterface */ private $delegate; @@ -45,12 +44,12 @@ class CachedResponseClient implements HttpClient private $cacheDir; /** - * @param HttpClient $delegate - * @param string $cacheDir - * @param string|null $apiKey - * @param string|null $appCode + * @param ClientInterface $delegate + * @param string $cacheDir + * @param string|null $apiKey + * @param string|null $appCode */ - public function __construct(HttpClient $delegate, $cacheDir, $apiKey = null, $appCode = null) + public function __construct(ClientInterface $delegate, $cacheDir, $apiKey = null, $appCode = null) { $this->delegate = $delegate; $this->cacheDir = $cacheDir; @@ -61,7 +60,7 @@ public function __construct(HttpClient $delegate, $cacheDir, $apiKey = null, $ap /** * {@inheritdoc} */ - protected function doSendRequest(RequestInterface $request) + public function sendRequest(RequestInterface $request): ResponseInterface { $host = (string) $request->getUri()->getHost(); $cacheKey = (string) $request->getUri(); diff --git a/src/HttpClientTrait.php b/src/HttpClientTrait.php deleted file mode 100644 index 3b14af2..0000000 --- a/src/HttpClientTrait.php +++ /dev/null @@ -1,48 +0,0 @@ -doSendRequest($request); - } - } -} else { - /** - * @internal code for php-http/httplug:1.x - */ - trait HttpClientTrait - { - abstract protected function doSendRequest(RequestInterface $request); - - public function sendRequest(RequestInterface $request) - { - return $this->doSendRequest($request); - } - } -} diff --git a/src/ProviderIntegrationTest.php b/src/ProviderIntegrationTest.php index 89d3846..4af41c8 100644 --- a/src/ProviderIntegrationTest.php +++ b/src/ProviderIntegrationTest.php @@ -22,10 +22,10 @@ use Geocoder\Provider\Provider; use Geocoder\Query\GeocodeQuery; use Geocoder\Query\ReverseQuery; -use Http\Client\HttpClient; -use Http\Discovery\HttpClientDiscovery; +use Http\Discovery\Psr18ClientDiscovery; use Nyholm\Psr7\Response; use PHPUnit\Framework\TestCase; +use Psr\Http\Client\ClientInterface; use Psr\Http\Message\ResponseInterface; /** @@ -47,7 +47,7 @@ abstract class ProviderIntegrationTest extends TestCase /** * @return Provider that is used in the tests. */ - abstract protected function createProvider(HttpClient $httpClient); + abstract protected function createProvider(ClientInterface $httpClient); /** * @return string the directory where cached responses are stored @@ -62,11 +62,11 @@ abstract protected function getApiKey(); /** * @param ResponseInterface $response * - * @return \PHPUnit_Framework_MockObject_MockObject|HttpClient + * @return \PHPUnit_Framework_MockObject_MockObject|ClientInterface */ private function getHttpClient(ResponseInterface $response) { - $client = $this->getMockForAbstractClass(HttpClient::class); + $client = $this->getMockForAbstractClass(ClientInterface::class); $client ->expects($this->any()) @@ -84,9 +84,9 @@ private function getHttpClient(ResponseInterface $response) private function getCachedHttpClient() { try { - $client = HttpClientDiscovery::find(); - } catch (\Http\Discovery\NotFoundException $e) { - $client = $this->getMockForAbstractClass(HttpClient::class); + $client = Psr18ClientDiscovery::find(); + } catch (\Http\Discovery\Exception\NotFoundException $e) { + $client = $this->getMockForAbstractClass(ClientInterface::class); $client ->expects($this->any()) diff --git a/tests/NominatimTest.php b/tests/NominatimTest.php index cbc12a7..9c9a20d 100644 --- a/tests/NominatimTest.php +++ b/tests/NominatimTest.php @@ -12,7 +12,7 @@ use Geocoder\IntegrationTest\ProviderIntegrationTest; use Geocoder\Provider\Nominatim\Nominatim; -use Http\Client\HttpClient; +use Psr\Http\Client\ClientInterface; /** * @author Tobias Nyholm @@ -22,7 +22,7 @@ class NominatimTest extends ProviderIntegrationTest protected $testIpv4 = false; protected $testIpv6 = false; - protected function createProvider(HttpClient $httpClient) + protected function createProvider(ClientInterface $httpClient) { return Nominatim::withOpenStreetMapServer($httpClient, 'Geocoder PHP/Nominatim Provider/Nominatim Test'); }