Skip to content

Commit

Permalink
Deprecate AbstractApi::post()
Browse files Browse the repository at this point in the history
  • Loading branch information
Art4 committed Feb 26, 2024
1 parent 9b03c9d commit c516448
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Deprecated

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

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

Expand Down
5 changes: 4 additions & 1 deletion src/Redmine/Api/AbstractApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Redmine\Api;

use Closure;
use InvalidArgumentException;
use Redmine\Api;
use Redmine\Client\Client;
Expand Down Expand Up @@ -142,13 +141,17 @@ protected function get($path, $decodeIfJson = true)
/**
* Perform the client post() method.
*
* @deprecated since v2.6.0, use `\Redmine\Http\HttpClient::request()` instead
*
* @param string $path
* @param string $data
*
* @return string|SimpleXMLElement|false
*/
protected function post($path, $data)
{
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.6.0, use `\Redmine\Http\HttpClient::request()` instead.', E_USER_DEPRECATED);

$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeRequest(
'POST',
strval($path),
Expand Down
43 changes: 38 additions & 5 deletions tests/Unit/Api/AbstractApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ public function testGetTriggersDeprecationWarning()
{
$client = $this->createMock(HttpClient::class);

$api = new class ($client) extends AbstractApi {};
$api = new class ($client) extends AbstractApi {
public function runGet($path)
{
return $this->get($path);
}
};

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

$method = new ReflectionMethod($api, 'get');
$method->setAccessible(true);

$method->invoke($api, '/path.json');
$api->runGet('/path.json');
}

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

/**
* @covers ::post
*/
public function testPostTriggersDeprecationWarning()
{
$client = $this->createMock(HttpClient::class);

$api = new class ($client) extends AbstractApi {
public function runPost($path, $data)
{
return $this->post($path, $data);
}
};

// PHPUnit 10 compatible way to test trigger_error().
set_error_handler(
function ($errno, $errstr): bool {
$this->assertSame(
'`Redmine\Api\AbstractApi::post()` is deprecated since v2.6.0, use `\Redmine\Http\HttpClient::request()` instead.',
$errstr
);

restore_error_handler();
return true;
},
E_USER_DEPRECATED
);

$api->runPost('/path.json', 'data');
}

/**
* @test
* @dataProvider getIsNotNullReturnsCorrectBooleanData
Expand Down

0 comments on commit c516448

Please sign in to comment.