Skip to content
Merged
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
10 changes: 5 additions & 5 deletions src/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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())
Expand Down
21 changes: 10 additions & 11 deletions src/CachedResponseClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <tobias.nyholm@gmail.com>
*/
class CachedResponseClient implements HttpClient
class CachedResponseClient implements ClientInterface
{
use HttpClientTrait;

/**
* @var HttpClient
* @var ClientInterface
*/
private $delegate;

Expand All @@ -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;
Expand All @@ -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();
Expand Down
48 changes: 0 additions & 48 deletions src/HttpClientTrait.php

This file was deleted.

16 changes: 8 additions & 8 deletions src/ProviderIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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
Expand All @@ -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())
Expand All @@ -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())
Expand Down
4 changes: 2 additions & 2 deletions tests/NominatimTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <tobias.nyholm@gmail.com>
Expand All @@ -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');
}
Expand Down