diff --git a/CHANGELOG.md b/CHANGELOG.md index 8eb52de6..263a6661 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - New class `Redmine\Http\HttpFactory` to create `Redmine\Http\Request` and `Redmine\Http\Response` instances. +### Deprecated + +- `Redmine\Client\Client::requestGet()` is deprecated, use `\Redmine\Client\Client::request()` instead. +- `Redmine\Client\Client::requestPost()` is deprecated, use `\Redmine\Client\Client::request()` instead. +- `Redmine\Client\Client::requestPut()` is deprecated, use `\Redmine\Client\Client::request()` instead. +- `Redmine\Client\Client::requestDelete()` is deprecated, use `\Redmine\Client\Client::request()` instead. +- `Redmine\Client\Client::getLastResponseStatusCode()` is deprecated, use `\Redmine\Client\Client::request()` or `\Redmine\Api\AbstractApi::getLastResponse()->getStatusCode()` instead. +- `Redmine\Client\Client::getLastResponseContentType()` is deprecated, use `\Redmine\Client\Client::request()` or `\Redmine\Api\AbstractApi::getLastResponse()->getContentType()` instead. +- `Redmine\Client\Client::getLastResponseBody()` is deprecated, use `\Redmine\Client\Client::request()` or `\Redmine\Api\AbstractApi::getLastResponse()->getContent()` instead. + ## [v2.7.0](https://github.com/kbsali/php-redmine-api/compare/v2.6.0...v2.7.0) - 2024-07-10 ### Added diff --git a/README.md b/README.md index 7d2b805b..58564f4e 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,8 @@ like [Guzzle](https://github.com/guzzle/guzzle) for handling http connections * [mid-level API](docs/usage.md#mid-level-api) e.g. ```php $client->getApi('issue')->create(['project_id' => 1, 'subject' => 'issue title']); + + $response = $client->getApi('issue')->getLastResponse(); ``` * [low-level API](docs/usage.md#low-level-api) e.g. ```php diff --git a/composer.json b/composer.json index f90b7334..55d10390 100644 --- a/composer.json +++ b/composer.json @@ -51,6 +51,7 @@ }, "scripts": { "bdt": [ + "Composer\\Config::disableProcessTimeout", "@behat --format=progress --suite=redmine_50103", "@behat --format=progress --suite=redmine_50009", "@behat --format=progress --suite=redmine_40210" diff --git a/src/Redmine/Client/Client.php b/src/Redmine/Client/Client.php index 610b5234..0832ace1 100644 --- a/src/Redmine/Client/Client.php +++ b/src/Redmine/Client/Client.php @@ -28,36 +28,60 @@ public function stopImpersonateUser(): void; /** * Create and send a GET request. + * + * @deprecated v2.8.0 Use `\Redmine\Http\HttpClient::request()` instead + * @see \Redmine\Http\HttpClient::request() */ public function requestGet(string $path): bool; /** * Create and send a POST request. + * + * @deprecated v2.8.0 Use `\Redmine\Http\HttpClient::request()` instead + * @see \Redmine\Http\HttpClient::request() */ public function requestPost(string $path, string $body): bool; /** * Create and send a PUT request. + * + * @deprecated v2.8.0 Use `\Redmine\Http\HttpClient::request()` instead + * @see \Redmine\Http\HttpClient::request() */ public function requestPut(string $path, string $body): bool; /** * Create and send a DELETE request. + * + * @deprecated v2.8.0 Use `\Redmine\Http\HttpClient::request()` instead + * @see \Redmine\Http\HttpClient::request() */ public function requestDelete(string $path): bool; /** * Returns status code of the last response. + * + * @deprecated v2.8.0 Use `\Redmine\Http\HttpClient::request()` or `\Redmine\Api\AbstractApi::getLastResponse()` instead + * @see \Redmine\Http\HttpClient::request() + * @see \Redmine\Api\AbstractApi::getLastResponse() */ public function getLastResponseStatusCode(): int; /** * Returns content type of the last response. + * + * @deprecated v2.8.0 Use `\Redmine\Http\HttpClient::request()` or `\Redmine\Api\AbstractApi::getLastResponse()` instead + * @see \Redmine\Http\HttpClient::request() + * @see \Redmine\Api\AbstractApi::getLastResponse() */ public function getLastResponseContentType(): string; /** * Returns the body of the last response. + * + * @deprecated v2.8.0 Use `\Redmine\Http\HttpClient::request()` or `\Redmine\Api\AbstractApi::getLastResponse()` instead + * @see \Redmine\Http\HttpClient::request() + * @see \Redmine\Api\AbstractApi::getLastResponse() */ public function getLastResponseBody(): string; } diff --git a/src/Redmine/Client/NativeCurlClient.php b/src/Redmine/Client/NativeCurlClient.php index ccabb429..6dfb2c06 100644 --- a/src/Redmine/Client/NativeCurlClient.php +++ b/src/Redmine/Client/NativeCurlClient.php @@ -111,57 +111,95 @@ public function stopImpersonateUser(): void /** * Create and send a GET request. + * + * @deprecated v2.8.0 Use `\Redmine\Http\HttpClient::request()` instead + * @see \Redmine\Http\HttpClient::request() */ public function requestGet(string $path): bool { + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.8.0, use `\Redmine\Client\NativeCurlClient::request()` instead.', E_USER_DEPRECATED); + return $this->runRequest('GET', $path); } /** * Create and send a POST request. + * + * @deprecated v2.8.0 Use `\Redmine\Http\HttpClient::request()` instead + * @see \Redmine\Http\HttpClient::request() */ public function requestPost(string $path, string $body): bool { + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.8.0, use `\Redmine\Client\NativeCurlClient::request()` instead.', E_USER_DEPRECATED); + return $this->runRequest('POST', $path, $body); } /** * Create and send a PUT request. + * + * @deprecated v2.8.0 Use `\Redmine\Http\HttpClient::request()` instead + * @see \Redmine\Http\HttpClient::request() */ public function requestPut(string $path, string $body): bool { + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.8.0, use `\Redmine\Client\NativeCurlClient::request()` instead.', E_USER_DEPRECATED); + return $this->runRequest('PUT', $path, $body); } /** * Create and send a DELETE request. + * + * @deprecated v2.8.0 Use `\Redmine\Http\HttpClient::request()` instead + * @see \Redmine\Http\HttpClient::request() */ public function requestDelete(string $path): bool { + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.8.0, use `\Redmine\Client\NativeCurlClient::request()` instead.', E_USER_DEPRECATED); + return $this->runRequest('DELETE', $path); } /** * Returns status code of the last response. + * + * @deprecated v2.8.0 Use `\Redmine\Http\HttpClient::request()` or `\Redmine\Api\AbstractApi::getLastResponse()` instead + * @see \Redmine\Http\HttpClient::request() + * @see \Redmine\Api\AbstractApi::getLastResponse() */ public function getLastResponseStatusCode(): int { + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.8.0, use `\Redmine\Client\NativeCurlClient::request()` or `\Redmine\Api\AbstractApi::getLastResponse()` instead.', E_USER_DEPRECATED); + return $this->lastResponseStatusCode; } /** * Returns content type of the last response. + * + * @deprecated v2.8.0 Use `\Redmine\Http\HttpClient::request()` or `\Redmine\Api\AbstractApi::getLastResponse()` instead + * @see \Redmine\Http\HttpClient::request() + * @see \Redmine\Api\AbstractApi::getLastResponse() */ public function getLastResponseContentType(): string { + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.8.0, use `\Redmine\Client\NativeCurlClient::request()` or `\Redmine\Api\AbstractApi::getLastResponse()` instead.', E_USER_DEPRECATED); + return $this->lastResponseContentType; } /** * Returns the body of the last response. + * + * @deprecated v2.8.0 Use `\Redmine\Http\HttpClient::request()` or `\Redmine\Api\AbstractApi::getLastResponse()` instead + * @see \Redmine\Http\HttpClient::request() + * @see \Redmine\Api\AbstractApi::getLastResponse() */ public function getLastResponseBody(): string { + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.8.0, use `\Redmine\Client\NativeCurlClient::request()` or `\Redmine\Api\AbstractApi::getLastResponse()` instead.', E_USER_DEPRECATED); + return $this->lastResponseBody; } diff --git a/src/Redmine/Client/Psr18Client.php b/src/Redmine/Client/Psr18Client.php index a62d415f..d0c0da17 100644 --- a/src/Redmine/Client/Psr18Client.php +++ b/src/Redmine/Client/Psr18Client.php @@ -118,12 +118,17 @@ public function stopImpersonateUser(): void /** * Create and send a GET request. * + * @deprecated v2.8.0 Use `\Redmine\Http\HttpClient::request()` instead + * @see \Redmine\Http\HttpClient::request() + * * @throws ClientException If anything goes wrong on the request * * @return bool true if status code of the response is not 4xx oder 5xx */ public function requestGet(string $path): bool { + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.8.0, use `\Redmine\Client\Psr18Client::request()` instead.', E_USER_DEPRECATED); + $response = $this->runRequest('GET', $path); return $response->getStatusCode() < 400; @@ -132,12 +137,17 @@ public function requestGet(string $path): bool /** * Create and send a POST request. * + * @deprecated v2.8.0 Use `\Redmine\Http\HttpClient::request()` instead + * @see \Redmine\Http\HttpClient::request() + * * @throws ClientException If anything goes wrong on the request * * @return bool true if status code of the response is not 4xx oder 5xx */ public function requestPost(string $path, string $body): bool { + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.8.0, use `\Redmine\Client\Psr18Client::request()` instead.', E_USER_DEPRECATED); + $response = $this->runRequest('POST', $path, $body); return $response->getStatusCode() < 400; @@ -146,12 +156,17 @@ public function requestPost(string $path, string $body): bool /** * Create and send a PUT request. * + * @deprecated v2.8.0 Use `\Redmine\Http\HttpClient::request()` instead + * @see \Redmine\Http\HttpClient::request() + * * @throws ClientException If anything goes wrong on the request * * @return bool true if status code of the response is not 4xx oder 5xx */ public function requestPut(string $path, string $body): bool { + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.8.0, use `\Redmine\Client\Psr18Client::request()` instead.', E_USER_DEPRECATED); + $response = $this->runRequest('PUT', $path, $body); return $response->getStatusCode() < 400; @@ -160,12 +175,17 @@ public function requestPut(string $path, string $body): bool /** * Create and send a DELETE request. * + * @deprecated v2.8.0 Use `\Redmine\Http\HttpClient::request()` instead + * @see \Redmine\Http\HttpClient::request() + * * @throws ClientException If anything goes wrong on the request * * @return bool true if status code of the response is not 4xx oder 5xx */ public function requestDelete(string $path): bool { + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.8.0, use `\Redmine\Client\Psr18Client::request()` instead.', E_USER_DEPRECATED); + $response = $this->runRequest('DELETE', $path); return $response->getStatusCode() < 400; @@ -173,9 +193,14 @@ public function requestDelete(string $path): bool /** * Returns status code of the last response. + * + * @deprecated v2.8.0 Use `\Redmine\Api\AbstractApi::getLastResponse()` instead + * @see \Redmine\Api\AbstractApi::getLastResponse() */ public function getLastResponseStatusCode(): int { + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.8.0, use `\Redmine\Api\AbstractApi::getLastResponse()` instead.', E_USER_DEPRECATED); + if (null === $this->lastResponse) { return 0; } @@ -185,9 +210,14 @@ public function getLastResponseStatusCode(): int /** * Returns content type of the last response. + * + * @deprecated v2.8.0 Use `\Redmine\Api\AbstractApi::getLastResponse()` instead + * @see \Redmine\Api\AbstractApi::getLastResponse() */ public function getLastResponseContentType(): string { + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.8.0, use `\Redmine\Api\AbstractApi::getLastResponse()` instead.', E_USER_DEPRECATED); + if (null === $this->lastResponse) { return ''; } @@ -197,9 +227,14 @@ public function getLastResponseContentType(): string /** * Returns the body of the last response. + * + * @deprecated v2.8.0 Use `\Redmine\Api\AbstractApi::getLastResponse()` instead + * @see \Redmine\Api\AbstractApi::getLastResponse() */ public function getLastResponseBody(): string { + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.8.0, use `\Redmine\Api\AbstractApi::getLastResponse()` instead.', E_USER_DEPRECATED); + if (null === $this->lastResponse) { return ''; } diff --git a/tests/Unit/Client/NativeCurlClientTest.php b/tests/Unit/Client/NativeCurlClientTest.php index 1f4c234d..c229db48 100644 --- a/tests/Unit/Client/NativeCurlClientTest.php +++ b/tests/Unit/Client/NativeCurlClientTest.php @@ -12,6 +12,7 @@ use PHPUnit\Framework\TestCase; use Redmine\Client\Client; use Redmine\Client\NativeCurlClient; +use Redmine\Exception\ClientException; use Redmine\Http\HttpClient; use stdClass; @@ -69,6 +70,30 @@ public function testGetLastResponseStatusCodeIsInitialNull(): void $this->assertSame(0, $client->getLastResponseStatusCode()); } + public function testGetLastResponseStatusCodeTriggersDeprecationWarning(): void + { + $client = new NativeCurlClient( + 'http://test.local', + 'access_token', + ); + + // PHPUnit 10 compatible way to test trigger_error(). + set_error_handler( + function ($errno, $errstr): bool { + $this->assertSame( + '`Redmine\Client\NativeCurlClient::getLastResponseStatusCode()` is deprecated since v2.8.0, use `\Redmine\Client\NativeCurlClient::request()` or `\Redmine\Api\AbstractApi::getLastResponse()` instead.', + $errstr, + ); + + restore_error_handler(); + return true; + }, + E_USER_DEPRECATED, + ); + + $client->getLastResponseStatusCode(); + } + public function testGetLastResponseContentTypeIsInitialEmpty(): void { $client = new NativeCurlClient( @@ -79,6 +104,30 @@ public function testGetLastResponseContentTypeIsInitialEmpty(): void $this->assertSame('', $client->getLastResponseContentType()); } + public function testGetLastResponseContentTypeTriggersDeprecationWarning(): void + { + $client = new NativeCurlClient( + 'http://test.local', + 'access_token', + ); + + // PHPUnit 10 compatible way to test trigger_error(). + set_error_handler( + function ($errno, $errstr): bool { + $this->assertSame( + '`Redmine\Client\NativeCurlClient::getLastResponseContentType()` is deprecated since v2.8.0, use `\Redmine\Client\NativeCurlClient::request()` or `\Redmine\Api\AbstractApi::getLastResponse()` instead.', + $errstr, + ); + + restore_error_handler(); + return true; + }, + E_USER_DEPRECATED, + ); + + $client->getLastResponseContentType(); + } + public function testGetLastResponseBodyIsInitialEmpty(): void { $client = new NativeCurlClient( @@ -89,6 +138,30 @@ public function testGetLastResponseBodyIsInitialEmpty(): void $this->assertSame('', $client->getLastResponseBody()); } + public function testGetLastResponseBodyTriggersDeprecationWarning(): void + { + $client = new NativeCurlClient( + 'http://test.local', + 'access_token', + ); + + // PHPUnit 10 compatible way to test trigger_error(). + set_error_handler( + function ($errno, $errstr): bool { + $this->assertSame( + '`Redmine\Client\NativeCurlClient::getLastResponseBody()` is deprecated since v2.8.0, use `\Redmine\Client\NativeCurlClient::request()` or `\Redmine\Api\AbstractApi::getLastResponse()` instead.', + $errstr, + ); + + restore_error_handler(); + return true; + }, + E_USER_DEPRECATED, + ); + + $client->getLastResponseBody(); + } + public function testStartAndStopImpersonateUser(): void { $expectedOptions = [ @@ -651,6 +724,186 @@ public static function getRequestReponseData(): array ]; } + public function testRequestGetTriggersDeprecationWarning(): void + { + $curl = $this->createMock(stdClass::class); + + $curlInit = $this->getFunctionMock(self::__NAMESPACE__, 'curl_init'); + + $curlExec = $this->getFunctionMock(self::__NAMESPACE__, 'curl_exec'); + + $curlSetoptArray = $this->getFunctionMock(self::__NAMESPACE__, 'curl_setopt_array'); + + $curlGetinfo = $this->getFunctionMock(self::__NAMESPACE__, 'curl_getinfo'); + + $curlErrno = $this->getFunctionMock(self::__NAMESPACE__, 'curl_errno'); + $curlErrno->expects($this->exactly(1))->willReturn(CURLE_COULDNT_CONNECT); + + $curlError = $this->getFunctionMock(self::__NAMESPACE__, 'curl_error'); + $curlError->expects($this->exactly(1))->willReturn(''); + + $curlClose = $this->getFunctionMock(self::__NAMESPACE__, 'curl_close'); + + $client = new NativeCurlClient( + 'http://test.local', + 'access_token', + ); + + // PHPUnit 10 compatible way to test trigger_error(). + set_error_handler( + function ($errno, $errstr): bool { + $this->assertSame( + '`Redmine\Client\NativeCurlClient::requestGet()` is deprecated since v2.8.0, use `\Redmine\Client\NativeCurlClient::request()` instead.', + $errstr, + ); + + restore_error_handler(); + return true; + }, + E_USER_DEPRECATED, + ); + + try { + $client->requestGet('/path'); + } catch (ClientException $th) { + } + } + + public function testRequestPostTriggersDeprecationWarning(): void + { + $curl = $this->createMock(stdClass::class); + + $curlInit = $this->getFunctionMock(self::__NAMESPACE__, 'curl_init'); + + $curlExec = $this->getFunctionMock(self::__NAMESPACE__, 'curl_exec'); + + $curlSetoptArray = $this->getFunctionMock(self::__NAMESPACE__, 'curl_setopt_array'); + + $curlGetinfo = $this->getFunctionMock(self::__NAMESPACE__, 'curl_getinfo'); + + $curlErrno = $this->getFunctionMock(self::__NAMESPACE__, 'curl_errno'); + $curlErrno->expects($this->exactly(1))->willReturn(CURLE_COULDNT_CONNECT); + + $curlError = $this->getFunctionMock(self::__NAMESPACE__, 'curl_error'); + $curlError->expects($this->exactly(1))->willReturn(''); + + $curlClose = $this->getFunctionMock(self::__NAMESPACE__, 'curl_close'); + + $client = new NativeCurlClient( + 'http://test.local', + 'access_token', + ); + + // PHPUnit 10 compatible way to test trigger_error(). + set_error_handler( + function ($errno, $errstr): bool { + $this->assertSame( + '`Redmine\Client\NativeCurlClient::requestPost()` is deprecated since v2.8.0, use `\Redmine\Client\NativeCurlClient::request()` instead.', + $errstr, + ); + + restore_error_handler(); + return true; + }, + E_USER_DEPRECATED, + ); + + try { + $client->requestPost('/path', ''); + } catch (ClientException $th) { + } + } + + public function testRequestPutTriggersDeprecationWarning(): void + { + $curl = $this->createMock(stdClass::class); + + $curlInit = $this->getFunctionMock(self::__NAMESPACE__, 'curl_init'); + + $curlExec = $this->getFunctionMock(self::__NAMESPACE__, 'curl_exec'); + + $curlSetoptArray = $this->getFunctionMock(self::__NAMESPACE__, 'curl_setopt_array'); + + $curlGetinfo = $this->getFunctionMock(self::__NAMESPACE__, 'curl_getinfo'); + + $curlErrno = $this->getFunctionMock(self::__NAMESPACE__, 'curl_errno'); + $curlErrno->expects($this->exactly(1))->willReturn(CURLE_COULDNT_CONNECT); + + $curlError = $this->getFunctionMock(self::__NAMESPACE__, 'curl_error'); + $curlError->expects($this->exactly(1))->willReturn(''); + + $curlClose = $this->getFunctionMock(self::__NAMESPACE__, 'curl_close'); + + $client = new NativeCurlClient( + 'http://test.local', + 'access_token', + ); + + // PHPUnit 10 compatible way to test trigger_error(). + set_error_handler( + function ($errno, $errstr): bool { + $this->assertSame( + '`Redmine\Client\NativeCurlClient::requestPut()` is deprecated since v2.8.0, use `\Redmine\Client\NativeCurlClient::request()` instead.', + $errstr, + ); + + restore_error_handler(); + return true; + }, + E_USER_DEPRECATED, + ); + + try { + $client->requestPut('/path', ''); + } catch (ClientException $th) { + } + } + + public function testRequestDeleteTriggersDeprecationWarning(): void + { + $curl = $this->createMock(stdClass::class); + + $curlInit = $this->getFunctionMock(self::__NAMESPACE__, 'curl_init'); + + $curlExec = $this->getFunctionMock(self::__NAMESPACE__, 'curl_exec'); + + $curlSetoptArray = $this->getFunctionMock(self::__NAMESPACE__, 'curl_setopt_array'); + + $curlGetinfo = $this->getFunctionMock(self::__NAMESPACE__, 'curl_getinfo'); + + $curlErrno = $this->getFunctionMock(self::__NAMESPACE__, 'curl_errno'); + $curlErrno->expects($this->exactly(1))->willReturn(CURLE_COULDNT_CONNECT); + + $curlError = $this->getFunctionMock(self::__NAMESPACE__, 'curl_error'); + $curlError->expects($this->exactly(1))->willReturn(''); + + $curlClose = $this->getFunctionMock(self::__NAMESPACE__, 'curl_close'); + + $client = new NativeCurlClient( + 'http://test.local', + 'access_token', + ); + + // PHPUnit 10 compatible way to test trigger_error(). + set_error_handler( + function ($errno, $errstr): bool { + $this->assertSame( + '`Redmine\Client\NativeCurlClient::requestDelete()` is deprecated since v2.8.0, use `\Redmine\Client\NativeCurlClient::request()` instead.', + $errstr, + ); + + restore_error_handler(); + return true; + }, + E_USER_DEPRECATED, + ); + + try { + $client->requestDelete('/path'); + } catch (ClientException $th) { + } + } + public function testHandlingOfResponseWithoutContent(): void { $content = ''; diff --git a/tests/Unit/Client/Psr18ClientTest.php b/tests/Unit/Client/Psr18ClientTest.php index 3f5b6592..472cf458 100644 --- a/tests/Unit/Client/Psr18ClientTest.php +++ b/tests/Unit/Client/Psr18ClientTest.php @@ -17,6 +17,7 @@ use Psr\Http\Message\StreamInterface; use Redmine\Client\Client; use Redmine\Client\Psr18Client; +use Redmine\Exception\ClientException; use Redmine\Http\HttpClient; use stdClass; @@ -90,6 +91,33 @@ public function testGetLastResponseStatusCodeIsInitialZero(): void $this->assertSame(0, $client->getLastResponseStatusCode()); } + public function testGetLastResponseStatusCodeTriggersDeprecationWarning(): void + { + $client = new Psr18Client( + $this->createMock(ClientInterface::class), + $this->createMock(RequestFactoryInterface::class), + $this->createMock(StreamFactoryInterface::class), + 'http://test.local', + 'access_token', + ); + + // PHPUnit 10 compatible way to test trigger_error(). + set_error_handler( + function ($errno, $errstr): bool { + $this->assertSame( + '`Redmine\Client\Psr18Client::getLastResponseStatusCode()` is deprecated since v2.8.0, use `\Redmine\Api\AbstractApi::getLastResponse()` instead.', + $errstr, + ); + + restore_error_handler(); + return true; + }, + E_USER_DEPRECATED, + ); + + $client->getLastResponseStatusCode(); + } + public function testGetLastResponseContentTypeIsInitialEmpty(): void { $client = new Psr18Client( @@ -103,6 +131,33 @@ public function testGetLastResponseContentTypeIsInitialEmpty(): void $this->assertSame('', $client->getLastResponseContentType()); } + public function testGetLastResponseContentTypeTriggersDeprecationWarning(): void + { + $client = new Psr18Client( + $this->createMock(ClientInterface::class), + $this->createMock(RequestFactoryInterface::class), + $this->createMock(StreamFactoryInterface::class), + 'http://test.local', + 'access_token', + ); + + // PHPUnit 10 compatible way to test trigger_error(). + set_error_handler( + function ($errno, $errstr): bool { + $this->assertSame( + '`Redmine\Client\Psr18Client::getLastResponseContentType()` is deprecated since v2.8.0, use `\Redmine\Api\AbstractApi::getLastResponse()` instead.', + $errstr, + ); + + restore_error_handler(); + return true; + }, + E_USER_DEPRECATED, + ); + + $client->getLastResponseContentType(); + } + public function testGetLastResponseBodyIsInitialEmpty(): void { $client = new Psr18Client( @@ -116,6 +171,33 @@ public function testGetLastResponseBodyIsInitialEmpty(): void $this->assertSame('', $client->getLastResponseBody()); } + public function testGetLastResponseBodyTriggersDeprecationWarning(): void + { + $client = new Psr18Client( + $this->createMock(ClientInterface::class), + $this->createMock(RequestFactoryInterface::class), + $this->createMock(StreamFactoryInterface::class), + 'http://test.local', + 'access_token', + ); + + // PHPUnit 10 compatible way to test trigger_error(). + set_error_handler( + function ($errno, $errstr): bool { + $this->assertSame( + '`Redmine\Client\Psr18Client::getLastResponseBody()` is deprecated since v2.8.0, use `\Redmine\Api\AbstractApi::getLastResponse()` instead.', + $errstr, + ); + + restore_error_handler(); + return true; + }, + E_USER_DEPRECATED, + ); + + $client->getLastResponseBody(); + } + public function testStartAndStopImpersonateUser(): void { $request = $this->createMock(RequestInterface::class); @@ -235,6 +317,146 @@ public static function getRequestReponseData(): array ]; } + public function testRequestGetTriggersDeprecationWarning(): void + { + $requestFactory = $this->createMock(RequestFactoryInterface::class); + $requestFactory->method('createRequest')->willThrowException( + $this->createMock(ClientException::class), + ); + + $client = new Psr18Client( + $this->createMock(ClientInterface::class), + $requestFactory, + $this->createMock(StreamFactoryInterface::class), + 'http://test.local', + 'access_token', + ); + + // PHPUnit 10 compatible way to test trigger_error(). + set_error_handler( + function ($errno, $errstr): bool { + $this->assertSame( + '`Redmine\Client\Psr18Client::requestGet()` is deprecated since v2.8.0, use `\Redmine\Client\Psr18Client::request()` instead.', + $errstr, + ); + + restore_error_handler(); + return true; + }, + E_USER_DEPRECATED, + ); + + try { + $client->requestGet('/path'); + } catch (ClientException $th) { + } + } + + public function testRequestPostTriggersDeprecationWarning(): void + { + $requestFactory = $this->createMock(RequestFactoryInterface::class); + $requestFactory->method('createRequest')->willThrowException( + $this->createMock(ClientException::class), + ); + + $client = new Psr18Client( + $this->createMock(ClientInterface::class), + $requestFactory, + $this->createMock(StreamFactoryInterface::class), + 'http://test.local', + 'access_token', + ); + + // PHPUnit 10 compatible way to test trigger_error(). + set_error_handler( + function ($errno, $errstr): bool { + $this->assertSame( + '`Redmine\Client\Psr18Client::requestPost()` is deprecated since v2.8.0, use `\Redmine\Client\Psr18Client::request()` instead.', + $errstr, + ); + + restore_error_handler(); + return true; + }, + E_USER_DEPRECATED, + ); + + try { + $client->requestPost('/path', ''); + } catch (ClientException $th) { + } + } + + public function testRequestPutTriggersDeprecationWarning(): void + { + $requestFactory = $this->createMock(RequestFactoryInterface::class); + $requestFactory->method('createRequest')->willThrowException( + $this->createMock(ClientException::class), + ); + + $client = new Psr18Client( + $this->createMock(ClientInterface::class), + $requestFactory, + $this->createMock(StreamFactoryInterface::class), + 'http://test.local', + 'access_token', + ); + + // PHPUnit 10 compatible way to test trigger_error(). + set_error_handler( + function ($errno, $errstr): bool { + $this->assertSame( + '`Redmine\Client\Psr18Client::requestPut()` is deprecated since v2.8.0, use `\Redmine\Client\Psr18Client::request()` instead.', + $errstr, + ); + + restore_error_handler(); + return true; + }, + E_USER_DEPRECATED, + ); + + try { + $client->requestPut('/path', ''); + } catch (ClientException $th) { + } + } + + public function testRequestDeleteTriggersDeprecationWarning(): void + { + $requestFactory = $this->createMock(RequestFactoryInterface::class); + $requestFactory->method('createRequest')->willThrowException( + $this->createMock(ClientException::class), + ); + + $client = new Psr18Client( + $this->createMock(ClientInterface::class), + $requestFactory, + $this->createMock(StreamFactoryInterface::class), + 'http://test.local', + 'access_token', + ); + + // PHPUnit 10 compatible way to test trigger_error(). + set_error_handler( + function ($errno, $errstr): bool { + $this->assertSame( + '`Redmine\Client\Psr18Client::requestDelete()` is deprecated since v2.8.0, use `\Redmine\Client\Psr18Client::request()` instead.', + $errstr, + ); + + restore_error_handler(); + return true; + }, + E_USER_DEPRECATED, + ); + + try { + $client->requestDelete('/path'); + } catch (ClientException $th) { + } + } + /** * @dataProvider getApiClassesProvider */