Tests: make the testsuite compatible with PHPUnit 9 and test against PHP 8 #278
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR can be summarized in the following changelog entry:
Relevant technical choices:
Composer: update the dependencies of the test dependencies
Update the
composer.lock
file with the latest dependencies related to the test suite.Note: the update is still based on
platform: php 5.6
, but some of the more recent sub-dependencies have widened their PHP version constraints, which makes getting the tests running on PHP 8 easier.Tests: use annotations instead of fixtures
In PHPUnit 8.x, the
setUpBeforeClass()
,tearDownAfterClass()
,setUp()
andtearDown()
methods have received type declarations,with a return typevoid
, making it neigh impossible to implement this in a cross-version manner as thevoid
return type is not available until PHP 7.1.However, PHPUnit also supports
@beforeClass
,@afterClass
,@before
and@after
annotations to run arbitrary methods for setting things up/tearing things down. Those annotations have been around forever and are supported all the way back to PHPUnit 4.x.So instead of doing convoluted things with extending different classes for different PHPUnit versions or creating classes on the fly for this, by renaming the fixture related methods and using the PHPUnit annotations, the unit test suite becomes compatible with PHPUnit 8.x without much effort.
Tests: implement work-around for remaining PHPUnit cross-version issue
PHPUnit 9 removed the
assertInternalType()
method in favour of more specific methods, which were introduced in PHPUnit 8.As this test suite only uses this assertion in one test file, a simple helper method with an if/else does the trick.
Composer: allow installation of PHPUnit 8 and 9
Now the tests have been made cross-version compatible with PHPUnit 8 and 9, allow installation of those versions by widening the version restraints in the
composer.json
file.PHPUnit 8 introduces a form of caching to PHPUnit, so adding this cache file to the
.gitignore
file.Travis: run the tests against PHP 8/nightly
Now the tests are fully compatible with PHPUnit 9, the test suite can be run on PHP 8.
As not all dependencies of PHPUnit have tagged a new version which allows for PHP 8 yet, we do need to
ignore-platform-reqs
for the time being.Includes adding
travis_retry
tocomposer install
-like commands to get round builds stalling on the connection with Packagist, especially on older PHP versions.Test instructions
This PR can be tested by following these steps:
To test locally, it will be simplest to:
phpunit9.phar
.The tests should pass, which confirms PHP 8 compatibility for the code covered by tests.