Skip to content

Instantly share code, notes, and snippets.

@alcaeus
Last active May 20, 2020 15:06
Show Gist options
  • Save alcaeus/a6ebbd774a847a84d02e038306b241cd to your computer and use it in GitHub Desktop.
Save alcaeus/a6ebbd774a847a84d02e038306b241cd to your computer and use it in GitHub Desktop.
Why composer hacks don't help when testing against PHP 8
  • composer.json: our project
  • ext-v*.json: composer.json for MongoDB ODM in version 1 and 2
  • restrictive-v*.json: composer.json for package restrictive about its php constraint

Assume we're running on PHP 8 and have ext-something installed. This presents a set of uninstallable depdendencies;

  1. Using --ignore-platform-reqs won't work, as that will cause the installation of vendor/extension 2.0 even though ext-other is missing
  2. Using config.platform with PHP locked to 7.4 won't work, as that would install vendor/restrictive 1.0 which is not compatible with PHP 8 even though there's a newer release that is compatible

The only way to test this is by changing our own constraint to ^7.2 || ^8.0. However, if vendor/extension were to also advertise a PHP constraint of ^7.2, we would never end up with a properly testable system.

{
"require": {
"php": "^7.2",
"vendor/extension": "^1 || ^2",
"vendor/restrictive": "^1 || ^2"
}
}
{
"require": {
"ext-something": "*"
}
}
{
"require": {
"ext-other": "*"
}
}
{
"require": {
"php": "~7.4.2"
}
}
{
"require": {
"php": "~8.0.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment