Skip to content

Commit 0d4a81a

Browse files
committed
fix: correct BC guard in Issue::create(), IssueCategory::create(), Membership::create()
1 parent 48f500e commit 0d4a81a

6 files changed

Lines changed: 69 additions & 3 deletions

File tree

src/Redmine/Api/Issue.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ public function create(array $params = [])
258258
$body = $this->lastResponse->getContent();
259259

260260
if ($this->lastResponse->getStatusCode() !== 201) {
261-
if (!Future::isForwardCompatibilityEnabled() && $body === '') {
261+
if (!Future::isForwardCompatibilityEnabled()) {
262262
return $body;
263263
}
264264

src/Redmine/Api/IssueCategory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ public function create($project, array $params = [])
269269
$body = $this->lastResponse->getContent();
270270

271271
if ($this->lastResponse->getStatusCode() !== 201) {
272-
if (!Future::isForwardCompatibilityEnabled() && $body === '') {
272+
if (!Future::isForwardCompatibilityEnabled()) {
273273
return $body;
274274
}
275275

src/Redmine/Api/Membership.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public function create($project, array $params = [])
151151
$body = $this->lastResponse->getContent();
152152

153153
if ($this->lastResponse->getStatusCode() !== 201) {
154-
if (!Future::isForwardCompatibilityEnabled() && $body === '') {
154+
if (!Future::isForwardCompatibilityEnabled()) {
155155
return $body;
156156
}
157157

tests/Unit/Api/Issue/CreateTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,28 @@ public function testCreateWithIncorrectStatusCodeReturnsEmptyString(): void
265265
$this->assertSame('', $return);
266266
}
267267

268+
public function testCreateWithIncorrectStatusCodeReturnsBody(): void
269+
{
270+
$client = AssertingHttpClient::create(
271+
$this,
272+
[
273+
'POST',
274+
'/issues.xml',
275+
'application/xml',
276+
'<?xml version="1.0" encoding="UTF-8"?><issue/>',
277+
500,
278+
'',
279+
'<error>error</error>',
280+
],
281+
);
282+
283+
$api = Issue::fromHttpClient($client);
284+
285+
$return = $api->create([]);
286+
287+
$this->assertSame('<error>error</error>', $return);
288+
}
289+
268290
public function testCreateWithIncorrectStatusCodeThrowsException(): void
269291
{
270292
$client = AssertingHttpClient::create(

tests/Unit/Api/IssueCategory/CreateTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,28 @@ public function testCreateReturnsEmptyString(): void
107107
$this->assertSame('', $return);
108108
}
109109

110+
public function testCreateWithIncorrectStatusCodeReturnsBody(): void
111+
{
112+
$client = AssertingHttpClient::create(
113+
$this,
114+
[
115+
'POST',
116+
'/projects/5/issue_categories.xml',
117+
'application/xml',
118+
'<?xml version="1.0" encoding="UTF-8"?><issue_category><name>Test Category</name></issue_category>',
119+
500,
120+
'',
121+
'<error>error</error>',
122+
],
123+
);
124+
125+
$api = IssueCategory::fromHttpClient($client);
126+
127+
$return = $api->create(5, ['name' => 'Test Category']);
128+
129+
$this->assertSame('<error>error</error>', $return);
130+
}
131+
110132
public function testCreateWithIncorrectStatusCodeThrowsException(): void
111133
{
112134
$client = AssertingHttpClient::create(

tests/Unit/Api/Membership/CreateTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,28 @@ public function testCreateReturnsEmptyString(): void
9898
$this->assertSame('', $return);
9999
}
100100

101+
public function testCreateWithIncorrectStatusCodeReturnsBody(): void
102+
{
103+
$client = AssertingHttpClient::create(
104+
$this,
105+
[
106+
'POST',
107+
'/projects/5/memberships.xml',
108+
'application/xml',
109+
'<?xml version="1.0" encoding="UTF-8"?><membership><user_id>4</user_id><role_ids>2</role_ids></membership>',
110+
500,
111+
'',
112+
'<error>error</error>',
113+
],
114+
);
115+
116+
$api = Membership::fromHttpClient($client);
117+
118+
$return = $api->create(5, ['user_id' => 4, 'role_ids' => 2]);
119+
120+
$this->assertSame('<error>error</error>', $return);
121+
}
122+
101123
public function testCreateThrowsExceptionWithEmptyParameters(): void
102124
{
103125
$client = $this->createStub(HttpClient::class);

0 commit comments

Comments
 (0)