Skip to content

Commit 178734f

Browse files
committed
Merge branch 'hotfix/1.1.2'
* hotfix/1.1.2: Request content was not set when a json was provided
2 parents af74300 + 7cf538e commit 178734f

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

55

6+
## 1.1.2 / 2018-06-18
7+
8+
### Fixed:
9+
- Request content was not set when a json was provided (issue #74)
10+
11+
12+
613
## 1.1.1 / 2018-06-11
714

815
### Fixed:

lib/Bitbucket/API/Http/Client.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Client extends ClientListener implements ClientInterface
3232
'api_versions' => array('1.0', '2.0'), // supported versions
3333
'format' => 'json',
3434
'formats' => array('json', 'xml'), // supported response formats
35-
'user_agent' => 'bitbucket-api-php/1.1.1 (https://bitbucket.org/gentlero/bitbucket-api)',
35+
'user_agent' => 'bitbucket-api-php/1.1.2 (https://bitbucket.org/gentlero/bitbucket-api)',
3636
'timeout' => 10,
3737
'verify_peer' => true
3838
);
@@ -134,6 +134,10 @@ public function request($endpoint, $params = array(), $method = 'GET', array $he
134134
$request->setContent($paramsString);
135135
}
136136

137+
if (is_string($params) && $params !== null) {
138+
$request->setContent($params);
139+
}
140+
137141
$response = is_object($this->responseObj) ? $this->responseObj : new Response();
138142

139143
$this->executeListeners($request, 'preSend');

test/Bitbucket/Tests/API/Http/ClientTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,26 @@ public function testShouldDoPostRequestWithContentAndReturnResponseInstance()
101101
);
102102
}
103103

104+
/**
105+
* @ticket 74
106+
*/
107+
public function testShouldDoPostRequestWithJsonContentAndReturnResponseInstance()
108+
{
109+
$endpoint = 'repositories/gentle/eof/pullrequests';
110+
$params = json_encode(array('1' => '2', 'name' => 'john'));
111+
$headers = array('Content-Type' => 'application/json');
112+
$baseClient = $this->getBrowserMock();
113+
$client = new Client(array('user_agent' => 'tests'), $baseClient);
114+
$response = $client->post($endpoint, $params, $headers);
115+
116+
$this->assertInstanceOf('\Buzz\Message\MessageInterface', $response);
117+
$this->assertEquals($params, $client->getLastRequest()->getContent());
118+
$this->assertEquals(
119+
array('User-Agent: tests', 'Content-Type: application/json'),
120+
$client->getLastRequest()->getHeaders()
121+
);
122+
}
123+
104124
public function testShouldDoPutRequestAndReturnResponseInstance()
105125
{
106126
$endpoint = 'repositories/gentle/eof/issues/3';

0 commit comments

Comments
 (0)