Skip to content

Commit

Permalink
Merge pull request #338 from Yoast/JRF/start-recording-code-coverage
Browse files Browse the repository at this point in the history
CI/QA: start recording code coverage
  • Loading branch information
jrfnl committed May 1, 2023
2 parents fb7c34a + 2d200f8 commit 44fee1c
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 2 deletions.
49 changes: 47 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ jobs:

strategy:
matrix:
php_version: ['7.2', '7.4', '8.0', '8.1', '8.2']
php_version: ['7.4', '8.0', '8.1']
coverage: [false]

# Run code coverage only on high/low PHP.
include:
- php_version: 7.2
coverage: true
- php_version: 8.2
coverage: true

name: "Unit Test: PHP ${{ matrix.php_version }}"

Expand All @@ -37,7 +45,7 @@ jobs:
with:
php-version: ${{ matrix.php_version }}
ini-values: zend.assertions=1, error_reporting=-1, display_errors=On
coverage: none
coverage: ${{ matrix.coverage == true && 'xdebug' || 'none' }}

# The PHP platform requirement would prevent updating the test utilities to the appropriate versions.
# As long as the `composer update` is run selectively to only update the test utils, removing this is fine.
Expand All @@ -58,4 +66,41 @@ jobs:
custom-cache-suffix: $(date -u "+%Y-%m")

- name: Run unit tests
if: ${{ matrix.coverage == false }}
run: composer test

- name: Run the unit tests with code coverage
if: ${{ matrix.coverage == true }}
run: composer coverage

# PHP Coveralls doesn't fully support PHP 8.x yet, so switch the PHP version.
- name: Switch to PHP 7.4
if: ${{ success() && matrix.coverage == true && startsWith( matrix.php_version, '8' ) }}
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
coverage: none

# Global install is used to prevent a conflict with the local composer.lock in PHP 8.0+.
- name: Install Coveralls
if: ${{ success() && matrix.coverage == true }}
run: composer global require php-coveralls/php-coveralls:"^2.5.3" --no-interaction

- name: Upload coverage results to Coveralls
if: ${{ success() && matrix.coverage == true }}
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_TOKEN }}
COVERALLS_PARALLEL: true
COVERALLS_FLAG_NAME: php-${{ matrix.php_version }}
run: php-coveralls -v -x build/logs/clover.xml

coveralls-finish:
needs: unit
runs-on: ubuntu-latest

steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.COVERALLS_TOKEN }}
parallel-finished: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ phpcs.xml
.cache/phpcs.cache
phpunit.xml
.phpunit.result.cache
build/
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![Coverage Status](https://coveralls.io/repos/github/Yoast/yoast-acf-analysis/badge.svg?branch=develop)](https://coveralls.io/github/Yoast/yoast-acf-analysis?branch=develop)

# ACF Content Analysis for Yoast SEO
WordPress plugin that adds the content of all ACF fields to the Yoast SEO score analysis.

Expand Down
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@
"@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --show-deprecated --exclude vendor --exclude node_modules --exclude .git"
],
"test": [
"@php ./vendor/phpunit/phpunit/phpunit --no-coverage --colors=always"
],
"coverage": [
"@php ./vendor/phpunit/phpunit/phpunit --colors=always"
],
"configure-phpcs": [
Expand Down
6 changes: 6 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,10 @@
<directory suffix=".php">inc/</directory>
</whitelist>
</filter>

<logging>
<log type="coverage-text" target="php://stdout" showOnlySummary="true"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>

</phpunit>

0 comments on commit 44fee1c

Please sign in to comment.