Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
We updated MINIMUM_PHP to 8.1.0 but left MINIMUM_SUPPORTED_PHP at 8.0.2. That makes no sense.
This is a Drupal 10 issue only.
Proposed resolution
Update MINIMUM_SUPPORTED_PHP to 8.1.0 and add a test to ensure it is greater than MINIMUM_PHP
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comment | File | Size | Author |
---|---|---|---|
#20 | 3266525-20.patch | 2.24 KB | quietone |
#20 | interdiff-15-20.txt | 731 bytes | quietone |
Comments
Comment #2
alexpottComment #3
alexpottOops #2's patch had another one as well... fixing that.
Comment #4
longwaveThis might not work if e.g. we recommend 8.1, but we need a minimum of 8.1.1 for a PHP bug fix. Still that's a hypothetical for now I guess, we can address that if it happens.
Otherwise +1 to the test for this to avoid getting it wrong again.
Comment #6
alexpott@longwave - good point. I made \Drupal::RECOMMENDED_PHP equal to 8.1.21 and \Drupal::MINIMUM_SUPPORTED_PHP equal to 8.1.43 and the patch attached failed as we'd hope. So let's fix that #4.
Comment #7
xjmNot that I actually expect PHP to ever have a patch version of 99, but isn't this test technically only valid so long as the recommended PHP version is MAJOR.MINOR.98 or less?
Also, what if
RECOMMENDED_PHP
does contain a patch version? Then this becomes a four-part version like 8.1.0.99.version_compare()
doesn't seem to fatal or anything for that, and Composer supports versions like that, but it's certainly not the expected behavior.Comment #8
alexpottIf we do recommend a specific patch version is works as expected. I documented the fact I tested that in my previous comment.
And yeah I just chose a number they PHP will never reach as a patch version. I think it is safe to assume they won’t reach 99 patch releases.
Comment #9
xjmCan we put this in the code comments though? (I still don't see where the issue says this. Edit: I'm pretty sure it doesn't.)
Also, I think the test could probably use
.9999999999999
or something just to make it far less likely that the test will break? IIRC Composer or someone does similarly already. Still not ideal, but as a reminder Drupal 7 is on 80-something now so 99 is not outside the realm of possibility.Comment #10
xjm(Also there is an NPM package with a version of
1.0.30001271
in our dependency tree.)Comment #11
xjmAlso it's possible for
MINIMUM_SUPPORTED_PHP
to only be two parts as well. See #3261447: Add an API for dynamically setting recommended and supported PHP versions based on known and predicted PHP release schedules which explicitly adds and tests that.Comment #12
xjmComment #13
alexpottUnfortunately there's nothing simple in Composer/Semver for us to use. So I've added an inline function to normalise the versions the way we'd like. I've also added a tiny test of that functionality just to be sure given a regex is involved.
Re testing what happens if RECOMMENDED_PHP has a patch version - I wrote in #6
I guess I could have also noted that I swapped these around and it passed as expected.
I've used the number of 9's that composer seems to use everywhere. Note though that I'm pretty certain we'll never set the minimum, minimum_supported or recommend PHP version to 8.4.99 - given PHP's current release cadence that is inconceivable and given our own release cadence even if PHP was releasing at such a cadence we'd be struggling. The current one PHP minor per year is challenging enough for us :) Also even if PHP did release a .10000000 it would not affect the test. The tests would only be affected if we make a change to one of the constants being tested here and presently that requires a code change.
If/when #3261447: Add an API for dynamically setting recommended and supported PHP versions based on known and predicted PHP release schedules lands then that change will need to ensure the minimum, minimum_supported or recommend PHP versions can't ever be inconsistent.
Comment #14
daffie CreditAttribution: daffie commentedPatch looks good.
version_compare() return a boolean value when the $operator parameter is used, which we are doing here. Therefor "(bool)" can be removed.
I cannot find where it is saying that MINIMUM_PHP must be of the type "Major.Minor.Patch". Can we add documentation for it and add a test that it is of the type "Major.Minor.Patch".
Comment #15
alexpottThanks for the review @daffie.
1. Fixed.
2. I think this is both out-of-scope and does not matter. If we set the minimum PHP to 9.1 and >=9.1 in composer.json this test would still work because https://3v4l.org/qLANS
Comment #16
daffie CreditAttribution: daffie commentedMy points have been addressed.
For me it is RTBC.
Comment #17
xjmIs there any specific reason we're constraining the major version to be between 1 and 5 digits? Because six nines is what Composer uses, or a different reason?
I mean, having PHP version 100,000 is even less likely than having version 8.0.99. :P But as-is the 1-5 digits seems like a magic number. It might be good for the inline comments to explain where the 5-digit limit comes from (and that the normalization pattern with its six nines are from Composer's own internal comparisons).
Outside that, the improved test looks great to me. (The interdiff in #13 is an inter-interdiff but I figured it out after only momentary confusion.) Thanks!
Comment #18
alexpottI borrowed the regex from Composer -
\Composer\Semver\VersionParser::normalize()
Specifically:
Also given that we maintain all of the constants this test will only fail if we change the constants to values that fail. At that point we can fix the tests or fix the constants... whatever is correct. For that reason I'm not sure it is worth a comment.
Comment #19
xjmIt's just an inline comment. It's free. Documenting hardcoded integers is never a bad thing. Explaining why a test provides the specific coverage it does is never a bad thing. All it has to say is:
// The regex below is borrowed from \Composer\Semver\VersionParser::normalize()
....And we never have to wonder about it again.
(I'd add it myself but I'd prefer to be able to commit the patch.)
Comment #20
quietone CreditAttribution: quietone at PreviousNext commentedI could use a simple task today and saw this. Shortened the suggestion to be under 80 chars.
Comment #22
quietone CreditAttribution: quietone at PreviousNext commentedRandom failures. Setting to NR.
Comment #23
daffie CreditAttribution: daffie commentedThe point of the regex string has been addressed.
Back to RTBC.
Comment #24
catchFor me this is very much at the edge of things I would add a test for - we change these constants at most once or twice per year, usually a long time before tagging a release for the branch that changes them, and although we managed to get into a wrong state, it was picked up very quickly and easy to fix.
However, the test is already written and should stop this happening again, so..
Committed c2495d1 and pushed to 10.0.x. Thanks!