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() and tearDown() methods have received type declarations,with a return type void, making it neigh impossible to implement this in a cross-version manner as the void 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 to composer 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:
Verify the output of all builds for this PR, making sure that 1) the installation via Composer works without issues, 2) the tests are being run and 3) the tests pass.
To test locally, it will be simplest to:
Download phars of PHPUnit 7/8/9 and save them somewhere in the system path or in the root directory of this project (an exclude them from Git).
On a recent PHP 7.4.x version, run the tests using each of the downloaded phars:
phpunit7.phar
phpunit8.phar
phpunit9.phar
The tests on each version should run without any warnings and pass. This confirms the PHPUnit cross-version compatibility.
On a recent PHP 8 pre-release, run the tests again, though now only using the phpunit9.phar.
The tests should pass, which confirms PHP 8 compatibility for the code covered by tests.
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:
The tests on each version should run without any warnings and pass. This confirms the PHPUnit cross-version compatibility.
phpunit9.phar
. The tests should pass, which confirms PHP 8 compatibility for the code covered by tests.