PHPUnit is a programmer-oriented testing framework for PHP.
It is an instance of the xUnit architecture for unit testing frameworks.
Create your Github Workflow configuration in .github/workflows/ci.yml or similar.
name: CI
on: [push]
jobs:
build-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: php-actions/composer@v6 # or alternative dependency management
- uses: php-actions/phpunit@v4
# ... then your own project steps ...GitHub have changed to an auto-tagging model, where the release will be made as vX.Y.Z and an automatic tag is created called vX, so there will be no more proxy releases for the latest version number.
Please use uses: php-actions/phpunit@v4 to always run the latest version of v4.
We've put together an extremely simple example application that uses php-actions/phpunit. Check it out here: https://github.com/php-actions/example-phpunit.
The following configuration options are available:
versionThe version of PHPUnit to use e.g.latest,9or9.5.0(default:composer- use the version specified in composer.json)php_versionThe version of PHP to use e.g.7.4(default: latest)php_extensionsSpace-separated list of extensions using php-build e.g.xdebug mbstring(default: N/A)vendored_phpunit_pathThe path to a phar file already present on the runner (default: N/A)configurationPath to thephpunit.xmlfile (default:test/phpunit/phpunit.xml)log_junitLog test execution in JUnit XML format to filelog_teamcityLog test execution in TeamCity format to filetestdox_htmlWrite documentation in HTML format to filetestdox_textWrite documentation in Text format to filememory_limitThe memory limit to run your tests with (default:128M)bootstrapThe path to the bootstrap filefilterFilter which tests to runtestsuiteSpecify a testsuite to rungroupOnly runs tests from the specified group(s)exclude_groupExclude tests from the specified group(s)test_suffixOnly search for test in files with specified suffix(es)whitelistPath to directory to whitelist for code coverage analysis (phpunit <= 8)coverage_filterInclude directory in code coverage reporting (phpunit >= 9)coverage_cloverGenerate code coverage report in Clover XML formatcoverage_coberturaGenerate code coverage report in Cobertura XML format requiredcoverage_crap4jGenerate code coverage report in Crap4J XML formatcoverage_htmlGenerate code coverage report in HTML formatcoverage_phpExport PHP_CodeCoverage object to filecoverage_textGenerate code coverage report in text format (true to output to console, path to output to file)coverage_xmlGenerate code coverage report in PHPUnit XML formatargsExtra arguments to pass to the phpunit binary
The syntax for passing in a custom input is the following:
...
jobs:
unit-tests:
...
- name: PHPUnit tests
uses: php-actions/phpunit@v4
with:
configuration: "custom/path/to/phpunit.xml"
memory_limit: "256M"If you require other configurations of phpunit, please request them in the Github issue tracker
It's possible to run any version of PHPUnit under any version of PHP, with any PHP extensions you require. This is configured with the following inputs:
version- the version number of PHPUnit to run e.g.latest,9or9.5.0(default:composer). Using the default value,composerwill install the version specified incomposer.jsonphp_version- the version number of PHP to use e.g.7.4(default: latest)php_extensions- a space-separated list of extensions to install using php-build e.g.xdebug mbstring(default: N/A)
Please note the version number specified within your Action configuration must match your composer.json major version number. For example, if your composer.json requires phpunit/phpunit 8.5.8, you must use the version: 8.5.8 input, as major versions of PHPUnit are incompatible with each other.
If you require a specific version that is not compatible with Github Actions for some reason, please make a request in the Github issue tracker.
To store the code coverage, use the coverage_* input that is appropriate for your needs. Coverage information is made possible by using the xdebug extension, which will be required to be added to the php_extensions input to work.
Example:
jobs:
unit-tests:
...
- name: PHPUnit tests
uses: php-actions/phpunit@v4
with:
php_extensions: "xdebug"
coverage_clover: "coverage/clover.xml"The above example will output coverage information to the terminal. Pass a file path to output to a file.
If you want to report coverage information somewhere, please see the code-coverage action.
Previously, the Github Actions release version numbers were in sync with the PHPUnit version, but this imposed too many limitations. For the next 12 months (until 30th November 2021), v7, v8 and v9 branches will still point to their existing commits, but we have reverted to v1-based Actions releases, allowing PHPUnit version number to be specified from your configuration, using the version input variable.
If you found this repository helpful, please consider sponsoring the developer.
