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
@@ -232,7 +234,7 @@ public static function getCreateData(): array
232234 ];
233235 }
234236
235- public function testCreateReturnsEmptyString (): void
237+ public function testCreateWithIncorrectStatusCodeReturnsEmptyString (): void
236238 {
237239 $ client = AssertingHttpClient::create (
238240 $ this ,
@@ -256,6 +258,35 @@ public function testCreateReturnsEmptyString(): void
256258 $ this ->assertSame ('' , $ return );
257259 }
258260
261+ public function testCreateWithIncorrectStatusCodeThrowsException (): void
262+ {
263+ $ client = AssertingHttpClient::create (
264+ $ this ,
265+ [
266+ 'POST ' ,
267+ '/issues.xml ' ,
268+ 'application/xml ' ,
269+ '<?xml version="1.0" encoding="UTF-8"?><issue/> ' ,
270+ 500 ,
271+ '' ,
272+ '' ,
273+ ],
274+ );
275+
276+ // Create the object under test
277+ $ api = Issue::fromHttpClient ($ client );
278+
279+ $ this ->expectException (UnexpectedResponseException::class);
280+
281+ try {
282+ Future::enableForwardCompatibility ();
283+
284+ $ api ->create ([]);
285+ } finally {
286+ Future::disableForwardCompatibility ();
287+ }
288+ }
289+
259290 public function testCreateWithHttpClientRetrievesIssueStatusId (): void
260291 {
261292 $ client = AssertingHttpClient::create (
@@ -274,7 +305,7 @@ public function testCreateWithHttpClientRetrievesIssueStatusId(): void
274305 '/issues.xml ' ,
275306 'application/xml ' ,
276307 '<?xml version="1.0"?><issue><status_id>123</status_id></issue> ' ,
277- 200 ,
308+ 201 ,
278309 'application/xml ' ,
279310 '<?xml version="1.0"?><issue></issue> ' ,
280311 ],
@@ -311,7 +342,7 @@ public function testCreateWithHttpClientRetrievesProjectId(): void
311342 '/issues.xml ' ,
312343 'application/xml ' ,
313344 '<?xml version="1.0"?><issue><project_id>3</project_id></issue> ' ,
314- 200 ,
345+ 201 ,
315346 'application/xml ' ,
316347 '<?xml version="1.0"?><issue></issue> ' ,
317348 ],
@@ -348,7 +379,7 @@ public function testCreateWithHttpClientRetrievesIssueCategoryId(): void
348379 '/issues.xml ' ,
349380 'application/xml ' ,
350381 '<?xml version="1.0"?><issue><project_id>3</project_id><category_id>45</category_id></issue> ' ,
351- 200 ,
382+ 201 ,
352383 'application/xml ' ,
353384 '<?xml version="1.0"?><issue></issue> ' ,
354385 ],
@@ -385,7 +416,7 @@ public function testCreateWithHttpClientRetrievesTrackerId(): void
385416 '/issues.xml ' ,
386417 'application/xml ' ,
387418 '<?xml version="1.0"?><issue><tracker_id>9</tracker_id></issue> ' ,
388- 200 ,
419+ 201 ,
389420 'application/xml ' ,
390421 '<?xml version="1.0"?><issue></issue> ' ,
391422 ],
@@ -422,7 +453,7 @@ public function testCreateWithHttpClientRetrievesUserId(): void
422453 '/issues.xml ' ,
423454 'application/xml ' ,
424455 '<?xml version="1.0"?><issue><assigned_to_id>6</assigned_to_id><author_id>5</author_id></issue> ' ,
425- 200 ,
456+ 201 ,
426457 'application/xml ' ,
427458 '<?xml version="1.0"?><issue></issue> ' ,
428459 ],
@@ -508,7 +539,7 @@ public function testCreateWithClientCleansParameters(): void
508539 <author_id>5</author_id>
509540 </issue>
510541 XML ,
511- 200 ,
542+ 201 ,
512543 'application/xml ' ,
513544 '<?xml version="1.0"?><issue></issue> ' ,
514545 ],
0 commit comments