Skip to content

✅ Fix PHPUnit cURL calls to iTop within Combodo's Docker dev. env. with PHP version autodetection#869

Merged
Molkobain merged 1 commit intosupport/3.2from
issue/fix-curl-calls-to-itop-within-docker-dev-environment-with-php-version-autodetection
Apr 7, 2026
Merged

✅ Fix PHPUnit cURL calls to iTop within Combodo's Docker dev. env. with PHP version autodetection#869
Molkobain merged 1 commit intosupport/3.2from
issue/fix-curl-calls-to-itop-within-docker-dev-environment-with-php-version-autodetection

Conversation

@Molkobain
Copy link
Copy Markdown
Contributor

@Molkobain Molkobain commented Apr 3, 2026

Base information

Question Answer
Related to a SourceForge thread / Another PR / Combodo ticket? N.A.
Type of change? Bug fix

Symptom (bug) / Objective (enhancement)

PHPUnit tests failing when run in Combodo's Docker dev/test environments when PHP version is autodetected, cURL calls from PHPUnit to iTop can fail because the target PHP version is not provided.

Symptom can vary depending on the unit test, for example with \Combodo\iTop\Test\UnitTest\Webservices\RestTest::testPostJSONDataAsCurlFile() you have the following error:

Trying to access array offset on value of type null
 /var/www/html/itop/dev-support-3.2/tests/php-unit-tests/unitary-tests/webservices/RestTest.php:102

The objective is to pass the running PHP version so the endpoint can be resolved correctly; without having to manually set the corresponding port in the app_root_url.

Reproduction procedure (bug)

  1. On iTop suport/3.2 branch
  2. With Combodo's Docker environment
  3. With app_root_url set to https with PHP version autodection
  4. Run unit test \Combodo\iTop\Test\UnitTest\Webservices\RestTest::testPostJSONDataAsCurlFile()
  5. See that you ahve the following error

Cause (bug)

When using PHP version autodetection in the app_root_url, the PHP version to use ust be passed through an HTTP header, which is done through a browser extension when using the browser, but isn't present for programatical calls.

  • PHP version autodetection URL examples:
    • https://localhost/itop
    • http://localhost:88/itop
  • PHP version passed with the URL examples:
    • http://localhost:83/itop for PHP 8.3
    • http://localhost:84/itop for PHP 8.4
    • ...

Proposed solution (bug and enhancement)

Add an X-PHP-Version header in \Combodo\iTop\Test\UnitTest\ItopTestCase::CallItopUri(), derived from PHP_VERSION (major+minor, e.g. 8.3.x →83), and pass it through to \Combodo\iTop\Test\UnitTest\ItopTestCase::CallUrl. This enables automatic PHP version detection in Docker dev/test environments.

Checklist before requesting a review

  • I have performed a self-review of my code
  • I have tested all changes I made on an iTop instance
  • I have added a unit test, otherwise I have explained why I couldn't
  • Is the PR clear and detailed enough so anyone can understand digging in the code?

@Molkobain Molkobain self-assigned this Apr 3, 2026
@Molkobain Molkobain added the bug Something isn't working label Apr 3, 2026
@CombodoApplicationsAccount CombodoApplicationsAccount added the internal Work made by Combodo label Apr 3, 2026
@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Apr 3, 2026

Greptile Summary

This PR fixes cURL calls from PHPUnit tests to iTop in Docker dev environments where PHP version autodetection is active. It adds an X-PHP-Version HTTP header (e.g. 83 for PHP 8.3) to all CallItopUri() requests, derived at runtime from PHP_VERSION, so the reverse proxy can route to the correct PHP container without requiring a hardcoded port in app_root_url.

Confidence Score: 5/5

Safe to merge — minimal, well-scoped change to a test utility with correct null-safety handling and no impact on production code.

The change is confined to a single test helper method, null coalescing is applied correctly for the nullable ?array $aCurlOptions parameter, existing headers are preserved via array_merge, and the version string construction (major+minor concatenation from PHP_VERSION) matches the Docker port-routing convention described in the PR. No P0/P1 findings.

No files require special attention.

Important Files Changed

Filename Overview
tests/php-unit-tests/src/BaseTestCase/ItopTestCase.php Adds X-PHP-Version HTTP header in CallItopUri() by deriving major+minor from PHP_VERSION, enabling Docker dev-environment PHP autodetection without requiring a hardcoded port in app_root_url.

Sequence Diagram

sequenceDiagram
    participant Test as PHPUnit Test
    participant CIU as CallItopUri()
    participant CU as CallUrl()
    participant iTop as iTop Endpoint (Docker)

    Test->>CIU: CallItopUri(sUri, aPostFields, aCurlOptions)
    CIU->>CIU: Build sUrl from app_root_url + sUri
    CIU->>CIU: Derive X-PHP-Version from PHP_VERSION<br/>(e.g. "8.3.x" → "83")
    CIU->>CIU: Merge X-PHP-Version into aCurlOptions[CURLOPT_HTTPHEADER]
    CIU->>CU: CallUrl(sUrl, aPostFields, aCurlOptions)
    CU->>CU: curl_init(), curl_setopt_array(ch, aCurlOptions)
    CU->>iTop: HTTP request + X-PHP-Version: 83 header
    iTop-->>CU: Response (routed to correct PHP version container)
    CU-->>CIU: sOutput
    CIU-->>Test: sOutput
Loading

Reviews (1): Last reviewed commit: ":white_check_mark: Fix cURL calls to iTo..." | Re-trigger Greptile

@Molkobain Molkobain changed the title ✅ Fix cURL calls to iTop within Docker dev. environment with PHP version autodetection ✅ Fix PHPUnit cURL calls to iTop within Combodo's Docker dev. env. with PHP version autodetection Apr 3, 2026
$sUrl = \MetaModel::GetConfig()->Get('app_root_url')."/$sUri";

// Add PHP version in header to be able to handle Docker dev environments with automatic PHP version detection (instead of hardcoding the PHP version in the app_root_url)
$sPhpVersion = PHP_VERSION;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

variable used one. you could inline it.

$aCurlOptions[CURLOPT_HTTPHEADER] ?? [],
['X-PHP-Version: '.$sPhpVersionHeaderValue]
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would extract this part in a separate function. its PHPDOC would explain why header is enriched.

@Molkobain Molkobain merged commit f66ce1c into support/3.2 Apr 7, 2026
2 of 3 checks passed
@Molkobain Molkobain deleted the issue/fix-curl-calls-to-itop-within-docker-dev-environment-with-php-version-autodetection branch April 7, 2026 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working internal Work made by Combodo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants