Skip to content

ci: add PHP 8.6 to test matrix, migrate tests to phunit - #170

Merged
dbu merged 5 commits into
php-http:1.xfrom
Chris53897:php85-new
Nov 22, 2026
Merged

dbu merged 5 commits into
php-http:1.xfrom
Chris53897:php85-new

Conversation

@Chris53897

Copy link
Copy Markdown
Contributor

based on #168

dbu and others added 5 commits December 10, 2025 18:07
add PHP 8.5 o the test-matrix
add PHP 8.5 o the test-matrix
add PHP 8.5 o the test-matrix
@Chris53897 Chris53897 changed the title ci: add PHP 8.5 to test matrix ci: add PHP 8.6 to test matrix, migrate tests to phunit Nov 21, 2026
@Chris53897

Copy link
Copy Markdown
Contributor Author

As manual review is hard with this much changes, here the info from claude.

Context Phpunit:
I've replaced the phpspec suite with PHPUnit tests and switched CI over. The 312 tests pass locally on PHPUnit 8.5 (PHP 7.2/7.3), 9.6 (PHP 7.4), 10.5, 11.5, 12.4 and 13.4 (PHP 8.5). I haven't run the updated GitHub Actions workflow itself. On PHPUnit 10 and later the run ends "OK, but there were issues!" because of 3 deprecations in src/CookieJar.php (details at the end).
Tests
All 47 spec/ files are deleted and replaced by tests/, using the [Http\Message\Tests](idea://file/Http%2FMessage%2FTests%2F) namespace.
The tests work across every PHPUnit version from 8.5 to 13. Data providers and requirements are declared twice (old-style annotation plus PHP 8 attribute), and test doubles use only methods every version supports.
The shared phpspec "behavior" traits for the factories became abstract base test classes, one per factory type.
The trick that simulates a missing zlib extension moved to tests/functions.php. It's loaded through autoload-dev.files, so it's in place before any encoding stream class loads.
The six zlib stream specs are now one data-driven test, plus new round-trip tests (encode, then decode, then compare).
New coverage: I added checks the specs didn't have, for example:
the WSSE password digest is actually verified (the spec only matched a regex)
request matchers with several conditions, and URL-decoded paths
curl output for HEAD and HTTP/1.0, and the Host header being skipped
error cases in the response builder
truncation of multibyte text in the message formatter
immutability of the decorators
The stream factory test for a non-seekable resource no longer downloads a file from GitHub; it uses a local socket pair instead (skipped on Windows).
Line coverage of src/ is 92%.
Config and CI
composer.json: phpspec is replaced by phpunit/phpunit: ^8.5.40 || ^9.6.22 || ^10.5.45 || ^11.5.20 || ^12.4 || ^13.0, and the test / test-ci scripts now run PHPUnit.
phpunit.xml.dist: new. It only uses settings all these PHPUnit versions understand, and fails on warnings and risky tests.
.github/workflows/tests.yml:
The PSR-7 2.0 job now deletes the Slim test files instead of the Slim spec files.
The coverage job no longer needs the phpspec coverage extension; it runs on PHP 8.5 with pcov.
fail-fast: false is set on the version matrices.
Other files: .php-cs-fixer.dist.php now checks tests/; .gitattributes, .gitignore and CHANGELOG.md are updated, and phpspec.yml.dist / phpspec.ci.yml are deleted. php-cs-fixer reports no issues and composer validate --strict passes.

Things to know
Security bypass on old PHP: on PHP 7.2–7.4, laminas-diactoros only has 2.x releases with a known high-severity advisory (CVE-2023-29530), and current Composer refuses to install them. I set COMPOSER_NO_SECURITY_BLOCKING=1 in the "latest" and "lowest" jobs. It only affects dev dependencies during tests. The other option is to drop Diactoros from the tests on PHP below 8.1.
Protocol version in factory tests: old Diactoros versions reject protocol "2.0", so the factory test uses "1.0" instead.
Deprecations in src/ on PHP 8.5: src/CookieJar.php uses SplObjectStorage::contains/attach/detach, which PHP 8.5 deprecates. The old specs hit the same calls; I left src/ unchanged.
In practice: PHPUnit 10 and later reports them as deprecations, but the run still passes.
PHPUnit 9.6 on PHP 8.5 treats the deprecation notices as risky output, and with failOnRisky that fails the run. CI never uses that combination (PHP 8.5 installs a newer PHPUnit).
The fix is switching to offsetExists/offsetSet/offsetUnset, which works from PHP 7.2 on. Should I make that change?
I didn't run composer normalize on the whole file, because the existing composer.json already fails the current version's check. Applying it would reorder unrelated sections, so I only changed the relevant entries.

Context PHPStan:
PHPStan now passes with no errors on level max, and all 312 tests still pass.
What was wrong: In src/Builder/ResponseBuilder.php, setHeadersFromString() was documented as taking only string. The method also accepts objects with __toString(), so the docblock didn't match what it actually does. Because it trusted the docblock, PHPStan decided the type check in the error message (is_object()) was pointless.
What I changed in that file:
The @PARAM now says string|\Stringable, which is what the method really accepts. It's only a docblock change, so it's still fine on PHP 7.2.
explode() now gets (string) $headers, so objects are converted to text explicitly.
The type description in the error message (class name or gettype) moved into a small helper, describeType(). The narrowed type no longer reaches that check, so PHPStan doesn't flag it, and the message is the same as before.
I didn't add any baseline entries or @PHPStan-Ignore comments.
To run the check, I installed PHPStan 2.3.7 in a temp folder, outside the project. CI uses the oskarstark/phpstan-ga Docker image, which may run a different PHPStan version. The test run also reports 3 deprecations; I didn't look into them.

@dbu dbu left a comment

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.

thanks! the changes to src are minimal and all look sane.

which gives me confidence the tests are alright, as they are still green.

the untyped method handling makes me itch to raise minimal php version, but i think for these libraries there is value to keep supporting legacy as long as its no bigger hassle.

@dbu
dbu merged commit 17d4d8f into php-http:1.x Nov 22, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants