Skip to content

Commit 7e26135

Browse files
committed
Deprecate getLastResponse... methods in Client classes
1 parent acb5589 commit 7e26135

File tree

5 files changed

+192
-0
lines changed

5 files changed

+192
-0
lines changed

src/Redmine/Client/Client.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,25 @@ public function requestDelete(string $path): bool;
4848

4949
/**
5050
* Returns status code of the last response.
51+
*
52+
* @deprecated v2.8.0 Use `\Redmine\Api\AbstractApi::getLastResponse()` instead
53+
* @see \Redmine\Api\AbstractApi::getLastResponse()
5154
*/
5255
public function getLastResponseStatusCode(): int;
5356

5457
/**
5558
* Returns content type of the last response.
59+
*
60+
* @deprecated v2.8.0 Use `\Redmine\Api\AbstractApi::getLastResponse()` instead
61+
* @see \Redmine\Api\AbstractApi::getLastResponse()
5662
*/
5763
public function getLastResponseContentType(): string;
5864

5965
/**
6066
* Returns the body of the last response.
67+
*
68+
* @deprecated v2.8.0 Use `\Redmine\Api\AbstractApi::getLastResponse()` instead
69+
* @see \Redmine\Api\AbstractApi::getLastResponse()
6170
*/
6271
public function getLastResponseBody(): string;
6372
}

src/Redmine/Client/NativeCurlClient.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,25 +143,40 @@ public function requestDelete(string $path): bool
143143

144144
/**
145145
* Returns status code of the last response.
146+
*
147+
* @deprecated v2.8.0 Use `\Redmine\Api\AbstractApi::getLastResponse()` instead
148+
* @see \Redmine\Api\AbstractApi::getLastResponse()
146149
*/
147150
public function getLastResponseStatusCode(): int
148151
{
152+
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.8.0, use `\Redmine\Api\AbstractApi::getLastResponse()` instead.', E_USER_DEPRECATED);
153+
149154
return $this->lastResponseStatusCode;
150155
}
151156

152157
/**
153158
* Returns content type of the last response.
159+
*
160+
* @deprecated v2.8.0 Use `\Redmine\Api\AbstractApi::getLastResponse()` instead
161+
* @see \Redmine\Api\AbstractApi::getLastResponse()
154162
*/
155163
public function getLastResponseContentType(): string
156164
{
165+
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.8.0, use `\Redmine\Api\AbstractApi::getLastResponse()` instead.', E_USER_DEPRECATED);
166+
157167
return $this->lastResponseContentType;
158168
}
159169

160170
/**
161171
* Returns the body of the last response.
172+
*
173+
* @deprecated v2.8.0 Use `\Redmine\Api\AbstractApi::getLastResponse()` instead
174+
* @see \Redmine\Api\AbstractApi::getLastResponse()
162175
*/
163176
public function getLastResponseBody(): string
164177
{
178+
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.8.0, use `\Redmine\Api\AbstractApi::getLastResponse()` instead.', E_USER_DEPRECATED);
179+
165180
return $this->lastResponseBody;
166181
}
167182

src/Redmine/Client/Psr18Client.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,14 @@ public function requestDelete(string $path): bool
173173

