Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
39 changes: 39 additions & 0 deletions .docker/PHP85-Dockerfile
Original file line number Diff line number Diff line change
@@ -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/
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
beStrictAboutCoverageMetadata="false"
beStrictAboutOutputDuringTests="true"
displayDetailsOnIncompleteTests="true"
displayDetailsOnPhpunitDeprecations="true"
displayDetailsOnSkippedTests="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnPhpunitDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
Expand Down
10 changes: 8 additions & 2 deletions src/Redmine/Client/NativeCurlClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}
Expand Down
11 changes: 9 additions & 2 deletions tests/Fixtures/AssertingHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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']);
Expand Down
8 changes: 4 additions & 4 deletions tests/Integration/Psr18ClientRequestGenerationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion tests/RedmineExtension/RedmineInstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
10 changes: 7 additions & 3 deletions tests/Unit/Api/AbstractApi/DeleteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');
Expand Down
16 changes: 11 additions & 5 deletions tests/Unit/Api/AbstractApi/GetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)) {
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 7 additions & 3 deletions tests/Unit/Api/AbstractApi/PostTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', '');
Expand All @@ -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', '');
Expand Down
10 changes: 7 additions & 3 deletions tests/Unit/Api/AbstractApi/PutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', '');
Expand All @@ -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', '');
Expand Down
Loading