Skip to content

Commit 46daacf

Browse files
committed
Simplify Http Client
1 parent 31d821e commit 46daacf

File tree

2 files changed

+2
-95
lines changed

2 files changed

+2
-95
lines changed

src/Common/Http/Client.php

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,8 @@ public function __construct($httpClient = null, RequestFactory $requestFactory =
3939
* @param string $protocolVersion
4040
* @return ResponseInterface
4141
*/
42-
public function send($method, $uri, array $headers = [], $body = null, $protocolVersion = '1.1')
42+
public function request($method, $uri, array $headers = [], $body = null, $protocolVersion = '1.1')
4343
{
44-
if (is_array($body)) {
45-
$body = http_build_query($body, '', '&');
46-
}
47-
4844
$request = $this->createRequest($method, $uri, $headers, $body, $protocolVersion);
4945

5046
return $this->sendRequest($request);
@@ -71,29 +67,4 @@ public function sendRequest(RequestInterface $request)
7167
{
7268
return $this->httpClient->sendRequest($request);
7369
}
74-
75-
/**
76-
* Send a GET request.
77-
*
78-
* @param UriInterface|string $uri
79-
* @param array $headers
80-
* @return ResponseInterface
81-
*/
82-
public function get($uri, array $headers = [])
83-
{
84-
return $this->send('GET', $uri, $headers);
85-
}
86-
87-
/**
88-
* Send a POST request.
89-
*
90-
* @param UriInterface|string $uri
91-
* @param array $headers
92-
* @param string|array|null|resource|StreamInterface $body
93-
* @return ResponseInterface
94-
*/
95-
public function post($uri, array $headers = [], $body = null)
96-
{
97-
return $this->send('POST', $uri, $headers, $body);
98-
}
9970
}

tests/Omnipay/Common/Http/ClientTest.php

Lines changed: 1 addition & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -48,70 +48,6 @@ public function testSend()
4848

4949
$mockClient->shouldReceive('sendRequest')->with($request)->once();
5050

51-
$client->send('GET', '/path');
52-
}
53-
54-
public function testSendParsesArrayBody()
55-
{
56-
$mockClient = m::mock(HttpClient::class);
57-
$mockFactory = m::mock(RequestFactory::class);
58-
$client = new Client($mockClient, $mockFactory);
59-
60-
$request = new Request('POST', '/path', [], 'a=1&b=2');
61-
62-
$mockFactory->shouldReceive('createRequest')->withArgs([
63-
'POST',
64-
'/path',
65-
[],
66-
'a=1&b=2',
67-
'1.1',
68-
])->andReturn($request);
69-
70-
$mockClient->shouldReceive('sendRequest')->with($request)->once();
71-
72-
$client->send('POST', '/path', [], ['a'=>'1', 'b'=>2]);
73-
}
74-
75-
76-
public function testGet()
77-
{
78-
$mockClient = m::mock(HttpClient::class);
79-
$mockFactory = m::mock(RequestFactory::class);
80-
$client = new Client($mockClient, $mockFactory);
81-
82-
$request = new Request('GET', '/path');
83-
84-
$mockFactory->shouldReceive('createRequest')->withArgs([
85-
'GET',
86-
'/path',
87-
[],
88-
null,
89-
'1.1',
90-
])->andReturn($request);
91-
92-
$mockClient->shouldReceive('sendRequest')->with($request)->once();
93-
94-
$client->get('/path');
95-
}
96-
97-
public function testPost()
98-
{
99-
$mockClient = m::mock(HttpClient::class);
100-
$mockFactory = m::mock(RequestFactory::class);
101-
$client = new Client($mockClient, $mockFactory);
102-
103-
$request = new Request('POST', '/path', [], 'a=b');
104-
105-
$mockFactory->shouldReceive('createRequest')->withArgs([
106-
'POST',
107-
'/path',
108-
[],
109-
'a=b',
110-
'1.1',
111-
])->andReturn($request);
112-
113-
$mockClient->shouldReceive('sendRequest')->with($request)->once();
114-
115-
$client->post('/path', [], ['a' => 'b']);
51+
$client->request('GET', '/path');
11652
}
11753
}

0 commit comments

Comments
 (0)