88use PHPUnit \Framework \Attributes \DataProvider ;
99use PHPUnit \Framework \TestCase ;
1010use Redmine \Api \Issue ;
11+ use Redmine \Exception \UnexpectedResponseException ;
12+ use Redmine \Future ;
1113use Redmine \Tests \Fixtures \AssertingHttpClient ;
1214use SimpleXMLElement ;
1315
@@ -239,7 +241,7 @@ public static function getCreateData(): array
239241 ];
240242 }
241243
242- public function testCreateReturnsEmptyString (): void
244+ public function testCreateWithIncorrectStatusCodeReturnsEmptyString (): void
243245 {
244246 $ client = AssertingHttpClient::create (
245247 $ this ,
@@ -263,6 +265,35 @@ public function testCreateReturnsEmptyString(): void
263265 $ this ->assertSame ('' , $ return );
264266 }
265267
268+ public function testCreateWithIncorrectStatusCodeThrowsException (): 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+ '' ,
280+ ],
281+ );
282+
283+ // Create the object under test
284+ $ api = Issue::fromHttpClient ($ client );
285+
286+ $ this ->expectException (UnexpectedResponseException::class);
287+
288+ try {
289+ Future::enableForwardCompatibility ();
290+
291+ $ api ->create ([]);
292+ } finally {
293+ Future::disableForwardCompatibility ();
294+ }
295+ }
296+
266297 public function testCreateWithHttpClientRetrievesIssueStatusId (): void
267298 {
268299 $ client = AssertingHttpClient::create (
@@ -281,7 +312,7 @@ public function testCreateWithHttpClientRetrievesIssueStatusId(): void
281312 '/issues.xml ' ,
282313 'application/xml ' ,
283314 '<?xml version="1.0"?><issue><status_id>123</status_id></issue> ' ,
284- 200 ,
315+ 201 ,
285316 'application/xml ' ,
286317 '<?xml version="1.0"?><issue></issue> ' ,
287318 ],
@@ -318,7 +349,7 @@ public function testCreateWithHttpClientRetrievesProjectId(): void
318349 '/issues.xml ' ,
319350 'application/xml ' ,
320351 '<?xml version="1.0"?><issue><project_id>3</project_id></issue> ' ,
321- 200 ,
352+ 201 ,
322353 'application/xml ' ,
323354 '<?xml version="1.0"?><issue></issue> ' ,
324355 ],
@@ -355,7 +386,7 @@ public function testCreateWithHttpClientRetrievesIssueCategoryId(): void
355386 '/issues.xml ' ,
356387 'application/xml ' ,
357388 '<?xml version="1.0"?><issue><project_id>3</project_id><category_id>45</category_id></issue> ' ,
358- 200 ,
389+ 201 ,
359390 'application/xml ' ,
360391 '<?xml version="1.0"?><issue></issue> ' ,
361392 ],
@@ -392,7 +423,7 @@ public function testCreateWithHttpClientRetrievesTrackerId(): void
392423 '/issues.xml ' ,
393424 'application/xml ' ,
394425 '<?xml version="1.0"?><issue><tracker_id>9</tracker_id></issue> ' ,
395- 200 ,
426+ 201 ,
396427 'application/xml ' ,
397428 '<?xml version="1.0"?><issue></issue> ' ,
398429 ],
@@ -429,7 +460,7 @@ public function testCreateWithHttpClientRetrievesUserId(): void
429460 '/issues.xml ' ,
430461 'application/xml ' ,
431462 '<?xml version="1.0"?><issue><assigned_to_id>6</assigned_to_id><author_id>5</author_id></issue> ' ,
432- 200 ,
463+ 201 ,
433464 'application/xml ' ,
434465 '<?xml version="1.0"?><issue></issue> ' ,
435466 ],
@@ -515,7 +546,7 @@ public function testCreateWithClientCleansParameters(): void
515546 <author_id>5</author_id>
516547 </issue>
517548 XML ,
518- 200 ,
549+ 201 ,
519550 'application/xml ' ,
520551 '<?xml version="1.0"?><issue></issue> ' ,
521552 ],
0 commit comments