✅ Fix PHPUnit cURL calls to iTop within Combodo's Docker dev. env. with PHP version autodetection#869
Conversation
…ion autodetection
|
| 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
Reviews (1): Last reviewed commit: ":white_check_mark: Fix cURL calls to iTo..." | Re-trigger Greptile
| $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; |
There was a problem hiding this comment.
variable used one. you could inline it.
| $aCurlOptions[CURLOPT_HTTPHEADER] ?? [], | ||
| ['X-PHP-Version: '.$sPhpVersionHeaderValue] | ||
| ); | ||
|
|
There was a problem hiding this comment.
i would extract this part in a separate function. its PHPDOC would explain why header is enriched.
Base information
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: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)
suport/3.2branchapp_root_urlset tohttpswith PHP version autodection\Combodo\iTop\Test\UnitTest\Webservices\RestTest::testPostJSONDataAsCurlFile()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.https://localhost/itophttp://localhost:88/itophttp://localhost:83/itopfor PHP 8.3http://localhost:84/itopfor PHP 8.4Proposed solution (bug and enhancement)
Add an
X-PHP-Versionheader in\Combodo\iTop\Test\UnitTest\ItopTestCase::CallItopUri(), derived fromPHP_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