Skip to content

Commit

Permalink
[TASK] Use PHPUnit 9.x with PHP 7.3+ (#930)
Browse files Browse the repository at this point in the history
This is required to be able to test against PHP 8.  However, PHPUnit 9.x
requires PHP 7.3, so a different version of PHPUnit is required for different
testing environments.

The main change here is a step in the GitHub Action to conditionally update
PHPUnit via PHIVE for PHP >=7.3.  PHIVE does not yet have the ability for
conditional installs (see
phar-io/phive#295 (comment)) so the
script must check the PHP version before running the update.

PHIVE has also been added to the tools (self-referencing) as it is not available
by default to GitHub Actions.

Note: There are warnings from PHPUnit 9.x about use of deprecated `assert`
methods (which will be removed in PHPUnit 10.x).  However, these don't cause the
tests to fail, and the replacement methods are not available in PHPUnit 7.x
which is still required to test against PHP 7.1 and 7.2.

Part of #925/#926.
  • Loading branch information
JakeQZ committed Nov 22, 2020
1 parent 7388179 commit 6b679ac
Show file tree
Hide file tree
Showing 5 changed files with 1,045 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,11 @@ jobs:
composer update --no-progress "${DEPENDENCIES}";
composer show;
- name: Update PHIVE dependencies
run: |
if ! composer php:version | grep -q '^7\.[012]'; then
composer phive:update:phpunit
fi
- name: Run Tests
run: composer ci:tests:unit
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@
"ci": [
"@ci:static",
"@ci:dynamic"
]
],
"phive:update:phpunit": "echo y | \"./tools/phive.phar\" --no-progress update phpunit"
},
"extra": {
"branch-alias": {
Expand Down
3 changes: 2 additions & 1 deletion phive.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="phar-io/phive" version="^0.14.4" installed="0.14.4" location="./tools/phive.phar" copy="true"/>
<phar name="php-cs-fixer" version="^2.16" installed="2.16.3" location="./tools/php-cs-fixer.phar" copy="true"/>
<phar name="phpmd" version="^2.8" installed="2.8.2" location="./tools/phpmd.phar" copy="true"/>
<phar name="phpunit" version="^7.5" installed="7.5.20" location="./tools/phpunit.phar" copy="true"/>
<phar name="phpunit" version="^7.5.20 || ^9.4.3" installed="7.5.20" location="./tools/phpunit.phar" copy="true"/>
<phar name="psalm" version="^3.11.5" installed="3.11.5" location="./tools/psalm.phar" copy="true"/>
</phive>
14 changes: 14 additions & 0 deletions tests/Support/Constraint/CssConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
* Due to {@link https://bugs.php.net/bug.php?id=75060 PHP 'bug' #75060}, traits cannot have constants, so, as a
* workaround, this is currently implemented as a base class (but ideally would be a `trait`).
*
* Since, then, this is a class, and PHPUnit's `Constraint` class may or may not have a constructor (it did prior to
* 8.x, but does not since) which must be called if it exists, this class also provides an explicit constructor which
* will invoke the parent's constructor if there is one.
*
* @author Jake Hotson <jake.github@qzdesign.co.uk>
*/
abstract class CssConstraint extends Constraint
Expand Down Expand Up @@ -74,4 +78,14 @@ private static function getCssNeedleRegularExpressionReplacement(array $matches)

return $regularExpressionEquivalent;
}

/**
* Invokes the parent class's constructor if there is one.
*/
public function __construct()
{
if (\is_callable('parent::__construct')) {
parent::__construct();
}
}
}

0 comments on commit 6b679ac

Please sign in to comment.