Skip to content

Commit

Permalink
Coverage options (#52)
Browse files Browse the repository at this point in the history
* docs: add missing config options

* feature: implement coverage options

* wip: equals required for optional arg

* wip: bump hash

* wip: typo
  • Loading branch information
g105b authored Feb 15, 2023
1 parent a11fcf3 commit 8b81f7e
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 15 deletions.
49 changes: 46 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,27 @@ The following configuration options are available:
+ `php_extensions` Space-separated list of extensions using [php-build][php-build] e.g. `xdebug mbstring` (default: N/A)
+ `vendored_phpunit_path` The path to a phar file already present on the runner (default: N/A)
+ `configuration` Path to the `phpunit.xml` file (default: `test/phpunit/phpunit.xml`)
+ `log_junit` Path to junit output file (default: `test/phpunit/_junit/junit.xml`)
+ `log_junit` Log test execution in JUnit XML format to file
+ `log_teamcity` Log test execution in TeamCity format to file
+ `testdox_html` Write documentation in HTML format to file
+ `testdox_text` Write documentation in Text format to file
+ `memory_limit` The memory limit to run your tests with (default: `128M`)
+ `bootstrap` The path to the bootstrap file
+ `filter` Filter which tests to run
+ `testsuite` Specify a testsuite to run
+ `group` Only runs tests from the specified group(s)
+ `exclude_group` Exclude tests from the specified group(s)
+ `test_suffix` Only search for test in files with specified suffix(es)
+ `whitelist` Path to directory to whitelist for code coverage analysis
+ `coverage_clover` Generate code coverage report in Clover XML format
+ `coverage_cobertura` Generate code coverage report in Cobertura XML format
required
+ `coverage_crap4j` Generate code coverage report in Crap4J XML format
+ `coverage_html` Generate code coverage report in HTML format
+ `coverage_php` Export PHP_CodeCoverage object to file
+ `coverage_text` Generate code coverage report in text format (true to output to console, path to output to file)
+ `coverage_xml` Generate code coverage report in PHPUnit XML format
+ `args` Extra arguments to pass to the phpunit binary

The syntax for passing in a custom input is the following:

Expand All @@ -66,8 +84,8 @@ jobs:
- name: PHPUnit tests
uses: php-actions/phpunit@v3
with:
configuration: custom/path/to/phpunit.xml
memory_limit: 256M
configuration: "custom/path/to/phpunit.xml"
memory_limit: "256M"
```
If you require other configurations of phpunit, please request them in the [Github issue tracker][issues]
Expand All @@ -85,6 +103,30 @@ Please note the version number specified within your Action configuration must m

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][issues].

Coverage
--------

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:

```yaml
jobs:
unit-tests:
...
- name: PHPUnit tests
uses: php-actions/phpunit@v3
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.

Github Actions releases
-----------------------

Expand All @@ -96,4 +138,5 @@ If you found this repository helpful, please consider [sponsoring the developer]

[issues]: https://github.com/php-actions/phpunit/issues
[php-build]: https://github.com/php-actions/php-build
[code-coverage]: https://github.com/php-actions/code-coverage
[sponsor]: https://github.com/sponsors/g105b
45 changes: 38 additions & 7 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,11 @@ inputs:
required: false

testdox_html:
description: JUnit output file location
description: Write documentation in HTML format to file
required: false

testdox_text:
description: JUnit output file location
required: false

testdox_xml:
description: JUnit output file location
description: Write documentation in Text format to file
required: false

memory_limit:
Expand Down Expand Up @@ -77,6 +73,34 @@ inputs:
description: Path to directory to whitelist for code coverage analysis
required: false

coverage_clover:
description: Generate code coverage report in Clover XML format
required: false

coverage_cobertura:
description: Generate code coverage report in Cobertura XML format
required: false

coverage_crap4j:
description: Generate code coverage report in Crap4J XML format
required: false

coverage_html:
description: Generate code coverage report in HTML format
required: false

coverage_php:
description: Export PHP_CodeCoverage object to file
required: false

coverage_text:
description: Generate code coverage report in text format (true to output to console, path to output to file)
required: false

coverage_xml:
description: Generate code coverage report in PHPUnit XML format
required: false

args:
description: Extra arguments to pass to the phpunit binary
required: false
Expand All @@ -94,7 +118,6 @@ runs:
ACTION_LOG_JUNIT: ${{ inputs.log_junit }}
ACTION_TESTDOX_HTML: ${{ inputs.testdox_html }}
ACTION_TESTDOX_TEXT: ${{ inputs.testdox_text }}
ACTION_TESTDOX_XML: ${{ inputs.testdox_xml }}
ACTION_BOOTSTRAP: ${{ inputs.bootstrap }}
ACTION_FILTER: ${{ inputs.filter }}
ACTION_TESTSUITE: ${{ inputs.testsuite }}
Expand All @@ -103,7 +126,15 @@ runs:
ACTION_TEST_SUFFIX: ${{ inputs.test_suffix }}
ACTION_WHITELIST: ${{ inputs.whitelist }}
ACTION_MEMORY_LIMIT: ${{ inputs.memory_limit }}
ACTION_COVERAGE_CLOVER: ${{ inputs.coverage_clover }}
ACTION_COVERAGE_COBERTURA: ${{ inputs.coverage_cobertura }}
ACTION_COVERAGE_CRAP4J: ${{ inputs.coverage_crap4j }}
ACTION_COVERAGE_HTML: ${{ inputs.coverage_html }}
ACTION_COVERAGE_PHP: ${{ inputs.coverage_php }}
ACTION_COVERAGE_TEXT: ${{ inputs.coverage_text }}
ACTION_COVERAGE_XML: ${{ inputs.coverage_xml }}
ACTION_ARGS: ${{ inputs.args }}

id: phpunit_run
run: |
set -e
Expand Down
45 changes: 40 additions & 5 deletions phpunit-action.bash
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ then
command_string+=(--testdox-text "$ACTION_TESTDOX_TEXT")
fi

if [ -n "$ACTION_TESTDOX_XML" ]
then
command_string+=(--testdox-xml "$ACTION_TESTDOX_XML")
fi

if [ -n "$ACTION_BOOTSTRAP" ]
then
command_string+=(--bootstrap "$ACTION_BOOTSTRAP")
Expand Down Expand Up @@ -91,6 +86,46 @@ then
command_string+=(-d memory_limit="$ACTION_MEMORY_LIMIT")
fi

if [ -n "$ACTION_COVERAGE_CLOVER" ]
then
command_string+=(--coverage-clover "$ACTION_COVERAGE_CLOVER")
fi

if [ -n "$ACTION_COVERAGE_COBERTURA" ]
then
command_string+=(--coverage-cobertura "$ACTION_COVERAGE_COBERTURA")
fi

if [ -n "$ACTION_COVERAGE_CRAP4J" ]
then
command_string+=(--coverage-crap4j "$ACTION_COVERAGE_CRAP4J")
fi

if [ -n "$ACTION_COVERAGE_HTML" ]
then
command_string+=(--coverage-html "$ACTION_COVERAGE_HTML")
fi

if [ -n "$ACTION_COVERAGE_PHP" ]
then
command_string+=(--coverage-php "$ACTION_COVERAGE_PHP")
fi

if [ -n "$ACTION_COVERAGE_TEXT" ]
then
if [ "${ACTION_COVERAGE_TEXT,,}" = "true" ]
then
command_string+=(--coverage-text)
else
command_string+=(--coverage-text="$ACTION_COVERAGE_TEXT")
fi
fi

if [ -n "$ACTION_COVERAGE_XML" ]
then
command_string+=(--coverage-xml "$ACTION_COVERAGE_XML")
fi

command_string+=(--colors=always)

if [ -n "$ACTION_ARGS" ]
Expand Down

0 comments on commit 8b81f7e

Please sign in to comment.