66use PHPUnit \Framework \Attributes \DataProvider ;
77use PHPUnit \Framework \TestCase ;
88use Redmine \Api \Issue ;
9+ use Redmine \Exception \UnexpectedResponseException ;
10+ use Redmine \Future ;
911use Redmine \Tests \Fixtures \AssertingHttpClient ;
1012use SimpleXMLElement ;
1113
@@ -237,7 +239,7 @@ public static function getCreateData(): array
237239 ];
238240 }
239241
240- public function testCreateReturnsEmptyString (): void
242+ public function testCreateWithIncorrectStatusCodeReturnsEmptyString (): void
241243 {
242244 $ client = AssertingHttpClient::create (
243245 $ this ,
@@ -261,6 +263,35 @@ public function testCreateReturnsEmptyString(): void
261263 $ this ->assertSame ('' , $ return );
262264 }
263265
266+ public function testCreateWithIncorrectStatusCodeThrowsException (): void
267+ {
268+ $ client = AssertingHttpClient::create (
269+ $ this ,
270+ [
271+ 'POST ' ,
272+ '/issues.xml ' ,
273+ 'application/xml ' ,
274+ '<?xml version="1.0" encoding="UTF-8"?><issue/> ' ,
275+ 500 ,
276+ '' ,
277+ '' ,
278+ ],
279+ );
280+
281+ // Create the object under test
282+ $ api = Issue::fromHttpClient ($ client );
283+
284+ $ this ->expectException (UnexpectedResponseException::class);
285+
286+ try {
287+ Future::enableForwardCompatibility ();
288+
289+ $ api ->create ([]);
290+ } finally {
291+ Future::disableForwardCompatibility ();
292+ }
293+ }
294+
264295 public function testCreateWithHttpClientRetrievesIssueStatusId (): void
265296 {
266297 $ client = AssertingHttpClient::create (
@@ -279,7 +310,7 @@ public function testCreateWithHttpClientRetrievesIssueStatusId(): void
279310 '/issues.xml ' ,
280311 'application/xml ' ,
281312 '<?xml version="1.0"?><issue><status_id>123</status_id></issue> ' ,
282- 200 ,
313+ 201 ,
283314 'application/xml ' ,
284315 '<?xml version="1.0"?><issue></issue> ' ,
285316 ],
@@ -316,7 +347,7 @@ public function testCreateWithHttpClientRetrievesProjectId(): void
316347 '/issues.xml ' ,
317348 'application/xml ' ,
318349 '<?xml version="1.0"?><issue><project_id>3</project_id></issue> ' ,
319- 200 ,
350+ 201 ,
320351 'application/xml ' ,
321352 '<?xml version="1.0"?><issue></issue> ' ,
322353 ],
@@ -353,7 +384,7 @@ public function testCreateWithHttpClientRetrievesIssueCategoryId(): void
353384 '/issues.xml ' ,
354385 'application/xml ' ,
355386 '<?xml version="1.0"?><issue><project_id>3</project_id><category_id>45</category_id></issue> ' ,
356- 200 ,
387+ 201 ,
357388 'application/xml ' ,
358389 '<?xml version="1.0"?><issue></issue> ' ,
359390 ],
@@ -390,7 +421,7 @@ public function testCreateWithHttpClientRetrievesTrackerId(): void
390421 '/issues.xml ' ,
391422 'application/xml ' ,
392423 '<?xml version="1.0"?><issue><tracker_id>9</tracker_id></issue> ' ,
393- 200 ,
424+ 201 ,
394425 'application/xml ' ,
395426 '<?xml version="1.0"?><issue></issue> ' ,
396427 ],
@@ -427,7 +458,7 @@ public function testCreateWithHttpClientRetrievesUserId(): void
427458 '/issues.xml ' ,
428459 'application/xml ' ,
429460 '<?xml version="1.0"?><issue><assigned_to_id>6</assigned_to_id><author_id>5</author_id></issue> ' ,
430- 200 ,
461+ 201 ,
431462 'application/xml ' ,
432463 '<?xml version="1.0"?><issue></issue> ' ,
433464 ],
@@ -513,7 +544,7 @@ public function testCreateWithClientCleansParameters(): void
513544 <author_id>5</author_id>
514545 </issue>
515546 XML ,
516- 200 ,
547+ 201 ,
517548 'application/xml ' ,
518549 '<?xml version="1.0"?><issue></issue> ' ,
519550 ],
0 commit comments