-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for PHP 8 #17
Conversation
Since PHP 7, `assert()` would throw an `AssertionError` if the ini option `assert.exception` was enabled, but it didn't become the default until PHP 8 so instead warnings were converted to an `ErrorException`. This commit updates phpunit's bootstrap script to make sure that the `assert.exception` option is enabled for both PHP 7 *and* 8, enabling us to switch the expectation to a proper `AssertionError` in the tests.
Codecov Report
@@ Coverage Diff @@
## main #17 +/- ##
===========================================
Coverage 100.00% 100.00%
Complexity 236 236
===========================================
Files 21 21
Lines 632 632
===========================================
Hits 632 632
Continue to review full report at Codecov.
|
The grumphp-config Composer dep was blocking Travis build due to lack of composer-2 support, so I've updated it to 4.0.1 which adds compatibility for it. Now that it's running again, it looks like the errors I'm getting locally with the mutation tests (xdebug could not connect to debugging client) are also happening in Travis, albeit only for php nightly. I've tried updating the |
assert()
in tests under php8
Thanks alot for your effort. |
I've just updated phpunit to 9.x and (so far) it's still green, although there are some new warnings now:
Running the migration command has kindly removed most line breaks so I gotta fix that before I can diff them, but with any luck we won't need to adjust too much. Assuming the phpunit stuff goes well, I'll push that up then see if there's time to look at the rest before I pass out For reference, these are the xdebug warnings from php itself:
|
Regarding the XDebug error. It seems like this error happens because XDebug cannot establish a connection to PHPStorm. |
That would make sense as I don't have PHPStorm installed :D The "cachegrind.out" and /tmp/debug errors can be solved easily a couple ways, depending which you prefer:
Option 3 could be the better route? But I'm not sure if other tools need to access the profiling data. If they do then we might need to go with option 1 regardless, in which case I can add it to this PR. The only other question is that of the PHP minimum version. Phpunit requires |
I actually added this line too |
It turns out the I've updated phpunit and infection locally and both are now running without issue. PHP 8 has also removed pcntl (used for timing) from core due to lack of maintainers. I've added that (and removed the aforementioned If there's anything that needs changing in that PR first, please let me know and I'll get to it asap - I'll hold pushes to this PR until that's merged in case the pcntl error ends up causing CI to fail |
I just merged it, so let's see whether this now works. Thanks for digging into this! |
No worries, thanks for the fast merge! I'll get the commits pushed right now... 🙏 |
76ff453
to
753b930
Compare
Forgot about infection requiring 7.4, so I've added Tests themselves are running again, but there's still some work to get coverage/infection working on Travis. I'll dig into that some more either today/tomorrow and update the PR if I figure anything out. 7.2 tests seem to only be failing currently due to latest infection using newer syntax (guessing trailing commas). We could just disable the infection task under 7.2? If that sounds good, I can add it in while I'm playing with the coverage bits. Turning out to be quite the adventure, but... I think we're getting there! |
For phpunit-watcher, I quickly created a pull request to their repository spatie/phpunit-watcher#124 so that we can omit
I wish I could drop 7.2 support altogether but sadly phpsu and our agency needs it.
|
The issue in 7.2 isn't failing infections, but Infection PHP itself using syntax that's incompatible with 7.2:
My first thought was infection simply wouldn't run, but seeing your PR to phpunit-watcher hinted at an
I'll try updating the composer.json to accept either version for phpunit and infection; hopefully that should sort it without having to exclude 7.2 from the infection/phpunit runs. |
d989c4b
to
09a0e75
Compare
Some 30 builds and one sleep later, Travis is finally happy across all 7.x jobs. Huzzah! Still got some work to do for the nightly job to pass, but once it does I'll rebase to clean up the huge string of commits. |
2b92cb7
to
9514227
Compare
Bumps infection, phpunit and php-invoker to the latest versions to get support for php8 and the xdebug config changes. With the update to phpunit comes a new xml config schema. The new `coverage` section is made up of the `filter.whitelist` value (now 'include') and the `log.coverage-*` values as children of `report`.
After updating the upstream image to include pcntl, Infection PHP flagged a mutation in `Collection\CollectionTuple::__toArray()` where `$this->value instanceof ShellInterface` could be changed to `false`. That results in the first half of the ternary never executing. To catch it, this commit adds a test for `__toArray()` that uses an instance of `ShellBuilder`, complimenting the existing string-based test.
After updating psalm, 17 errors were uncovered - all either a MissingConstructor error or PropertyNotSetInConstructor - largely depending on whether it found it in the `final` class or a parent. In all cases, the root cause was simply lack of a default value.
The most recent version of Infection PHP that will run on 7.2 is 0.15.x. v0.19 adds support for php 8, but also drops support for versions older than 7.4 meaning we also need to allow for 0.18.x to get 7.3 working.
Phpunit 9 won't run under 7.2, but phpunit 8 doesn't understand the config for v9. This here is an attempt at a "dual boot" of sorts. The old config is restored to a separate file so we can pass the legacy config for 7.2 but still use the new config format for other versions.
Manually installs the latest copy of phpunit 8.x for php 7.3 because while phpunit9 is compatible with php7.3, infection is not able to read the new xml config schema that phpunit uses as of v9.
Copies the legacy config rather than moving it so that xmllint can scan it, which was the last thing preventing the 7.x build from passing. Since the config is always available under the same filename, we also no longer need to pass a custom `--configuration` flag for phpunit.
For php 8, we need to manually set the new `xdebug.mode` option to enable coverage mode, but it won't work if we simply do something like `php -d xdebug.mode=coverage composer infection` because InfectionPHP spawns new processes that would lose that option. To provide for this, there's the `--initial-tests-php-options` shell option to infection that will pass that on when it calls PHP for the initial test run, which is the only time we need coverage enabled. Since this is only required in PHP 8 and there are no other parts using the `PHPUNIT_LEGACY` env variable, we can instead test against php 7.x to remove the need for PHPUNIT_LEGACY entirely.
Infection PHP hasn't released the commit adding php 8 support yet, so for now we reference it directly as a fallback with 1.24 preemptively set ready for when it's actually available. phpro/grumphp still requires ^7.3 so we can't stop ignoring platform requirements just yet, but enforcing 4.0.1 explicitly at least removes the error about 4.0.0 requiring the composer v1 plugin api package.
assert()
in tests under php8
@ChrisB9 I've removed It all seems to be working fine though, so I'll create a separate issue with the details on that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good so far
Thanks for all your effort here!
Co-authored-by: Chris Ben <[email protected]>
@ChrisB9 Good idea to limit the ignores, committed that now so touch wood it'll all pass soon and it won't flag anything else! |
Description and Background
With the recent changes in ChrisB9/php8-xdebug that fix xdebug options, update composer and (afaict) remove the profiler that caused errors previously, there seem to be only two errors remaining in the tests on PHP 8.
Both errors are with the
assert()
lines, which throw anAssertionError
in v8, but only trigger a warning (converted toErrorException
) when ran under v7. This is caused by a change in php8 which now enables theassert.exception
option by default.I considered a couple methods, but simply enabling the option by default seems to be the cleanest route. The option itself was added in v7, so this change just makes things consistent across both versions.
How Has This Been Tested
Existing tests fixed, ran with
docker-compose run php composer test && docker-compose run php8 composer test
.Psalm is happy, but the infection tests are currently still failing as a result of xdebug connection issues.
Checklist
documentation
accordingly.tests
to cover my changes.Resolves #15