174174
/**
175175
* Returns status code of the last response.
176+
*
177+
* @deprecated v2.8.0 Use `\Redmine\Api\AbstractApi::getLastResponse()` instead
178+
* @see \Redmine\Api\AbstractApi::getLastResponse()
176179
*/
177180
public function getLastResponseStatusCode(): int
178181
{
182+
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.8.0, use `\Redmine\Api\AbstractApi::getLastResponse()` instead.', E_USER_DEPRECATED);
183+
179184
if (null === $this->lastResponse) {
180185
return 0;
181186
}
@@ -185,9 +190,14 @@ public function getLastResponseStatusCode(): int
185190

186191
/**
187192
* Returns content type of the last response.
193+
*
194+
* @deprecated v2.8.0 Use `\Redmine\Api\AbstractApi::getLastResponse()` instead
195+
* @see \Redmine\Api\AbstractApi::getLastResponse()
188196
*/
189197
public function getLastResponseContentType(): string
190198
{
199+
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.8.0, use `\Redmine\Api\AbstractApi::getLastResponse()` instead.', E_USER_DEPRECATED);
200+
191201
if (null === $this->lastResponse) {
192202
return '';
193203
}
@@ -197,9 +207,14 @@ public function getLastResponseContentType(): string
197207

198208
/**
199209
* Returns the body of the last response.
210+
*
211+
* @deprecated v2.8.0 Use `\Redmine\Api\AbstractApi::getLastResponse()` instead
212+
* @see \Redmine\Api\AbstractApi::getLastResponse()
200213
*/
201214
public function getLastResponseBody(): string
202215
{
216+
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.8.0, use `\Redmine\Api\AbstractApi::getLastResponse()` instead.', E_USER_DEPRECATED);
217+
203218
if (null === $this->lastResponse) {
204219
return '';
205220
}

tests/Unit/Client/NativeCurlClientTest.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,30 @@ public function testGetLastResponseStatusCodeIsInitialNull(): void
6969
$this->assertSame(0, $client->getLastResponseStatusCode());
7070
}
7171

72+
public function testGetLastResponseStatusCodeTriggersDeprecationWarning(): void
73+
{
74+
$client = new NativeCurlClient(
75+
'http://test.local',
76+
'access_token',
77+
);
78+
79+
// PHPUnit 10 compatible way to test trigger_error().
80+
set_error_handler(
81+
function ($errno, $errstr): bool {
82+
$this->assertSame(
83+
'`Redmine\Client\NativeCurlClient::getLastResponseStatusCode()` is deprecated since v2.8.0, use `\Redmine\Api\AbstractApi::getLastResponse()` instead.',
84+
$errstr,
85+
);
86+
87+
restore_error_handler();
88+
return true;
89+
},
90+
E_USER_DEPRECATED,
91+
);
92+
93+
$client->getLastResponseStatusCode();
94+
}
95+
7296
public function testGetLastResponseContentTypeIsInitialEmpty(): void
7397
{
7498
$client = new NativeCurlClient(
@@ -79,6 +103,30 @@ public function testGetLastResponseContentTypeIsInitialEmpty(): void
79103
$this->assertSame('', $client->getLastResponseContentType());
80104
}
81105

106+
public function testGetLastResponseContentTypeTriggersDeprecationWarning(): void
107+
{
108+
$client = new NativeCurlClient(
109+
'http://test.local',
110+
'access_token',
111+
);
112+
113+
// PHPUnit 10 compatible way to test trigger_error().
114+
set_error_handler(
115+
function ($errno, $errstr): bool {
116+
$this->assertSame(
117+
'`Redmine\Client\NativeCurlClient::getLastResponseContentType()` is deprecated since v2.8.0, use `\Redmine\Api\AbstractApi::getLastResponse()` instead.',
118+
$errstr,
119+
);
120+
121+
restore_error_handler();
122+
return true;
123+
},
124+
E_USER_DEPRECATED,
125+
);
126+
127+
$client->getLastResponseContentType();
128+
}
129+
82130
public function testGetLastResponseBodyIsInitialEmpty(): void
83131
{
84132
$client = new NativeCurlClient(
@@ -89,6 +137,30 @@ public function testGetLastResponseBodyIsInitialEmpty(): void
89137
$this->assertSame('', $client->getLastResponseBody());
90138
}
91139

140+
public function testGetLastResponseBodyTriggersDeprecationWarning(): void
141+
{
142+
$client = new NativeCurlClient(
143+
'http://test.local',
144+
'access_token',
145+
);
146+
147+
// PHPUnit 10 compatible way to test trigger_error().
148+
set_error_handler(
149+
function ($errno, $errstr): bool {
150+
$this->assertSame(
151+
'`Redmine\Client\NativeCurlClient::getLastResponseBody()` is deprecated since v2.8.0, use `\Redmine\Api\AbstractApi::getLastResponse()` instead.',
152+
$errstr,
153+
);
154+
155+
restore_error_handler();
156+
return true;
157+
},
158+
E_USER_DEPRECATED,
159+
);
160+
161+
$client->getLastResponseBody();
162+
}
163+
92164
public function testStartAndStopImpersonateUser(): void
93165
{
94166
$expectedOptions = [

tests/Unit/Client/Psr18ClientTest.php

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,33 @@ public function testGetLastResponseStatusCodeIsInitialZero(): void
9090
$this->assertSame(0, $client->getLastResponseStatusCode());
9191
}
9292

93+
public function testGetLastResponseStatusCodeTriggersDeprecationWarning(): void
94+
{
95+
$client = new Psr18Client(
96+
$this->createMock(ClientInterface::class),
97+
$this->createMock(RequestFactoryInterface::class),
98+
$this->createMock(StreamFactoryInterface::class),
99+
'http://test.local',
100+
'access_token',
101+
);
102+
103+
// PHPUnit 10 compatible way to test trigger_error().
104+
set_error_handler(
105+
function ($errno, $errstr): bool {
106+
$this->assertSame(
107+
'`Redmine\Client\Psr18Client::getLastResponseStatusCode()` is deprecated since v2.8.0, use `\Redmine\Api\AbstractApi::getLastResponse()` instead.',
108+
$errstr,
109+
);
110+
111+
restore_error_handler();
112+
return true;
113+
},
114+
E_USER_DEPRECATED,
115+
);
116+
117+
$client->getLastResponseStatusCode();
118+
}
119+
93120
public function testGetLastResponseContentTypeIsInitialEmpty(): void
94121
{
95122
$client = new Psr18Client(
@@ -103,6 +130,33 @@ public function testGetLastResponseContentTypeIsInitialEmpty(): void
103130
$this->assertSame('', $client->getLastResponseContentType());
104131
}
105132

133+
public function testGetLastResponseContentTypeTriggersDeprecationWarning(): void
134+
{
135+
$client = new Psr18Client(
136+
$this->createMock(ClientInterface::class),
137+
$this->createMock(RequestFactoryInterface::class),
138+
$this->createMock(StreamFactoryInterface::class),
139+
'http://test.local',
140+
'access_token',
141+
);
142+
143+
// PHPUnit 10 compatible way to test trigger_error().
144+
set_error_handler(
145+
function ($errno, $errstr): bool {
146+
$this->assertSame(
147+
'`Redmine\Client\Psr18Client::getLastResponseContentType()` is deprecated since v2.8.0, use `\Redmine\Api\AbstractApi::getLastResponse()` instead.',
148+
$errstr,
149+
);
150+
151+
restore_error_handler();
152+
return true;
153+
},
154+
E_USER_DEPRECATED,
155+
);
156+
157+
$client->getLastResponseContentType();
158+
}
159+
106160
public function testGetLastResponseBodyIsInitialEmpty(): void
107161
{
108162
$client = new Psr18Client(
@@ -116,6 +170,33 @@ public function testGetLastResponseBodyIsInitialEmpty(): void
116170
$this->assertSame('', $client->getLastResponseBody());
117171
}
118172

173+
public function testGetLastResponseBodyTriggersDeprecationWarning(): void
174+
{
175+
$client = new Psr18Client(
176+
$this->createMock(ClientInterface::class),
177+
$this->createMock(RequestFactoryInterface::class),
178+
$this->createMock(StreamFactoryInterface::class),
179+
'http://test.local',
180+
'access_token',
181+
);
182+
183+
// PHPUnit 10 compatible way to test trigger_error().
184+
set_error_handler(
185+
function ($errno, $errstr): bool {
186+
$this->assertSame(
187+
'`Redmine\Client\Psr18Client::getLastResponseBody()` is deprecated since v2.8.0, use `\Redmine\Api\AbstractApi::getLastResponse()` instead.',
188+
$errstr,
189+
);
190+
191+
restore_error_handler();
192+
return true;
193+
},
194+
E_USER_DEPRECATED,
195+
);
196+
197+
$client->getLastResponseBody();
198+
}
199+
119200
public function testStartAndStopImpersonateUser(): void
120201
{
121202
$request = $this->createMock(RequestInterface::class);

0 commit comments

Comments
 (0)