Skip to content

Commit 036d62a

Browse files
committed
Deprecate AbstractApi::put()
1 parent c09823a commit 036d62a

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2828

2929
- `Redmine\Api\AbstractApi::get()` is deprecated, use `\Redmine\Http\HttpClient::request()` instead.
3030
- `Redmine\Api\AbstractApi::post()` is deprecated, use `\Redmine\Http\HttpClient::request()` instead.
31+
- `Redmine\Api\AbstractApi::put()` is deprecated, use `\Redmine\Http\HttpClient::request()` instead.
3132
- The constant `Redmine\Api\Issue::PRIO_LOW` is deprecated.
3233
- The constant `Redmine\Api\Issue::PRIO_NORMAL` is deprecated.
3334
- The constant `Redmine\Api\Issue::PRIO_HIGH` is deprecated.

src/Redmine/Api/AbstractApi.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,18 @@ protected function post($path, $data)
175175
/**
176176
* Perform the client put() method.
177177
*
178+
* @deprecated v2.6.0 Use `\Redmine\Http\HttpClient::request()` instead
179+
* @see \Redmine\Http\HttpClient::request()
180+
*
178181
* @param string $path
179182
* @param string $data
180183
*
181184
* @return string|SimpleXMLElement
182185
*/
183186
protected function put($path, $data)
184187
{
188+
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.6.0, use `\Redmine\Http\HttpClient::request()` instead.', E_USER_DEPRECATED);
189+
185190
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeRequest(
186191
'PUT',
187192
strval($path),

tests/Unit/Api/AbstractApiTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,37 @@ function ($errno, $errstr): bool {
125125
$api->runPost('/path.json', 'data');
126126
}
127127

128+
/**
129+
* @covers ::put
130+
*/
131+
public function testPutTriggersDeprecationWarning()
132+
{
133+
$client = $this->createMock(HttpClient::class);
134+
135+
$api = new class ($client) extends AbstractApi {
136+
public function runPut($path, $data)
137+
{
138+
return $this->put($path, $data);
139+
}
140+
};
141+
142+
// PHPUnit 10 compatible way to test trigger_error().
143+
set_error_handler(
144+
function ($errno, $errstr): bool {
145+
$this->assertSame(
146+
'`Redmine\Api\AbstractApi::put()` is deprecated since v2.6.0, use `\Redmine\Http\HttpClient::request()` instead.',
147+
$errstr
148+
);
149+
150+
restore_error_handler();
151+
return true;
152+
},
153+
E_USER_DEPRECATED
154+
);
155+
156+
$api->runPut('/path.json', 'data');
157+
}
158+
128159
/**
129160
* @test
130161
* @dataProvider getIsNotNullReturnsCorrectBooleanData

0 commit comments

Comments
 (0)