Skip to content

Commit

Permalink
Replace php-http/message-factory to psr/http-factory
Browse files Browse the repository at this point in the history
  • Loading branch information
Fábio Galvão committed Apr 15, 2024
1 parent 2eca382 commit 2de52c7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 36 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"php": "^7.2|^8",
"php-http/client-implementation": "^1",
"php-http/message": "^1.5",
"php-http/message-factory": "^1.1",
"psr/http-factory": "^1.0.2",
"php-http/discovery": "^1.14",
"symfony/http-foundation": "^2.1|^3|^4|^5|^6|^7",
"moneyphp/money": "^3.1|^4.0.3"
Expand Down
22 changes: 7 additions & 15 deletions src/Common/Http/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
use Http\Client\HttpClient;
use Http\Discovery\HttpClientDiscovery;
use Http\Discovery\MessageFactoryDiscovery;
use Http\Message\RequestFactory;
use Omnipay\Common\Http\Exception\NetworkException;
use Omnipay\Common\Http\Exception\RequestException;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamInterface;
use Psr\Http\Message\UriInterface;
Expand All @@ -25,33 +25,25 @@ class Client implements ClientInterface
private $httpClient;

/**
* @var RequestFactory
* @var RequestFactoryInterface
*/
private $requestFactory;

public function __construct($httpClient = null, RequestFactory $requestFactory = null)
public function __construct($httpClient = null, RequestFactoryInterface $requestFactory = null)
{
$this->httpClient = $httpClient ?: HttpClientDiscovery::find();
$this->requestFactory = $requestFactory ?: MessageFactoryDiscovery::find();
}

/**
* @param $method
* @param $uri
* @param array $headers
* @param string|array|resource|StreamInterface|null $body
* @param string $protocolVersion
* @param string $method
* @param string|UriInterface $uri
* @return ResponseInterface
* @throws \Http\Client\Exception
*/
public function request(
$method,
$uri,
array $headers = [],
$body = null,
$protocolVersion = '1.1'
) {
$request = $this->requestFactory->createRequest($method, $uri, $headers, $body, $protocolVersion);
$method, $uri) {
$request = $this->requestFactory->createRequest($method, $uri);

return $this->sendRequest($request);
}
Expand Down
8 changes: 1 addition & 7 deletions src/Common/Http/ClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ interface ClientInterface
*
* @param string $method
* @param string|UriInterface $uri
* @param array $headers
* @param resource|string|StreamInterface|null $body
* @param string $protocolVersion
*
* @throws RequestException when the HTTP client is passed a request that is invalid and cannot be sent.
* @throws NetworkException if there is an error with the network or the remote server cannot be reached.
Expand All @@ -26,9 +23,6 @@ interface ClientInterface
*/
public function request(
$method,
$uri,
array $headers = [],
$body = null,
$protocolVersion = '1.1'
$uri
);
}
14 changes: 1 addition & 13 deletions tests/Common/Http/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Mockery as m;
use GuzzleHttp\Psr7\Request;
use Http\Client\HttpClient;
use Http\Message\RequestFactory;
use Psr\Http\Message\RequestFactoryInterface as RequestFactory;
use Omnipay\Common\Http\Exception\RequestException;
use Omnipay\Tests\TestCase;

Expand All @@ -26,9 +26,6 @@ public function testSend()
$mockFactory->shouldReceive('createRequest')->withArgs([
'GET',
'/path',
[],
null,
'1.1',
])->andReturn($request);

$mockClient->shouldReceive('sendRequest')
Expand All @@ -52,9 +49,6 @@ public function testSendException()
$mockFactory->shouldReceive('createRequest')->withArgs([
'GET',
'/path',
[],
null,
'1.1',
])->andReturn($request);

$mockClient->shouldReceive('sendRequest')
Expand All @@ -79,9 +73,6 @@ public function testSendNetworkException()
$mockFactory->shouldReceive('createRequest')->withArgs([
'GET',
'/path',
[],
null,
'1.1',
])->andReturn($request);

$mockClient->shouldReceive('sendRequest')
Expand All @@ -106,9 +97,6 @@ public function testSendExceptionGetRequest()
$mockFactory->shouldReceive('createRequest')->withArgs([
'GET',
'/path',
[],
null,
'1.1',
])->andReturn($request);

$exception = new \Exception('Something went wrong');
Expand Down

0 comments on commit 2de52c7

Please sign in to comment.