Skip to content

Commit c516448

Browse files
committed
Deprecate AbstractApi::post()
1 parent 9b03c9d commit c516448

File tree

3 files changed

+43
-6
lines changed

3 files changed

+43
-6
lines changed

CHANGELOG.md

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

2929
- `Redmine\Api\AbstractApi::get()` is deprecated, use `\Redmine\Http\HttpClient::request()` instead.
30+
- `Redmine\Api\AbstractApi::post()` is deprecated, use `\Redmine\Http\HttpClient::request()` instead.
3031

3132
## [v2.5.0](https://github.com/kbsali/php-redmine-api/compare/v2.4.0...v2.5.0) - 2024-02-05
3233

src/Redmine/Api/AbstractApi.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Redmine\Api;
44

5-
use Closure;
65
use InvalidArgumentException;
76
use Redmine\Api;
87
use Redmine\Client\Client;
@@ -142,13 +141,17 @@ protected function get($path, $decodeIfJson = true)
142141
/**
143142
* Perform the client post() method.
144143
*
144+
* @deprecated since v2.6.0, use `\Redmine\Http\HttpClient::request()` instead
145+
*
145146
* @param string $path
146147
* @param string $data
147148
*
148149
* @return string|SimpleXMLElement|false
149150
*/
150151
protected function post($path, $data)
151152
{
153+
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.6.0, use `\Redmine\Http\HttpClient::request()` instead.', E_USER_DEPRECATED);
154+
152155
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeRequest(
153156
'POST',
154157
strval($path),

tests/Unit/Api/AbstractApiTest.php

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,12 @@ public function testGetTriggersDeprecationWarning()
5858
{
5959
$client = $this->createMock(HttpClient::class);
6060

61-
$api = new class ($client) extends AbstractApi {};
61+
$api = new class ($client) extends AbstractApi {
62+
public function runGet($path)
63+
{
64+
return $this->get($path);
65+
}
66+
};
6267

6368
// PHPUnit 10 compatible way to test trigger_error().
6469
set_error_handler(
@@ -74,10 +79,7 @@ function ($errno, $errstr): bool {
7479
E_USER_DEPRECATED
7580
);
7681

77-
$method = new ReflectionMethod($api, 'get');
78-
$method->setAccessible(true);
79-
80-
$method->invoke($api, '/path.json');
82+
$api->runGet('/path.json');
8183
}
8284

8385
/**
@@ -92,6 +94,37 @@ public function testGetLastResponseWithHttpClientWorks()
9294
$this->assertInstanceOf(Response::class, $api->getLastResponse());
9395
}
9496

97+
/**
98+
* @covers ::post
99+
*/
100+
public function testPostTriggersDeprecationWarning()
101+
{
102+
$client = $this->createMock(HttpClient::class);
103+
104+
$api = new class ($client) extends AbstractApi {
105+
public function runPost($path, $data)
106+
{
107+
return $this->post($path, $data);
108+
}
109+
};
110+
111+
// PHPUnit 10 compatible way to test trigger_error().
112+
set_error_handler(
113+
function ($errno, $errstr): bool {
114+
$this->assertSame(
115+
'`Redmine\Api\AbstractApi::post()` is deprecated since v2.6.0, use `\Redmine\Http\HttpClient::request()` instead.',
116+
$errstr
117+
);
118+
119+
restore_error_handler();
120+
return true;
121+
},
122+
E_USER_DEPRECATED
123+
);
124+
125+
$api->runPost('/path.json', 'data');
126+
}
127+
95128
/**
96129
* @test
97130
* @dataProvider getIsNotNullReturnsCorrectBooleanData

0 commit comments

Comments
 (0)