diff --git a/.docker/PHP-Dockerfile b/.docker/PHP74-Dockerfile similarity index 100% rename from .docker/PHP-Dockerfile rename to .docker/PHP74-Dockerfile diff --git a/.docker/PHP85-Dockerfile b/.docker/PHP85-Dockerfile new file mode 100644 index 00000000..88e72eb4 --- /dev/null +++ b/.docker/PHP85-Dockerfile @@ -0,0 +1,39 @@ +FROM php:8.5-fpm + +RUN apt-get update +RUN apt-get --yes --no-install-recommends install \ + apt-utils \ + curl \ + git \ + vim + +ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ + +RUN install-php-extensions \ + bcmath \ + exif \ + gd \ + intl \ + mysqli \ + opcache \ + pdo \ + pdo_mysql \ + sockets \ + xdebug-^3.5 \ + zip \ + @composer + +COPY build/php/opcache.ini /usr/local/etc/php/conf.d/ +COPY build/php/custom.ini /usr/local/etc/php/conf.d/ + + +RUN php --version + +RUN composer --version + +RUN usermod -u 1000 www-data +RUN usermod -a -G www-data root +RUN mkdir -p /var/www/.composer +RUN chown -R www-data:www-data /var/www + +WORKDIR /var/www/project/ diff --git a/docker-compose.yml b/docker-compose.yml index ee91460e..4c1e5cbf 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,7 @@ services: php: build: # Info to build the Docker image context: ./.docker # Specify where the Dockerfile is located (e.g. in the root directory of the project) - dockerfile: PHP-Dockerfile # Specify the name of the Dockerfile + dockerfile: PHP74-Dockerfile # Specify the name of the Dockerfile ports: - 8111:80 depends_on: diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 0eb978e2..ad9380c5 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -7,9 +7,9 @@ beStrictAboutCoverageMetadata="false" beStrictAboutOutputDuringTests="true" displayDetailsOnIncompleteTests="true" - displayDetailsOnPhpunitDeprecations="true" displayDetailsOnSkippedTests="true" displayDetailsOnTestsThatTriggerDeprecations="true" + displayDetailsOnPhpunitDeprecations="true" displayDetailsOnTestsThatTriggerErrors="true" displayDetailsOnTestsThatTriggerNotices="true" displayDetailsOnTestsThatTriggerWarnings="true" diff --git a/src/Redmine/Client/NativeCurlClient.php b/src/Redmine/Client/NativeCurlClient.php index dfa31a08..d55ea9ba 100644 --- a/src/Redmine/Client/NativeCurlClient.php +++ b/src/Redmine/Client/NativeCurlClient.php @@ -309,7 +309,11 @@ private function runRequest(string $method, string $path, string $body = '', str if (CURLE_OK !== $curlErrorNumber) { $e = new ClientException(curl_error($curl), $curlErrorNumber); - curl_close($curl); + + if (PHP_VERSION_ID < 80000) { + curl_close($curl); + } + throw $e; } @@ -321,7 +325,9 @@ private function runRequest(string $method, string $path, string $body = '', str $this->lastResponseContentType = $possibleContentType; } - curl_close($curl); + if (PHP_VERSION_ID < 80000) { + curl_close($curl); + } return $this->lastResponseStatusCode < 400; } diff --git a/tests/Fixtures/AssertingHttpClient.php b/tests/Fixtures/AssertingHttpClient.php index 884f08f7..38539085 100644 --- a/tests/Fixtures/AssertingHttpClient.php +++ b/tests/Fixtures/AssertingHttpClient.php @@ -6,6 +6,7 @@ use PHPUnit\Framework\MockObject\MockBuilder; use PHPUnit\Framework\MockObject\Rule\InvokedCount; +use PHPUnit\Framework\MockObject\TestStubBuilder; use PHPUnit\Framework\TestCase; use Redmine\Http\HttpClient; use Redmine\Http\Request; @@ -100,8 +101,14 @@ public function request(Request $request): Response $this->testCase->assertSame($data['content'], $request->getContent()); } - /** @var \PHPUnit\Framework\MockObject\MockObject&Response */ - $response = (new MockBuilder($this->testCase, Response::class))->getMock(); + $createStubMethod = new \ReflectionMethod($this->testCase, 'createStub'); + + if (PHP_VERSION_ID < 80100) { + $createStubMethod->setAccessible(true); + } + + /** @var \PHPUnit\Framework\MockObject\Stub&Response $response */ + $response = $createStubMethod->invoke($this->testCase, Response::class); $response->method('getStatusCode')->willReturn($data['responseCode']); $response->method('getContentType')->willReturn($data['responseContentType']); diff --git a/tests/Integration/Psr18ClientRequestGenerationTest.php b/tests/Integration/Psr18ClientRequestGenerationTest.php index 69f0b846..4dd27c70 100644 --- a/tests/Integration/Psr18ClientRequestGenerationTest.php +++ b/tests/Integration/Psr18ClientRequestGenerationTest.php @@ -33,11 +33,11 @@ public function testPsr18ClientCreatesCorrectRequests( $data, string $expectedOutput ): void { - $response = $this->createMock(ResponseInterface::class); + $response = $this->createStub(ResponseInterface::class); /** @var ClientInterface&\PHPUnit\Framework\MockObject\MockObject */ - $httpClient = $this->createMock(ClientInterface::class); - $httpClient->method('sendRequest')->willReturnCallback(function ($request) use ($response, $expectedOutput): \PHPUnit\Framework\MockObject\MockObject { + $httpClient = $this->createStub(ClientInterface::class); + $httpClient->method('sendRequest')->willReturnCallback(function ($request) use ($response, $expectedOutput): \PHPUnit\Framework\MockObject\Stub { // Create a text representation of the HTTP request $content = $request->getBody()->__toString(); @@ -64,7 +64,7 @@ public function testPsr18ClientCreatesCorrectRequests( return $response; }); - $requestFactory = $this->createMock(RequestFactoryInterface::class); + $requestFactory = $this->createStub(RequestFactoryInterface::class); $requestFactory->method('createRequest')->willReturnCallback(fn($method, $uri): \GuzzleHttp\Psr7\Request => new Request($method, $uri)); $streamFactory = new class implements StreamFactoryInterface { diff --git a/tests/RedmineExtension/RedmineInstance.php b/tests/RedmineExtension/RedmineInstance.php index 6f69996f..da035c99 100644 --- a/tests/RedmineExtension/RedmineInstance.php +++ b/tests/RedmineExtension/RedmineInstance.php @@ -105,7 +105,9 @@ private function runHealthChecks(RedmineVersion $version): void curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $data = curl_exec($ch); $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); - curl_close($ch); + if (PHP_VERSION_ID < 80000) { + curl_close($ch); + } if ($data === false || $statusCode !== 200) { throw new InvalidArgumentException(sprintf( diff --git a/tests/Unit/Api/AbstractApi/DeleteTest.php b/tests/Unit/Api/AbstractApi/DeleteTest.php index a86460d0..766adbe3 100644 --- a/tests/Unit/Api/AbstractApi/DeleteTest.php +++ b/tests/Unit/Api/AbstractApi/DeleteTest.php @@ -33,7 +33,9 @@ public function testDeleteWithHttpClient(): void $api = new class ($client) extends AbstractApi {}; $method = new ReflectionMethod($api, 'delete'); - $method->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $method->setAccessible(true); + } // Perform the tests $return = $method->invoke($api, 'path.xml'); @@ -47,14 +49,16 @@ public function testDeleteWithHttpClient(): void #[DataProvider('getXmlDecodingFromDeleteMethodData')] public function testXmlDecodingFromDeleteMethod(string $response, string $expected): void { - $client = $this->createMock(Client::class); + $client = $this->createStub(Client::class); $client->method('getLastResponseBody')->willReturn($response); $client->method('getLastResponseContentType')->willReturn('application/xml'); $api = new class ($client) extends AbstractApi {}; $method = new ReflectionMethod($api, 'delete'); - $method->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $method->setAccessible(true); + } // Perform the tests $return = $method->invoke($api, 'path.xml'); diff --git a/tests/Unit/Api/AbstractApi/GetTest.php b/tests/Unit/Api/AbstractApi/GetTest.php index 43f21085..98227ccc 100644 --- a/tests/Unit/Api/AbstractApi/GetTest.php +++ b/tests/Unit/Api/AbstractApi/GetTest.php @@ -34,7 +34,9 @@ public function testGetWithHttpClient(): void $api = new class ($client) extends AbstractApi {}; $method = new ReflectionMethod($api, 'get'); - $method->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $method->setAccessible(true); + } // Perform the tests $this->assertSame( @@ -49,14 +51,16 @@ public function testGetWithHttpClient(): void #[DataProvider('getJsonDecodingFromGetMethodData')] public function testJsonDecodingFromGetMethod(string $response, ?bool $decode, $expected): void { - $client = $this->createMock(Client::class); + $client = $this->createStub(Client::class); $client->method('getLastResponseBody')->willReturn($response); $client->method('getLastResponseContentType')->willReturn('application/json'); $api = new class ($client) extends AbstractApi {}; $method = new ReflectionMethod($api, 'get'); - $method->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $method->setAccessible(true); + } // Perform the tests if (is_bool($decode)) { @@ -84,14 +88,16 @@ public static function getJsonDecodingFromGetMethodData(): array #[DataProvider('getXmlDecodingFromGetMethodData')] public function testXmlDecodingFromGetMethod(string $response, ?bool $decode, string $expected): void { - $client = $this->createMock(Client::class); + $client = $this->createStub(Client::class); $client->method('getLastResponseBody')->willReturn($response); $client->method('getLastResponseContentType')->willReturn('application/xml'); $api = new class ($client) extends AbstractApi {}; $method = new ReflectionMethod($api, 'get'); - $method->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $method->setAccessible(true); + } // Perform the tests $return = $method->invoke($api, 'path', $decode); diff --git a/tests/Unit/Api/AbstractApi/PostTest.php b/tests/Unit/Api/AbstractApi/PostTest.php index adcb7161..5a2ef539 100644 --- a/tests/Unit/Api/AbstractApi/PostTest.php +++ b/tests/Unit/Api/AbstractApi/PostTest.php @@ -34,7 +34,9 @@ public function testPostWithHttpClient(): void $api = new class ($client) extends AbstractApi {}; $method = new ReflectionMethod($api, 'post'); - $method->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $method->setAccessible(true); + } // Perform the tests $return = $method->invoke($api, 'path.xml', ''); @@ -49,14 +51,16 @@ public function testPostWithHttpClient(): void #[DataProvider('getXmlDecodingFromPostMethodData')] public function testXmlDecodingFromPostMethod(string $response, string $expected): void { - $client = $this->createMock(Client::class); + $client = $this->createStub(Client::class); $client->method('getLastResponseBody')->willReturn($response); $client->method('getLastResponseContentType')->willReturn('application/xml'); $api = new class ($client) extends AbstractApi {}; $method = new ReflectionMethod($api, 'post'); - $method->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $method->setAccessible(true); + } // Perform the tests $return = $method->invoke($api, 'path.xml', ''); diff --git a/tests/Unit/Api/AbstractApi/PutTest.php b/tests/Unit/Api/AbstractApi/PutTest.php index e6e80ef6..2869ab9b 100644 --- a/tests/Unit/Api/AbstractApi/PutTest.php +++ b/tests/Unit/Api/AbstractApi/PutTest.php @@ -34,7 +34,9 @@ public function testPutWithHttpClient(): void $api = new class ($client) extends AbstractApi {}; $method = new ReflectionMethod($api, 'put'); - $method->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $method->setAccessible(true); + } // Perform the tests $return = $method->invoke($api, 'path.xml', ''); @@ -49,14 +51,16 @@ public function testPutWithHttpClient(): void #[DataProvider('getXmlDecodingFromPutMethodData')] public function testXmlDecodingFromPutMethod(string $response, string $expected): void { - $client = $this->createMock(Client::class); + $client = $this->createStub(Client::class); $client->method('getLastResponseBody')->willReturn($response); $client->method('getLastResponseContentType')->willReturn('application/xml'); $api = new class ($client) extends AbstractApi {}; $method = new ReflectionMethod($api, 'put'); - $method->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $method->setAccessible(true); + } // Perform the tests $return = $method->invoke($api, 'path.xml', ''); diff --git a/tests/Unit/Api/AbstractApiTest.php b/tests/Unit/Api/AbstractApiTest.php index 2c8a2896..25a0fed4 100644 --- a/tests/Unit/Api/AbstractApiTest.php +++ b/tests/Unit/Api/AbstractApiTest.php @@ -20,24 +20,28 @@ class AbstractApiTest extends TestCase { public function testCreateWithHttpClientWorks(): void { - $client = $this->createMock(HttpClient::class); + $client = $this->createStub(HttpClient::class); $api = new class ($client) extends AbstractApi {}; $method = new ReflectionMethod($api, 'getHttpClient'); - $method->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $method->setAccessible(true); + } $this->assertSame($client, $method->invoke($api)); } public function testCreateWitClientWorks(): void { - $client = $this->createMock(Client::class); + $client = $this->createStub(Client::class); $api = new class ($client) extends AbstractApi {}; $method = new ReflectionMethod($api, 'getHttpClient'); - $method->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $method->setAccessible(true); + } $this->assertInstanceOf(HttpClient::class, $method->invoke($api)); } @@ -53,7 +57,7 @@ public function testCreateWithoutClitentOrHttpClientThrowsException(): void public function testGetTriggersDeprecationWarning(): void { - $client = $this->createMock(HttpClient::class); + $client = $this->createStub(HttpClient::class); $api = new class ($client) extends AbstractApi { public function runGet($path) @@ -81,7 +85,7 @@ function ($errno, $errstr): bool { public function testGetLastResponseWithHttpClientWorks(): void { - $client = $this->createMock(HttpClient::class); + $client = $this->createStub(HttpClient::class); $api = new class ($client) extends AbstractApi {}; @@ -90,7 +94,7 @@ public function testGetLastResponseWithHttpClientWorks(): void public function testPostTriggersDeprecationWarning(): void { - $client = $this->createMock(HttpClient::class); + $client = $this->createStub(HttpClient::class); $api = new class ($client) extends AbstractApi { public function runPost($path, $data) @@ -118,7 +122,7 @@ function ($errno, $errstr): bool { public function testPutTriggersDeprecationWarning(): void { - $client = $this->createMock(HttpClient::class); + $client = $this->createStub(HttpClient::class); $api = new class ($client) extends AbstractApi { public function runPut($path, $data) @@ -146,7 +150,7 @@ function ($errno, $errstr): bool { public function testDeleteTriggersDeprecationWarning(): void { - $client = $this->createMock(HttpClient::class); + $client = $this->createStub(HttpClient::class); $api = new class ($client) extends AbstractApi { public function runDelete($path) @@ -178,12 +182,14 @@ function ($errno, $errstr): bool { #[DataProvider('getIsNotNullReturnsCorrectBooleanData')] public function testIsNotNullReturnsCorrectBoolean(bool $expected, $value): void { - $client = $this->createMock(Client::class); + $client = $this->createStub(Client::class); $api = new class ($client) extends AbstractApi {}; $method = new ReflectionMethod($api, 'isNotNull'); - $method->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $method->setAccessible(true); + } $this->assertSame($expected, $method->invoke($api, $value)); } @@ -259,7 +265,7 @@ public function __construct($client) #[DataProvider('getLastCallFailedData')] public function testLastCallFailedWithClientReturnsCorrectBoolean(int $statusCode, bool $expectedBoolean): void { - $client = $this->createMock(Client::class); + $client = $this->createStub(Client::class); $client->method('getLastResponseStatusCode')->willReturn($statusCode); $api = new class ($client) extends AbstractApi {}; @@ -273,10 +279,10 @@ public function testLastCallFailedWithClientReturnsCorrectBoolean(int $statusCod #[DataProvider('getLastCallFailedData')] public function testLastCallFailedWithHttpClientReturnsCorrectBoolean(int $statusCode, bool $expectedBoolean): void { - $response = $this->createMock(Response::class); + $response = $this->createStub(Response::class); $response->method('getStatusCode')->willReturn($statusCode); - $client = $this->createMock(HttpClient::class); + $client = $this->createStub(HttpClient::class); $client->method('request')->willReturn($response); $api = new class ($client) extends AbstractApi { @@ -367,7 +373,7 @@ public static function getLastCallFailedData(): array #[DataProvider('retrieveDataData')] public function testRetrieveData(string $path, string $contentType, string $response, array $expected): void { - $client = $this->createMock(Client::class); + $client = $this->createStub(Client::class); $client->method('requestGet')->willReturn(true); $client->method('getLastResponseBody')->willReturn($response); $client->method('getLastResponseContentType')->willReturn($contentType); @@ -375,7 +381,9 @@ public function testRetrieveData(string $path, string $contentType, string $resp $api = new class ($client) extends AbstractApi {}; $method = new ReflectionMethod($api, 'retrieveData'); - $method->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $method->setAccessible(true); + } $this->assertSame($expected, $method->invoke($api, $path)); } @@ -410,7 +418,9 @@ public function testRetrieveDataWith100ResultsMakes1Request(): void $api = new class ($client) extends AbstractApi {}; $method = new ReflectionMethod($api, 'retrieveData'); - $method->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $method->setAccessible(true); + } $method->invoke($api, '/data.json', ['limit' => 101]); } @@ -435,7 +445,9 @@ public function testRetrieveDataWith250ResultsMakes3Requests(): void $api = new class ($client) extends AbstractApi {}; $method = new ReflectionMethod($api, 'retrieveData'); - $method->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $method->setAccessible(true); + } $method->invoke($api, '/data.json', ['limit' => 301]); } @@ -446,7 +458,7 @@ public function testRetrieveDataWith250ResultsMakes3Requests(): void #[DataProvider('getRetrieveDataToExceptionData')] public function testRetrieveDataThrowsException(string $response, string $contentType, string $expectedException, string $expectedMessage): void { - $client = $this->createMock(Client::class); + $client = $this->createStub(Client::class); $client->method('requestGet')->willReturn(true); $client->method('getLastResponseBody')->willReturn($response); $client->method('getLastResponseContentType')->willReturn($contentType); @@ -454,7 +466,9 @@ public function testRetrieveDataThrowsException(string $response, string $conten $api = new class ($client) extends AbstractApi {}; $method = new ReflectionMethod($api, 'retrieveData'); - $method->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $method->setAccessible(true); + } $this->expectException($expectedException); $this->expectExceptionMessage($expectedMessage); @@ -475,7 +489,7 @@ public static function getRetrieveDataToExceptionData(): array #[DataProvider('getRetrieveAllData')] public function testDeprecatedRetrieveAll(string $content, string $contentType, $expected): void { - $client = $this->createMock(Client::class); + $client = $this->createStub(Client::class); $client->method('requestGet')->willReturn(true); $client->method('getLastResponseBody')->willReturn($content); $client->method('getLastResponseContentType')->willReturn($contentType); @@ -483,7 +497,9 @@ public function testDeprecatedRetrieveAll(string $content, string $contentType, $api = new class ($client) extends AbstractApi {}; $method = new ReflectionMethod($api, 'retrieveAll'); - $method->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $method->setAccessible(true); + } $this->assertSame($expected, $method->invoke($api, '')); } @@ -499,12 +515,14 @@ public static function getRetrieveAllData(): array public function testDeprecatedAttachCustomFieldXML(): void { - $client = $this->createMock(Client::class); + $client = $this->createStub(Client::class); $api = new class ($client) extends AbstractApi {}; $method = new ReflectionMethod($api, 'attachCustomFieldXML'); - $method->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $method->setAccessible(true); + } $xml = new SimpleXMLElement(''); diff --git a/tests/Unit/Api/CustomFieldTest.php b/tests/Unit/Api/CustomFieldTest.php index 6fd94f86..39811bda 100644 --- a/tests/Unit/Api/CustomFieldTest.php +++ b/tests/Unit/Api/CustomFieldTest.php @@ -286,7 +286,7 @@ public function testListingCallsGetEveryTimeWithForceUpdate(): void */ public function testListingTriggersDeprecationWarning(): void { - $client = $this->createMock(Client::class); + $client = $this->createStub(Client::class); $client->method('requestGet') ->willReturn(true); $client->method('getLastResponseBody') @@ -346,7 +346,7 @@ public function testGetIdByNameMakesGetRequest(): void public function testGetIdByNameTriggersDeprecationWarning(): void { - $client = $this->createMock(Client::class); + $client = $this->createStub(Client::class); $client->method('requestGet') ->willReturn(true); $client->method('getLastResponseBody') diff --git a/tests/Unit/Api/Group/CreateTest.php b/tests/Unit/Api/Group/CreateTest.php index ae269f54..13ae0b3c 100644 --- a/tests/Unit/Api/Group/CreateTest.php +++ b/tests/Unit/Api/Group/CreateTest.php @@ -137,7 +137,7 @@ public function testCreateThrowsExceptionIfNameIsMissing(): void $postParameter = []; // Create the used mock objects - $client = $this->createMock(HttpClient::class); + $client = $this->createStub(HttpClient::class); // Create the object under test $api = new Group($client); diff --git a/tests/Unit/Api/GroupTest.php b/tests/Unit/Api/GroupTest.php index 14d01398..ba05217d 100644 --- a/tests/Unit/Api/GroupTest.php +++ b/tests/Unit/Api/GroupTest.php @@ -118,7 +118,7 @@ public function testAllReturnsClientGetResponseWithParameters(): void */ public function testListingTriggersDeprecationWarning(): void { - $client = $this->createMock(Client::class); + $client = $this->createStub(Client::class); $client->method('requestGet') ->willReturn(true); $client->method('getLastResponseBody') diff --git a/tests/Unit/Api/IssueCategory/CreateTest.php b/tests/Unit/Api/IssueCategory/CreateTest.php index 576d9be3..ecd48568 100644 --- a/tests/Unit/Api/IssueCategory/CreateTest.php +++ b/tests/Unit/Api/IssueCategory/CreateTest.php @@ -100,7 +100,7 @@ public function testCreateReturnsEmptyString(): void public function testCreateThrowsExceptionWithEmptyParameters(): void { // Create the used mock objects - $client = $this->createMock(HttpClient::class); + $client = $this->createStub(HttpClient::class); // Create the object under test $api = new IssueCategory($client); @@ -119,7 +119,7 @@ public function testCreateThrowsExceptionWithEmptyParameters(): void public function testCreateThrowsExceptionIfMandatoyParametersAreMissing(array $parameters): void { // Create the used mock objects - $client = $this->createMock(HttpClient::class); + $client = $this->createStub(HttpClient::class); // Create the object under test $api = new IssueCategory($client); diff --git a/tests/Unit/Api/IssueCategory/ListNamesByProjectTest.php b/tests/Unit/Api/IssueCategory/ListNamesByProjectTest.php index 2640f277..e10ffc90 100644 --- a/tests/Unit/Api/IssueCategory/ListNamesByProjectTest.php +++ b/tests/Unit/Api/IssueCategory/ListNamesByProjectTest.php @@ -118,7 +118,7 @@ public function testListNamesByProjectCallsHttpClientOnlyOnce(): void #[DataProviderExternal(TestDataProvider::class, 'getInvalidProjectIdentifiers')] public function testListNamesByProjectWithWrongProjectIdentifierThrowsException($projectIdentifier): void { - $api = new IssueCategory($this->createMock(HttpClient::class)); + $api = new IssueCategory($this->createStub(HttpClient::class)); $this->expectException(InvalidParameterException::class); $this->expectExceptionMessage('Redmine\Api\IssueCategory::listNamesByProject(): Argument #1 ($projectIdentifier) must be of type int or string'); diff --git a/tests/Unit/Api/IssueCategoryTest.php b/tests/Unit/Api/IssueCategoryTest.php index 12d63b4e..a37e9c50 100644 --- a/tests/Unit/Api/IssueCategoryTest.php +++ b/tests/Unit/Api/IssueCategoryTest.php @@ -224,7 +224,7 @@ public function testListingCallsGetEveryTimeWithForceUpdate(): void */ public function testListingTriggersDeprecationWarning(): void { - $client = $this->createMock(Client::class); + $client = $this->createStub(Client::class); $client->method('requestGet') ->willReturn(true); $client->method('getLastResponseBody') @@ -284,7 +284,7 @@ public function testGetIdByNameMakesGetRequest(): void public function testGetIdByNameTriggersDeprecationWarning(): void { - $client = $this->createMock(Client::class); + $client = $this->createStub(Client::class); $client->method('requestGet') ->willReturn(true); $client->method('getLastResponseBody') diff --git a/tests/Unit/Api/IssueRelation/CreateTest.php b/tests/Unit/Api/IssueRelation/CreateTest.php index 004d8edb..8b486e08 100644 --- a/tests/Unit/Api/IssueRelation/CreateTest.php +++ b/tests/Unit/Api/IssueRelation/CreateTest.php @@ -86,7 +86,7 @@ public function testCreateThrowsExceptionIfResponseContainsEmptyString(): void public function testCreateThrowsExceptionWithEmptyParameters(): void { // Create the used mock objects - $client = $this->createMock(HttpClient::class); + $client = $this->createStub(HttpClient::class); // Create the object under test $api = new IssueRelation($client); @@ -105,7 +105,7 @@ public function testCreateThrowsExceptionWithEmptyParameters(): void public function testCreateThrowsExceptionIfMandatoyParametersAreMissing(array $parameters): void { // Create the used mock objects - $client = $this->createMock(HttpClient::class); + $client = $this->createStub(HttpClient::class); // Create the object under test $api = new IssueRelation($client); diff --git a/tests/Unit/Api/IssueStatusTest.php b/tests/Unit/Api/IssueStatusTest.php index 32a27bd5..4bd64210 100644 --- a/tests/Unit/Api/IssueStatusTest.php +++ b/tests/Unit/Api/IssueStatusTest.php @@ -220,7 +220,7 @@ public function testListingCallsGetEveryTimeWithForceUpdate(): void */ public function testListingTriggersDeprecationWarning(): void { - $client = $this->createMock(Client::class); + $client = $this->createStub(Client::class); $client->method('requestGet') ->willReturn(true); $client->method('getLastResponseBody') @@ -280,7 +280,7 @@ public function testGetIdByNameMakesGetRequest(): void public function testGetIdByNameTriggersDeprecationWarning(): void { - $client = $this->createMock(Client::class); + $client = $this->createStub(Client::class); $client->method('requestGet') ->willReturn(true); $client->method('getLastResponseBody') diff --git a/tests/Unit/Api/Membership/CreateTest.php b/tests/Unit/Api/Membership/CreateTest.php index 9473d818..2cbfd387 100644 --- a/tests/Unit/Api/Membership/CreateTest.php +++ b/tests/Unit/Api/Membership/CreateTest.php @@ -92,7 +92,7 @@ public function testCreateReturnsEmptyString(): void public function testCreateThrowsExceptionWithEmptyParameters(): void { // Create the used mock objects - $client = $this->createMock(HttpClient::class); + $client = $this->createStub(HttpClient::class); // Create the object under test $api = new Membership($client); @@ -111,7 +111,7 @@ public function testCreateThrowsExceptionWithEmptyParameters(): void public function testCreateThrowsExceptionIfMandatoyParametersAreMissing(array $parameters): void { // Create the used mock objects - $client = $this->createMock(HttpClient::class); + $client = $this->createStub(HttpClient::class); // Create the object under test $api = new Membership($client); diff --git a/tests/Unit/Api/Membership/UpdateTest.php b/tests/Unit/Api/Membership/UpdateTest.php index 92e348c8..f6b70d20 100644 --- a/tests/Unit/Api/Membership/UpdateTest.php +++ b/tests/Unit/Api/Membership/UpdateTest.php @@ -89,7 +89,7 @@ public function testUpdateReturnsEmptyString(): void public function testUpdateThrowsExceptionWithEmptyParameters(): void { // Create the used mock objects - $client = $this->createMock(HttpClient::class); + $client = $this->createStub(HttpClient::class); // Create the object under test $api = new Membership($client); @@ -108,7 +108,7 @@ public function testUpdateThrowsExceptionWithEmptyParameters(): void public function testUpdateThrowsExceptionIfMandatoyParametersAreMissing(array $parameters): void { // Create the used mock objects - $client = $this->createMock(HttpClient::class); + $client = $this->createStub(HttpClient::class); // Create the object under test $api = new Membership($client); diff --git a/tests/Unit/Api/Project/ArchiveTest.php b/tests/Unit/Api/Project/ArchiveTest.php index 600a635b..6a9216da 100644 --- a/tests/Unit/Api/Project/ArchiveTest.php +++ b/tests/Unit/Api/Project/ArchiveTest.php @@ -56,7 +56,7 @@ public function testArchiveThrowsUnexpectedResponseException(): void public function testArchiveWithoutIntOrStringThrowsInvalidArgumentException(): void { - $client = $this->createMock(HttpClient::class); + $client = $this->createStub(HttpClient::class); $api = new Project($client); diff --git a/tests/Unit/Api/Project/CloseTest.php b/tests/Unit/Api/Project/CloseTest.php index c48c54e8..470f517f 100644 --- a/tests/Unit/Api/Project/CloseTest.php +++ b/tests/Unit/Api/Project/CloseTest.php @@ -54,7 +54,7 @@ public function testCloseThrowsUnexpectedResponseException(): void public function testCloseWithoutIntOrStringThrowsInvalidArgumentException(): void { - $client = $this->createMock(HttpClient::class); + $client = $this->createStub(HttpClient::class); $api = new Project($client); diff --git a/tests/Unit/Api/Project/CreateTest.php b/tests/Unit/Api/Project/CreateTest.php index c44e398c..87217ceb 100644 --- a/tests/Unit/Api/Project/CreateTest.php +++ b/tests/Unit/Api/Project/CreateTest.php @@ -158,7 +158,7 @@ public function testCreateReturnsEmptyString(): void public function testCreateThrowsExceptionWithEmptyParameters(): void { // Create the used mock objects - $client = $this->createMock(HttpClient::class); + $client = $this->createStub(HttpClient::class); // Create the object under test $api = new Project($client); @@ -177,7 +177,7 @@ public function testCreateThrowsExceptionWithEmptyParameters(): void public function testCreateThrowsExceptionIfMandatoyParametersAreMissing(array $parameters): void { // Create the used mock objects - $client = $this->createMock(HttpClient::class); + $client = $this->createStub(HttpClient::class); // Create the object under test $api = new Project($client); diff --git a/tests/Unit/Api/Project/ReopenTest.php b/tests/Unit/Api/Project/ReopenTest.php index b82e2153..bb111378 100644 --- a/tests/Unit/Api/Project/ReopenTest.php +++ b/tests/Unit/Api/Project/ReopenTest.php @@ -54,7 +54,7 @@ public function testReopenThrowsUnexpectedResponseException(): void public function testReopenWithoutIntOrStringThrowsInvalidArgumentException(): void { - $client = $this->createMock(HttpClient::class); + $client = $this->createStub(HttpClient::class); $api = new Project($client); diff --git a/tests/Unit/Api/Project/UnarchiveTest.php b/tests/Unit/Api/Project/UnarchiveTest.php index 9b2b6840..e3c57b00 100644 --- a/tests/Unit/Api/Project/UnarchiveTest.php +++ b/tests/Unit/Api/Project/UnarchiveTest.php @@ -54,7 +54,7 @@ public function testUnarchiveThrowsUnexpectedResponseException(): void public function testUnarchiveWithoutIntOrStringThrowsInvalidArgumentException(): void { - $client = $this->createMock(HttpClient::class); + $client = $this->createStub(HttpClient::class); $api = new Project($client); diff --git a/tests/Unit/Api/ProjectTest.php b/tests/Unit/Api/ProjectTest.php index a100c14f..b88452ca 100644 --- a/tests/Unit/Api/ProjectTest.php +++ b/tests/Unit/Api/ProjectTest.php @@ -222,7 +222,7 @@ public function testListingCallsGetEveryTimeWithForceUpdate(): void */ public function testListingTriggersDeprecationWarning(): void { - $client = $this->createMock(Client::class); + $client = $this->createStub(Client::class); $client->method('requestGet') ->willReturn(true); $client->method('getLastResponseBody') @@ -282,7 +282,7 @@ public function testGetIdByNameMakesGetRequest(): void public function testGetIdByNameTriggersDeprecationWarning(): void { - $client = $this->createMock(Client::class); + $client = $this->createStub(Client::class); $client->method('requestGet') ->willReturn(true); $client->method('getLastResponseBody') @@ -311,12 +311,14 @@ function ($errno, $errstr): bool { public function testDeprecatedPrepareParamsXml(): void { - $client = $this->createMock(Client::class); + $client = $this->createStub(Client::class); $api = new Project($client); $method = new ReflectionMethod($api, 'prepareParamsXml'); - $method->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $method->setAccessible(true); + } $this->assertInstanceOf(SimpleXMLElement::class, $method->invoke($api, ['id' => 1])); } diff --git a/tests/Unit/Api/RoleTest.php b/tests/Unit/Api/RoleTest.php index e11ec6d9..249dba22 100644 --- a/tests/Unit/Api/RoleTest.php +++ b/tests/Unit/Api/RoleTest.php @@ -220,7 +220,7 @@ public function testListingCallsGetEveryTimeWithForceUpdate(): void */ public function testListingTriggersDeprecationWarning(): void { - $client = $this->createMock(Client::class); + $client = $this->createStub(Client::class); $client->method('requestGet') ->willReturn(true); $client->method('getLastResponseBody') diff --git a/tests/Unit/Api/TimeEntry/CreateTest.php b/tests/Unit/Api/TimeEntry/CreateTest.php index 821afdb3..ab98c04f 100644 --- a/tests/Unit/Api/TimeEntry/CreateTest.php +++ b/tests/Unit/Api/TimeEntry/CreateTest.php @@ -133,7 +133,7 @@ public function testCreateThrowsExceptionWithEmptyParameters(): void $response = 'API Response'; // Create the used mock objects - $client = $this->createMock(HttpClient::class); + $client = $this->createStub(HttpClient::class); // Create the object under test $api = new TimeEntry($client); @@ -152,7 +152,7 @@ public function testCreateThrowsExceptionWithEmptyParameters(): void public function testCreateThrowsExceptionIfValueIsMissingInParameters(array $parameters): void { // Create the used mock objects - $client = $this->createMock(HttpClient::class); + $client = $this->createStub(HttpClient::class); // Create the object under test $api = new TimeEntry($client); diff --git a/tests/Unit/Api/TimeEntryActivityTest.php b/tests/Unit/Api/TimeEntryActivityTest.php index 1a9450ee..be5d2b8e 100644 --- a/tests/Unit/Api/TimeEntryActivityTest.php +++ b/tests/Unit/Api/TimeEntryActivityTest.php @@ -171,7 +171,7 @@ public function testListingCallsGetEveryTimeWithForceUpdate(): void */ public function testListingTriggersDeprecationWarning(): void { - $client = $this->createMock(Client::class); + $client = $this->createStub(Client::class); $client->method('requestGet') ->willReturn(true); $client->method('getLastResponseBody') @@ -224,7 +224,7 @@ public function testGetIdByNameMakesGetRequest(): void public function testGetIdByNameTriggersDeprecationWarning(): void { - $client = $this->createMock(Client::class); + $client = $this->createStub(Client::class); $client->method('requestGet') ->willReturn(true); $client->method('getLastResponseBody') diff --git a/tests/Unit/Api/TrackerTest.php b/tests/Unit/Api/TrackerTest.php index 54dd54a0..a4555aa8 100644 --- a/tests/Unit/Api/TrackerTest.php +++ b/tests/Unit/Api/TrackerTest.php @@ -220,7 +220,7 @@ public function testListingCallsGetEveryTimeWithForceUpdate(): void */ public function testListingTriggersDeprecationWarning(): void { - $client = $this->createMock(Client::class); + $client = $this->createStub(Client::class); $client->method('requestGet') ->willReturn(true); $client->method('getLastResponseBody') @@ -280,7 +280,7 @@ public function testGetIdByNameMakesGetRequest(): void public function testGgetIdByNameTriggersDeprecationWarning(): void { - $client = $this->createMock(Client::class); + $client = $this->createStub(Client::class); $client->method('requestGet') ->willReturn(true); $client->method('getLastResponseBody') diff --git a/tests/Unit/Api/User/CreateTest.php b/tests/Unit/Api/User/CreateTest.php index 538864a7..4c6f6e4d 100644 --- a/tests/Unit/Api/User/CreateTest.php +++ b/tests/Unit/Api/User/CreateTest.php @@ -120,7 +120,7 @@ public function testCreateThrowsExceptionWithEmptyParameters(): void $response = 'API Response'; // Create the used mock objects - $client = $this->createMock(HttpClient::class); + $client = $this->createStub(HttpClient::class); // Create the object under test $api = new User($client); @@ -139,7 +139,7 @@ public function testCreateThrowsExceptionWithEmptyParameters(): void public function testCreateThrowsExceptionIfValueIsMissingInParameters(array $parameters): void { // Create the used mock objects - $client = $this->createMock(HttpClient::class); + $client = $this->createStub(HttpClient::class); // Create the object under test $api = new User($client); diff --git a/tests/Unit/Api/UserTest.php b/tests/Unit/Api/UserTest.php index b76f8176..71a44ce1 100644 --- a/tests/Unit/Api/UserTest.php +++ b/tests/Unit/Api/UserTest.php @@ -85,7 +85,7 @@ public function testGetIdByUsernameMakesGetRequest(): void public function testGetIdByUsernameTriggersDeprecationWarning(): void { - $client = $this->createMock(Client::class); + $client = $this->createStub(Client::class); $client->method('requestGet') ->willReturn(true); $client->method('getLastResponseBody') @@ -321,7 +321,7 @@ public function testListingCallsGetEveryTimeWithForceUpdate(): void */ public function testListingTriggersDeprecationWarning(): void { - $client = $this->createMock(Client::class); + $client = $this->createStub(Client::class); $client->method('requestGet') ->willReturn(true); $client->method('getLastResponseBody') diff --git a/tests/Unit/Api/Version/CreateTest.php b/tests/Unit/Api/Version/CreateTest.php index 7632e805..a7bced6b 100644 --- a/tests/Unit/Api/Version/CreateTest.php +++ b/tests/Unit/Api/Version/CreateTest.php @@ -157,7 +157,7 @@ public function testCreateReturnsEmptyString(): void public function testCreateWithEmptyParametersThrowsMissingParameterException(): void { // Create the used mock objects - $client = $this->createMock(HttpClient::class); + $client = $this->createStub(HttpClient::class); // Create the object under test $api = new Version($client); @@ -177,7 +177,7 @@ public function testCreateWithMissingNameInParametersThrowsMissingParameterExcep ]; // Create the used mock objects - $client = $this->createMock(HttpClient::class); + $client = $this->createStub(HttpClient::class); // Create the object under test $api = new Version($client); @@ -199,7 +199,7 @@ public function testCreateWithInvalidStatusThrowsInvalidParameterException(): vo ]; // Create the used mock objects - $client = $this->createMock(HttpClient::class); + $client = $this->createStub(HttpClient::class); // Create the object under test $api = new Version($client); diff --git a/tests/Unit/Api/Version/ListNamesByProjectTest.php b/tests/Unit/Api/Version/ListNamesByProjectTest.php index 2281727a..93243535 100644 --- a/tests/Unit/Api/Version/ListNamesByProjectTest.php +++ b/tests/Unit/Api/Version/ListNamesByProjectTest.php @@ -118,7 +118,7 @@ public function testListNamesByProjectCallsHttpClientOnlyOnce(): void #[DataProviderExternal(TestDataProvider::class, 'getInvalidProjectIdentifiers')] public function testListNamesByProjectWithWrongProjectIdentifierThrowsException($projectIdentifier): void { - $api = new Version($this->createMock(HttpClient::class)); + $api = new Version($this->createStub(HttpClient::class)); $this->expectException(InvalidParameterException::class); $this->expectExceptionMessage('Redmine\Api\Version::listNamesByProject(): Argument #1 ($projectIdentifier) must be of type int or string'); diff --git a/tests/Unit/Api/Version/UpdateTest.php b/tests/Unit/Api/Version/UpdateTest.php index 60253ded..7a30844a 100644 --- a/tests/Unit/Api/Version/UpdateTest.php +++ b/tests/Unit/Api/Version/UpdateTest.php @@ -183,7 +183,7 @@ public function testUpdateWithInvalidStatusThrowsInvalidParameterException(): vo ]; // Create the used mock objects - $client = $this->createMock(HttpClient::class); + $client = $this->createStub(HttpClient::class); // Create the object under test $api = new Version($client); @@ -205,7 +205,7 @@ public function testUpdateWithInvalidSharingThrowsInvalidParameterException(): v ]; // Create the used mock objects - $client = $this->createMock(HttpClient::class); + $client = $this->createStub(HttpClient::class); // Create the object under test $api = new Version($client); diff --git a/tests/Unit/Api/VersionTest.php b/tests/Unit/Api/VersionTest.php index 1ab3fd59..e0b9f614 100644 --- a/tests/Unit/Api/VersionTest.php +++ b/tests/Unit/Api/VersionTest.php @@ -251,7 +251,7 @@ public function testListingCallsGetEveryTimeWithForceUpdate(): void */ public function testListingTriggersDeprecationWarning(): void { - $client = $this->createMock(Client::class); + $client = $this->createStub(Client::class); $client->method('requestGet') ->willReturn(true); $client->method('getLastResponseBody') @@ -311,7 +311,7 @@ public function testGetIdByNameMakesGetRequest(): void public function testGetIdByNameTriggersDeprecationWarning(): void { - $client = $this->createMock(Client::class); + $client = $this->createStub(Client::class); $client->method('requestGet') ->willReturn(true); $client->method('getLastResponseBody') @@ -353,7 +353,7 @@ public function testCreateThrowsExceptionWithInvalidSharing(string $sharingValue ]; // Create the used mock objects - $client = $this->createMock(Client::class); + $client = $this->createStub(Client::class); // Create the object under test $api = new Version($client); diff --git a/tests/Unit/Client/NativeCurlClient/RequestTest.php b/tests/Unit/Client/NativeCurlClient/RequestTest.php index 869c9e59..84fb57af 100644 --- a/tests/Unit/Client/NativeCurlClient/RequestTest.php +++ b/tests/Unit/Client/NativeCurlClient/RequestTest.php @@ -24,7 +24,7 @@ public function testRequestReturnsCorrectResponse(string $method, string $data, { $namespace = 'Redmine\Client'; - $curl = $this->createMock(stdClass::class); + $curl = $this->createStub(stdClass::class); $curlInit = $this->getFunctionMock($namespace, 'curl_init'); $curlInit->expects($this->exactly(1))->willReturn($curl); @@ -50,13 +50,11 @@ public function testRequestReturnsCorrectResponse(string $method, string $data, 'access_token', ); - /** @var Request&\PHPUnit\Framework\MockObject\MockObject */ - $request = $this->createConfiguredMock(Request::class, [ - 'getMethod' => $method, - 'getPath' => '/path', - 'getContentType' => $contentType, - 'getContent' => $data, - ]); + $request = $this->createStub(Request::class); + $request->method('getMethod')->willReturn($method); + $request->method('getPath')->willReturn('/path'); + $request->method('getContentType')->willReturn($contentType); + $request->method('getContent')->willReturn($data); $response = $client->request($request); @@ -97,7 +95,7 @@ public function testRequestWithUploadAndFilepathReturnsCorrectResponse(): void { $namespace = 'Redmine\Client'; - $curl = $this->createMock(stdClass::class); + $curl = $this->createStub(stdClass::class); $curlInit = $this->getFunctionMock($namespace, 'curl_init'); $curlInit->expects($this->exactly(1))->willReturn($curl); @@ -137,13 +135,11 @@ function ($errno, $errstr): bool { E_USER_DEPRECATED, ); - /** @var Request&\PHPUnit\Framework\MockObject\MockObject */ - $request = $this->createConfiguredMock(Request::class, [ - 'getMethod' => 'POST', - 'getPath' => '/uploads.json', - 'getContentType' => 'application/octet-stream', - 'getContent' => realpath(__DIR__ . '/../../../Fixtures/testfile_01.txt'), - ]); + $request = $this->createStub(Request::class); + $request->method('getMethod')->willReturn('POST'); + $request->method('getPath')->willReturn('/uploads.json'); + $request->method('getContentType')->willReturn('application/octet-stream'); + $request->method('getContent')->willReturn(realpath(__DIR__ . '/../../../Fixtures/testfile_01.txt')); $response = $client->request($request); diff --git a/tests/Unit/Client/NativeCurlClientTest.php b/tests/Unit/Client/NativeCurlClientTest.php index 1a03d056..bd0c03f5 100644 --- a/tests/Unit/Client/NativeCurlClientTest.php +++ b/tests/Unit/Client/NativeCurlClientTest.php @@ -178,7 +178,7 @@ public function testStartAndStopImpersonateUser(): void CURLOPT_RETURNTRANSFER => 1, ]; - $curl = $this->createMock(stdClass::class); + $curl = $this->createStub(stdClass::class); $curlInit = $this->getFunctionMock(self::__NAMESPACE__, 'curl_init'); $curlInit->expects($this->exactly(3))->willReturn($curl); @@ -233,7 +233,7 @@ public function testSetSslVersion(): void CURLOPT_RETURNTRANSFER => 1, ]; - $curl = $this->createMock(stdClass::class); + $curl = $this->createStub(stdClass::class); $curlInit = $this->getFunctionMock(self::__NAMESPACE__, 'curl_init'); $curlInit->expects($this->exactly(3))->willReturn($curl); @@ -289,7 +289,7 @@ public function testSetSslVerifypeer(): void CURLOPT_RETURNTRANSFER => 1, ]; - $curl = $this->createMock(stdClass::class); + $curl = $this->createStub(stdClass::class); $curlInit = $this->getFunctionMock(self::__NAMESPACE__, 'curl_init'); $curlInit->expects($this->exactly(3))->willReturn($curl); @@ -345,7 +345,7 @@ public function testSetSslVerifyhost(): void CURLOPT_RETURNTRANSFER => 1, ]; - $curl = $this->createMock(stdClass::class); + $curl = $this->createStub(stdClass::class); $curlInit = $this->getFunctionMock(self::__NAMESPACE__, 'curl_init'); $curlInit->expects($this->exactly(3))->willReturn($curl); @@ -402,7 +402,7 @@ public function testSetCustomHttpHeaders(): void CURLOPT_RETURNTRANSFER => 1, ]; - $curl = $this->createMock(stdClass::class); + $curl = $this->createStub(stdClass::class); $curlInit = $this->getFunctionMock(self::__NAMESPACE__, 'curl_init'); $curlInit->expects($this->exactly(3))->willReturn($curl); @@ -463,7 +463,7 @@ public function testSetCustomHost(): void CURLOPT_RETURNTRANSFER => 1, ]; - $curl = $this->createMock(stdClass::class); + $curl = $this->createStub(stdClass::class); $curlInit = $this->getFunctionMock(self::__NAMESPACE__, 'curl_init'); $curlInit->expects($this->exactly(3))->willReturn($curl); @@ -520,7 +520,7 @@ public function testSetPort(): void CURLOPT_RETURNTRANSFER => 1, ]; - $curl = $this->createMock(stdClass::class); + $curl = $this->createStub(stdClass::class); $curlInit = $this->getFunctionMock(self::__NAMESPACE__, 'curl_init'); $curlInit->expects($this->exactly(3))->willReturn($curl); @@ -588,7 +588,7 @@ public function testCustomPortWillSetFromSchema(): void CURLOPT_RETURNTRANSFER => 1, ]; - $curl = $this->createMock(stdClass::class); + $curl = $this->createStub(stdClass::class); $curlInit = $this->getFunctionMock(self::__NAMESPACE__, 'curl_init'); $curlInit->expects($this->exactly(1))->willReturn($curl); @@ -638,7 +638,7 @@ public function testCustomPortWillSetFromUrl(): void CURLOPT_RETURNTRANSFER => 1, ]; - $curl = $this->createMock(stdClass::class); + $curl = $this->createStub(stdClass::class); $curlInit = $this->getFunctionMock(self::__NAMESPACE__, 'curl_init'); $curlInit->expects($this->exactly(1))->willReturn($curl); @@ -679,7 +679,7 @@ public function testCustomPortWillSetFromUrl(): void #[DataProvider('getRequestReponseData')] public function testRequestsReturnsCorrectContent(string $method, string $data, bool $boolReturn, int $statusCode, string $contentType, string $content): void { - $curl = $this->createMock(stdClass::class); + $curl = $this->createStub(stdClass::class); $curlInit = $this->getFunctionMock(self::__NAMESPACE__, 'curl_init'); $curlInit->expects($this->exactly(1))->willReturn($curl); @@ -899,7 +899,7 @@ public function testHandlingOfResponseWithoutContent(): void $statusCode = 204; $contentType = null; - $curl = $this->createMock(stdClass::class); + $curl = $this->createStub(stdClass::class); $curlInit = $this->getFunctionMock(self::__NAMESPACE__, 'curl_init'); $curlInit->expects($this->exactly(1))->willReturn($curl); @@ -933,7 +933,7 @@ public function testHandlingOfResponseWithoutContent(): void public function testCurlErrorThrowsException(): void { - $curl = $this->createMock(stdClass::class); + $curl = $this->createStub(stdClass::class); $curlInit = $this->getFunctionMock(self::__NAMESPACE__, 'curl_init'); $curlInit->expects($this->exactly(1))->willReturn($curl); diff --git a/tests/Unit/Client/Psr18Client/RequestTest.php b/tests/Unit/Client/Psr18Client/RequestTest.php index 2298d944..3d44aaea 100644 --- a/tests/Unit/Client/Psr18Client/RequestTest.php +++ b/tests/Unit/Client/Psr18Client/RequestTest.php @@ -27,40 +27,37 @@ class RequestTest extends TestCase #[DataProvider('getRequestReponseData')] public function testRequestReturnsCorrectResponse(string $method, string $data, int $statusCode, string $contentType, string $content): void { - $httpClient = $this->createConfiguredMock(ClientInterface::class, [ - 'sendRequest' => $this->createConfiguredMock(ResponseInterface::class, [ - 'getStatusCode' => $statusCode, - 'getHeaderLine' => $contentType, - 'getBody' => $this->createConfiguredMock(StreamInterface::class, [ - '__toString' => $content, - ]), - ]), - ]); - - $requestFactory = $this->createConfiguredMock(RequestFactoryInterface::class, [ - 'createRequest' => (function (): \PHPUnit\Framework\MockObject\MockObject { - $request = $this->createMock(RequestInterface::class); - $request->method('withHeader')->willReturn($request); - $request->method('withBody')->willReturn($request); - - return $request; - })(), - ]); + $stream = $this->createStub(StreamInterface::class); + $stream->method('__toString')->willReturn($content); + + $response = $this->createStub(ResponseInterface::class); + $response->method('getStatusCode')->willReturn($statusCode); + $response->method('getHeaderLine')->willReturn($contentType); + $response->method('getBody')->willReturn($stream); + + $httpClient = $this->createStub(ClientInterface::class); + $httpClient->method('sendRequest')->willReturn($response); + + $request = $this->createStub(RequestInterface::class); + $request->method('withHeader')->willReturn($request); + $request->method('withBody')->willReturn($request); + + $requestFactory = $this->createStub(RequestFactoryInterface::class); + $requestFactory->method('createRequest')->willReturn($request); $client = new Psr18Client( $httpClient, $requestFactory, - $this->createMock(StreamFactoryInterface::class), + $this->createStub(StreamFactoryInterface::class), 'http://test.local', 'access_token', ); - $request = $this->createConfiguredMock(Request::class, [ - 'getMethod' => $method, - 'getPath' => '/path', - 'getContentType' => $contentType, - 'getContent' => $data, - ]); + $request = $this->createStub(Request::class); + $request->method('getMethod')->willReturn($method); + $request->method('getPath')->willReturn('/path'); + $request->method('getContentType')->willReturn($contentType); + $request->method('getContent')->willReturn($data); $response = $client->request($request); @@ -104,30 +101,26 @@ public function testRequestThrowsClientException(): void new class ('error message') extends Exception implements ClientExceptionInterface {}, ); - $requestFactory = $this->createConfiguredMock(RequestFactoryInterface::class, [ - 'createRequest' => (function (): \PHPUnit\Framework\MockObject\MockObject { - $request = $this->createMock(RequestInterface::class); - $request->method('withHeader')->willReturn($request); - $request->method('withBody')->willReturn($request); + $request = $this->createStub(RequestInterface::class); + $request->method('withHeader')->willReturn($request); + $request->method('withBody')->willReturn($request); - return $request; - })(), - ]); + $requestFactory = $this->createStub(RequestFactoryInterface::class); + $requestFactory->method('createRequest')->willReturn($request); $client = new Psr18Client( $httpClient, $requestFactory, - $this->createMock(StreamFactoryInterface::class), + $this->createStub(StreamFactoryInterface::class), 'http://test.local', 'access_token', ); - $request = $this->createConfiguredMock(Request::class, [ - 'getMethod' => 'GET', - 'getPath' => '/path', - 'getContentType' => 'application/json', - 'getContent' => '', - ]); + $request = $this->createStub(Request::class); + $request->method('getMethod')->willReturn('GET'); + $request->method('getPath')->willReturn('/path'); + $request->method('getContentType')->willReturn('application/json'); + $request->method('getContent')->willReturn(''); $this->expectException(ClientException::class); $this->expectExceptionMessage('error message'); diff --git a/tests/Unit/Client/Psr18ClientTest.php b/tests/Unit/Client/Psr18ClientTest.php index 0b596576..78cdd8e6 100644 --- a/tests/Unit/Client/Psr18ClientTest.php +++ b/tests/Unit/Client/Psr18ClientTest.php @@ -27,9 +27,9 @@ class Psr18ClientTest extends TestCase public function testShouldPassApiKeyToConstructor(): void { $client = new Psr18Client( - $this->createMock(ClientInterface::class), - $this->createMock(RequestFactoryInterface::class), - $this->createMock(StreamFactoryInterface::class), + $this->createStub(ClientInterface::class), + $this->createStub(RequestFactoryInterface::class), + $this->createStub(StreamFactoryInterface::class), 'http://test.local', 'access_token', ); @@ -41,34 +41,35 @@ public function testShouldPassApiKeyToConstructor(): void public function testServerRequestFactoryIsAcceptedInConstructorForBC(): void { - $client = new Psr18Client( - $this->createMock(ClientInterface::class), - $this->createConfiguredMock(ServerRequestFactoryInterface::class, [ - 'createServerRequest' => (function (): \PHPUnit\Framework\MockObject\MockObject { - $request = $this->createMock(ServerRequestInterface::class); - $request->method('withHeader')->willReturn($request); - $request->method('withBody')->willReturn($request); - - return $request; - })(), - ]), - $this->createMock(StreamFactoryInterface::class), + // PHPUnit 10 compatible way to test trigger_error(). + set_error_handler( + function ($errno, $errstr): bool { + $this->assertSame( + 'Redmine\Client\Psr18Client::__construct(): Providing Argument #2 ($requestFactory) as Psr\Http\Message\ServerRequestFactoryInterface is deprecated since v2.3.0, please provide as Psr\Http\Message\RequestFactoryInterface instead.', + $errstr, + ); + + restore_error_handler(); + return true; + }, + E_USER_DEPRECATED, + ); + + new Psr18Client( + $this->createStub(ClientInterface::class), + $this->createStub(ServerRequestFactoryInterface::class), + $this->createStub(StreamFactoryInterface::class), 'http://test.local', 'access_token', ); - - $this->assertInstanceOf(Psr18Client::class, $client); - $this->assertInstanceOf(Client::class, $client); - - $client->requestGet('/path.xml'); } public function testShouldPassUsernameAndPasswordToConstructor(): void { $client = new Psr18Client( - $this->createMock(ClientInterface::class), - $this->createMock(RequestFactoryInterface::class), - $this->createMock(StreamFactoryInterface::class), + $this->createStub(ClientInterface::class), + $this->createStub(RequestFactoryInterface::class), + $this->createStub(StreamFactoryInterface::class), 'http://test.local', 'username', 'password', @@ -81,9 +82,9 @@ public function testShouldPassUsernameAndPasswordToConstructor(): void public function testGetLastResponseStatusCodeIsInitialZero(): void { $client = new Psr18Client( - $this->createMock(ClientInterface::class), - $this->createMock(RequestFactoryInterface::class), - $this->createMock(StreamFactoryInterface::class), + $this->createStub(ClientInterface::class), + $this->createStub(RequestFactoryInterface::class), + $this->createStub(StreamFactoryInterface::class), 'http://test.local', 'access_token', ); @@ -94,9 +95,9 @@ public function testGetLastResponseStatusCodeIsInitialZero(): void public function testGetLastResponseStatusCodeTriggersDeprecationWarning(): void { $client = new Psr18Client( - $this->createMock(ClientInterface::class), - $this->createMock(RequestFactoryInterface::class), - $this->createMock(StreamFactoryInterface::class), + $this->createStub(ClientInterface::class), + $this->createStub(RequestFactoryInterface::class), + $this->createStub(StreamFactoryInterface::class), 'http://test.local', 'access_token', ); @@ -121,9 +122,9 @@ function ($errno, $errstr): bool { public function testGetLastResponseContentTypeIsInitialEmpty(): void { $client = new Psr18Client( - $this->createMock(ClientInterface::class), - $this->createMock(RequestFactoryInterface::class), - $this->createMock(StreamFactoryInterface::class), + $this->createStub(ClientInterface::class), + $this->createStub(RequestFactoryInterface::class), + $this->createStub(StreamFactoryInterface::class), 'http://test.local', 'access_token', ); @@ -134,9 +135,9 @@ public function testGetLastResponseContentTypeIsInitialEmpty(): void public function testGetLastResponseContentTypeTriggersDeprecationWarning(): void { $client = new Psr18Client( - $this->createMock(ClientInterface::class), - $this->createMock(RequestFactoryInterface::class), - $this->createMock(StreamFactoryInterface::class), + $this->createStub(ClientInterface::class), + $this->createStub(RequestFactoryInterface::class), + $this->createStub(StreamFactoryInterface::class), 'http://test.local', 'access_token', ); @@ -161,9 +162,9 @@ function ($errno, $errstr): bool { public function testGetLastResponseBodyIsInitialEmpty(): void { $client = new Psr18Client( - $this->createMock(ClientInterface::class), - $this->createMock(RequestFactoryInterface::class), - $this->createMock(StreamFactoryInterface::class), + $this->createStub(ClientInterface::class), + $this->createStub(RequestFactoryInterface::class), + $this->createStub(StreamFactoryInterface::class), 'http://test.local', 'access_token', ); @@ -174,9 +175,9 @@ public function testGetLastResponseBodyIsInitialEmpty(): void public function testGetLastResponseBodyTriggersDeprecationWarning(): void { $client = new Psr18Client( - $this->createMock(ClientInterface::class), - $this->createMock(RequestFactoryInterface::class), - $this->createMock(StreamFactoryInterface::class), + $this->createStub(ClientInterface::class), + $this->createStub(RequestFactoryInterface::class), + $this->createStub(StreamFactoryInterface::class), 'http://test.local', 'access_token', ); @@ -210,13 +211,13 @@ public function testStartAndStopImpersonateUser(): void ['X-Redmine-API-Key', 'access_token', $request], ]); - $requestFactory = $this->createMock(RequestFactoryInterface::class); + $requestFactory = $this->createStub(RequestFactoryInterface::class); $requestFactory->method('createRequest')->willReturn($request); $client = new Psr18Client( - $this->createMock(ClientInterface::class), + $this->createStub(ClientInterface::class), $requestFactory, - $this->createMock(StreamFactoryInterface::class), + $this->createStub(StreamFactoryInterface::class), 'http://test.local', 'access_token', ); @@ -230,22 +231,22 @@ public function testStartAndStopImpersonateUser(): void public function testRequestGetReturnsFalse(): void { - $response = $this->createMock(ResponseInterface::class); + $response = $this->createStub(ResponseInterface::class); $response->method('getStatusCode')->willReturn(404); - $httpClient = $this->createMock(ClientInterface::class); + $httpClient = $this->createStub(ClientInterface::class); $httpClient->method('sendRequest')->willReturn($response); - $request = $this->createMock(RequestInterface::class); + $request = $this->createStub(RequestInterface::class); $request->method('withHeader')->willReturn($request); - $requestFactory = $this->createMock(RequestFactoryInterface::class); + $requestFactory = $this->createStub(RequestFactoryInterface::class); $requestFactory->method('createRequest')->willReturn($request); $client = new Psr18Client( $httpClient, $requestFactory, - $this->createMock(StreamFactoryInterface::class), + $this->createStub(StreamFactoryInterface::class), 'http://test.local', 'access_token', ); @@ -259,28 +260,28 @@ public function testRequestGetReturnsFalse(): void #[DataProvider('getRequestReponseData')] public function testRequestsReturnsCorrectContent(string $method, string $data, bool $boolReturn, int $statusCode, string $contentType, string $content): void { - $stream = $this->createMock(StreamInterface::class); + $stream = $this->createStub(StreamInterface::class); $stream->method('__toString')->willReturn($content); - $response = $this->createMock(ResponseInterface::class); + $response = $this->createStub(ResponseInterface::class); $response->method('getStatusCode')->willReturn($statusCode); $response->method('getHeaderLine')->willReturn($contentType); $response->method('getBody')->willReturn($stream); - $httpClient = $this->createMock(ClientInterface::class); + $httpClient = $this->createStub(ClientInterface::class); $httpClient->method('sendRequest')->willReturn($response); - $request = $this->createMock(RequestInterface::class); + $request = $this->createStub(RequestInterface::class); $request->method('withHeader')->willReturn($request); $request->method('withBody')->willReturn($request); - $requestFactory = $this->createMock(RequestFactoryInterface::class); + $requestFactory = $this->createStub(RequestFactoryInterface::class); $requestFactory->method('createRequest')->willReturn($request); $client = new Psr18Client( $httpClient, $requestFactory, - $this->createMock(StreamFactoryInterface::class), + $this->createStub(StreamFactoryInterface::class), 'http://test.local', 'access_token', ); @@ -319,15 +320,15 @@ public static function getRequestReponseData(): array public function testRequestGetTriggersDeprecationWarning(): void { - $requestFactory = $this->createMock(RequestFactoryInterface::class); + $requestFactory = $this->createStub(RequestFactoryInterface::class); $requestFactory->method('createRequest')->willThrowException( - $this->createMock(ClientException::class), + $this->createStub(ClientException::class), ); $client = new Psr18Client( - $this->createMock(ClientInterface::class), + $this->createStub(ClientInterface::class), $requestFactory, - $this->createMock(StreamFactoryInterface::class), + $this->createStub(StreamFactoryInterface::class), 'http://test.local', 'access_token', ); @@ -354,15 +355,15 @@ function ($errno, $errstr): bool { public function testRequestPostTriggersDeprecationWarning(): void { - $requestFactory = $this->createMock(RequestFactoryInterface::class); + $requestFactory = $this->createStub(RequestFactoryInterface::class); $requestFactory->method('createRequest')->willThrowException( - $this->createMock(ClientException::class), + $this->createStub(ClientException::class), ); $client = new Psr18Client( - $this->createMock(ClientInterface::class), + $this->createStub(ClientInterface::class), $requestFactory, - $this->createMock(StreamFactoryInterface::class), + $this->createStub(StreamFactoryInterface::class), 'http://test.local', 'access_token', ); @@ -389,15 +390,15 @@ function ($errno, $errstr): bool { public function testRequestPutTriggersDeprecationWarning(): void { - $requestFactory = $this->createMock(RequestFactoryInterface::class); + $requestFactory = $this->createStub(RequestFactoryInterface::class); $requestFactory->method('createRequest')->willThrowException( - $this->createMock(ClientException::class), + $this->createStub(ClientException::class), ); $client = new Psr18Client( - $this->createMock(ClientInterface::class), + $this->createStub(ClientInterface::class), $requestFactory, - $this->createMock(StreamFactoryInterface::class), + $this->createStub(StreamFactoryInterface::class), 'http://test.local', 'access_token', ); @@ -424,15 +425,15 @@ function ($errno, $errstr): bool { public function testRequestDeleteTriggersDeprecationWarning(): void { - $requestFactory = $this->createMock(RequestFactoryInterface::class); + $requestFactory = $this->createStub(RequestFactoryInterface::class); $requestFactory->method('createRequest')->willThrowException( - $this->createMock(ClientException::class), + $this->createStub(ClientException::class), ); $client = new Psr18Client( - $this->createMock(ClientInterface::class), + $this->createStub(ClientInterface::class), $requestFactory, - $this->createMock(StreamFactoryInterface::class), + $this->createStub(StreamFactoryInterface::class), 'http://test.local', 'access_token', ); @@ -464,9 +465,9 @@ function ($errno, $errstr): bool { public function testGetApiShouldReturnApiInstance(string $apiName, string $class): void { $client = new Psr18Client( - $this->createMock(ClientInterface::class), - $this->createMock(RequestFactoryInterface::class), - $this->createMock(StreamFactoryInterface::class), + $this->createStub(ClientInterface::class), + $this->createStub(RequestFactoryInterface::class), + $this->createStub(StreamFactoryInterface::class), 'http://test.local', 'access_token', ); @@ -505,10 +506,10 @@ public function testCreateWithoutFactoryThrowsException(): void $this->expectExceptionMessage('Redmine\Client\Psr18Client::__construct(): Argument #2 ($requestFactory) must be of type Psr\Http\Message\RequestFactoryInterface'); new Psr18Client( - $this->createMock(ClientInterface::class), + $this->createStub(ClientInterface::class), /** @phpstan-ignore-next-line We are providing an invalid parameter to test the exception */ new stdClass(), - $this->createMock(StreamFactoryInterface::class), + $this->createStub(StreamFactoryInterface::class), 'http://test.local', 'access_token', ); @@ -517,9 +518,9 @@ public function testCreateWithoutFactoryThrowsException(): void public function testGetApiShouldThrowException(): void { $client = new Psr18Client( - $this->createMock(ClientInterface::class), - $this->createMock(RequestFactoryInterface::class), - $this->createMock(StreamFactoryInterface::class), + $this->createStub(ClientInterface::class), + $this->createStub(RequestFactoryInterface::class), + $this->createStub(StreamFactoryInterface::class), 'http://test.local', 'access_token', ); diff --git a/tests/Unit/Exception/UnexpectedResponseExceptionTest.php b/tests/Unit/Exception/UnexpectedResponseExceptionTest.php index 2633526c..43e83296 100644 --- a/tests/Unit/Exception/UnexpectedResponseExceptionTest.php +++ b/tests/Unit/Exception/UnexpectedResponseExceptionTest.php @@ -14,7 +14,7 @@ class UnexpectedResponseExceptionTest extends TestCase { public function testCreateReturnsException(): void { - $response = $this->createMock(Response::class); + $response = $this->createStub(Response::class); $exception = UnexpectedResponseException::create($response); @@ -24,7 +24,7 @@ public function testCreateReturnsException(): void public function testCreateWithThrowable(): void { - $response = $this->createMock(Response::class); + $response = $this->createStub(Response::class); $throwable = new Exception('message', 5); $exception = UnexpectedResponseException::create($response, $throwable); @@ -35,7 +35,7 @@ public function testCreateWithThrowable(): void public function testGetResponseReturnsResponse(): void { - $response = $this->createMock(Response::class); + $response = $this->createStub(Response::class); $exception = UnexpectedResponseException::create($response);