Skip to content

Commit 2de52c7

Browse files
author
Fábio Galvão
committed
Replace php-http/message-factory to psr/http-factory
1 parent 2eca382 commit 2de52c7

File tree

4 files changed

+10
-36
lines changed

4 files changed

+10
-36
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"php": "^7.2|^8",
4646
"php-http/client-implementation": "^1",
4747
"php-http/message": "^1.5",
48-
"php-http/message-factory": "^1.1",
48+
"psr/http-factory": "^1.0.2",
4949
"php-http/discovery": "^1.14",
5050
"symfony/http-foundation": "^2.1|^3|^4|^5|^6|^7",
5151
"moneyphp/money": "^3.1|^4.0.3"

src/Common/Http/Client.php

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
use Http\Client\HttpClient;
77
use Http\Discovery\HttpClientDiscovery;
88
use Http\Discovery\MessageFactoryDiscovery;
9-
use Http\Message\RequestFactory;
109
use Omnipay\Common\Http\Exception\NetworkException;
1110
use Omnipay\Common\Http\Exception\RequestException;
1211
use Psr\Http\Message\RequestInterface;
12+
use Psr\Http\Message\RequestFactoryInterface;
1313
use Psr\Http\Message\ResponseInterface;
1414
use Psr\Http\Message\StreamInterface;
1515
use Psr\Http\Message\UriInterface;
@@ -25,33 +25,25 @@ class Client implements ClientInterface
2525
private $httpClient;
2626

2727
/**
28-
* @var RequestFactory
28+
* @var RequestFactoryInterface
2929
*/
3030
private $requestFactory;
3131

32-
public function __construct($httpClient = null, RequestFactory $requestFactory = null)
32+
public function __construct($httpClient = null, RequestFactoryInterface $requestFactory = null)
3333
{
3434
$this->httpClient = $httpClient ?: HttpClientDiscovery::find();
3535
$this->requestFactory = $requestFactory ?: MessageFactoryDiscovery::find();
3636
}
3737

3838
/**
39-
* @param $method
40-
* @param $uri
41-
* @param array $headers
42-
* @param string|array|resource|StreamInterface|null $body
43-
* @param string $protocolVersion
39+
* @param string $method
40+
* @param string|UriInterface $uri
4441
* @return ResponseInterface
4542
* @throws \Http\Client\Exception
4643
*/
4744
public function request(
48-
$method,
49-
$uri,
50-
array $headers = [],
51-
$body = null,
52-
$protocolVersion = '1.1'
53-
) {
54-
$request = $this->requestFactory->createRequest($method, $uri, $headers, $body, $protocolVersion);
45+
$method, $uri) {
46+
$request = $this->requestFactory->createRequest($method, $uri);
5547

5648
return $this->sendRequest($request);
5749
}

src/Common/Http/ClientInterface.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ interface ClientInterface
1515
*
1616
* @param string $method
1717
* @param string|UriInterface $uri
18-
* @param array $headers
19-
* @param resource|string|StreamInterface|null $body
20-
* @param string $protocolVersion
2118
*
2219
* @throws RequestException when the HTTP client is passed a request that is invalid and cannot be sent.
2320
* @throws NetworkException if there is an error with the network or the remote server cannot be reached.
@@ -26,9 +23,6 @@ interface ClientInterface
2623
*/
2724
public function request(
2825
$method,
29-
$uri,
30-
array $headers = [],
31-
$body = null,
32-
$protocolVersion = '1.1'
26+
$uri
3327
);
3428
}

tests/Common/Http/ClientTest.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Mockery as m;
88
use GuzzleHttp\Psr7\Request;
99
use Http\Client\HttpClient;
10-
use Http\Message\RequestFactory;
10+
use Psr\Http\Message\RequestFactoryInterface as RequestFactory;
1111
use Omnipay\Common\Http\Exception\RequestException;
1212
use Omnipay\Tests\TestCase;
1313

@@ -26,9 +26,6 @@ public function testSend()
2626
$mockFactory->shouldReceive('createRequest')->withArgs([
2727
'GET',
2828
'/path',
29-
[],
30-
null,
31-
'1.1',
3229
])->andReturn($request);
3330

3431
$mockClient->shouldReceive('sendRequest')
@@ -52,9 +49,6 @@ public function testSendException()
5249
$mockFactory->shouldReceive('createRequest')->withArgs([
5350
'GET',
5451
'/path',
55-
[],
56-
null,
57-
'1.1',
5852
])->andReturn($request);
5953

6054
$mockClient->shouldReceive('sendRequest')
@@ -79,9 +73,6 @@ public function testSendNetworkException()
7973
$mockFactory->shouldReceive('createRequest')->withArgs([
8074
'GET',
8175
'/path',
82-
[],
83-
null,
84-
'1.1',
8576
])->andReturn($request);
8677

8778
$mockClient->shouldReceive('sendRequest')
@@ -106,9 +97,6 @@ public function testSendExceptionGetRequest()
10697
$mockFactory->shouldReceive('createRequest')->withArgs([
10798
'GET',
10899
'/path',
109-
[],
110-
null,
111-
'1.1',
112100
])->andReturn($request);
113101

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

0 commit comments

Comments
 (0)