Skip to content

Commit 3148df7

Browse files
authored
Merge pull request #3 from francisco-aguilar-olx/master
Add support for PATCH requests
2 parents 956c9b8 + 167daaf commit 3148df7

File tree

5 files changed

+35
-1
lines changed

5 files changed

+35
-1
lines changed

src/HttpClient.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ public function put($uri)
4949
return new FluentRequest('PUT', $uri, $this->client);
5050
}
5151

52+
/**
53+
* @param $uri
54+
* @return FluentRequestInterface
55+
*/
56+
public function patch($uri)
57+
{
58+
return new FluentRequest('PATCH', $uri, $this->client);
59+
}
60+
5261
/**
5362
* @param $uri
5463
* @return FluentRequestInterface

src/HttpClientInterface.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ public function post($uri);
2323
*/
2424
public function put($uri);
2525

26+
/**
27+
* @param $uri
28+
* @return FluentRequestInterface
29+
*/
30+
public function patch($uri);
31+
2632
/**
2733
* @param $uri
2834
* @return FluentRequestInterface

src/Request/RequestExecutor.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public function execute()
5151
case 'PUT':
5252
$requestResponse = $this->getClient()->put($this->uri, $this->options);
5353
break;
54+
case 'PATCH':
55+
$requestResponse = $this->getClient()->patch($this->uri, $this->options);
56+
break;
5457
case 'DELETE':
5558
$requestResponse = $this->getClient()->delete($this->uri, $this->options);
5659
break;

tests/HttpClientTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ public function testPutMethodIsCalledShouldReturnFluentRequestWithHTTPPutMethod(
3636
$this->assertAttributeEquals('http://www.olx.com', 'uri', $requestObj);
3737
}
3838

39+
public function testPatchMethodIsCalledShouldReturnFluentRequestWithHTTPPatchMethod()
40+
{
41+
$requestObj = $this->httpClient->patch('http://www.olx.com');
42+
43+
$this->assertAttributeEquals('PATCH', 'method', $requestObj);
44+
$this->assertAttributeEquals('http://www.olx.com', 'uri', $requestObj);
45+
}
46+
3947
public function testDeleteMethodIsCalledShouldReturnFluentRequestWithHTTPDeleteMethod()
4048
{
4149
$requestObj = $this->httpClient->delete('http://www.olx.com');

tests/Request/RequestExecutorTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ public function testExecuteGivenHTTPMethodIsPUT()
2929
$this->assertEquals('put', $executor());
3030
}
3131

32+
public function testExecuteGivenHTTPMethodIsPATCH()
33+
{
34+
$executor = $this->makeRequestExecutorFor('PATCH');
35+
36+
$this->assertEquals('patch', $executor());
37+
}
38+
3239
public function testExecuteGivenHTTPMethodIsDELETE()
3340
{
3441
$executor = $this->makeRequestExecutorFor('DELETE');
@@ -55,12 +62,13 @@ private function makeRequestExecutorFor($method)
5562
{
5663
// set the methods manually, since with >Guzzle 6.0 the client uses __call method which complicates a bit the mocking
5764
$httpClient = $this->getMockBuilder(Client::class)
58-
->setMethods(['get','post','put','delete'])
65+
->setMethods(['get','post','put','patch','delete'])
5966
->getMock();
6067

6168
$httpClient->method('get')->willReturn('get');
6269
$httpClient->method('post')->willReturn('post');
6370
$httpClient->method('put')->willReturn('put');
71+
$httpClient->method('patch')->willReturn('patch');
6472
$httpClient->method('delete')->willReturn('delete');
6573

6674
$requestExecutor = $this->getMockBuilder(RequestExecutor::class)

0 commit comments

Comments
 (0)