File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -250,6 +250,17 @@ public function remove($id)
250250 '/time_entries/ ' . $ id . '.xml ' ,
251251 ));
252252
253- return $ this ->lastResponse ->getContent ();
253+ $ body = $ this ->lastResponse ->getContent ();
254+ $ statusCode = $ this ->lastResponse ->getStatusCode ();
255+
256+ if ($ statusCode !== 200 && $ statusCode !== 204 ) {
257+ if (!Future::isForwardCompatibilityEnabled ()) {
258+ return $ body ;
259+ }
260+
261+ throw UnexpectedResponseException::create ($ this ->lastResponse );
262+ }
263+
264+ return $ body ;
254265 }
255266}
Original file line number Diff line number Diff line change 88use PHPUnit \Framework \Attributes \DataProvider ;
99use PHPUnit \Framework \TestCase ;
1010use Redmine \Api \TimeEntry ;
11+ use Redmine \Exception \UnexpectedResponseException ;
12+ use Redmine \Future ;
1113use Redmine \Tests \Fixtures \AssertingHttpClient ;
1214
1315#[CoversClass(TimeEntry::class)]
@@ -53,4 +55,52 @@ public static function getRemoveData(): array
5355 ],
5456 ];
5557 }
58+
59+ public function testRemoveWithIncorrectStatusCodeReturnsBody (): void
60+ {
61+ $ client = AssertingHttpClient::create (
62+ $ this ,
63+ [
64+ 'DELETE ' ,
65+ '/time_entries/5.xml ' ,
66+ 'application/xml ' ,
67+ '' ,
68+ 500 ,
69+ '' ,
70+ '' ,
71+ ],
72+ );
73+
74+ $ api = TimeEntry::fromHttpClient ($ client );
75+
76+ $ this ->assertSame ('' , $ api ->remove (5 ));
77+ }
78+
79+ public function testRemoveWithIncorrectStatusCodeThrowsException (): void
80+ {
81+ $ client = AssertingHttpClient::create (
82+ $ this ,
83+ [
84+ 'DELETE ' ,
85+ '/time_entries/5.xml ' ,
86+ 'application/xml ' ,
87+ '' ,
88+ 500 ,
89+ '' ,
90+ '' ,
91+ ],
92+ );
93+
94+ $ api = TimeEntry::fromHttpClient ($ client );
95+
96+ $ this ->expectException (UnexpectedResponseException::class);
97+
98+ try {
99+ Future::enableForwardCompatibility ();
100+
101+ $ api ->remove (5 );
102+ } finally {
103+ Future::disableForwardCompatibility ();
104+ }
105+ }
56106}
You can’t perform that action at this time.
0 commit comments