Skip to content

Commit cbf9b55

Browse files
authored
Collect code coverage (#53)
* Collect Behat code coverage * Coverage for unit test too * install driver
1 parent d80de8f commit cbf9b55

File tree

2 files changed

+61
-3
lines changed

2 files changed

+61
-3
lines changed

.github/workflows/testing.yml

+60-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ jobs:
1717
strategy:
1818
matrix:
1919
php: ['8.2']
20+
wp: ['latest']
21+
coverage: [true]
2022
runs-on: ubuntu-latest
2123
services:
2224
mysql:
@@ -43,19 +45,61 @@ jobs:
4345
- name: Install composer packages
4446
run: composer install
4547

48+
- name: Check Behat environment
49+
env:
50+
WP_VERSION: '${{ matrix.wp }}'
51+
WP_CLI_TEST_DBUSER: wp_cli_test
52+
WP_CLI_TEST_DBPASS: password1
53+
WP_CLI_TEST_DBNAME: wp_cli_test
54+
WP_CLI_TEST_DBHOST: 127.0.0.1:${{ job.services.mysql.ports['3306'] }}
55+
run: WP_CLI_TEST_DEBUG_BEHAT_ENV=1 composer behat
56+
4657
- name: Run Behat
47-
run: composer behat
4858
env:
59+
WP_VERSION: '${{ matrix.wp }}'
4960
WP_CLI_TEST_DBUSER: wp_cli_test
5061
WP_CLI_TEST_DBPASS: password1
5162
WP_CLI_TEST_DBNAME: wp_cli_test
5263
WP_CLI_TEST_DBHOST: 127.0.0.1:${{ job.services.mysql.ports['3306'] }}
64+
WP_CLI_TEST_COVERAGE: ${{ matrix.coverage }}
65+
run: |
66+
ARGS=()
67+
68+
if [[ $WP_CLI_TEST_COVERAGE == 'true' ]]; then
69+
ARGS+=("--xdebug")
70+
fi
71+
72+
if [[ $RUNNER_DEBUG == '1' ]]; then
73+
ARGS+=("--format=pretty")
74+
fi
75+
76+
composer behat -- "${ARGS[@]}" || composer behat-rerun -- "${ARGS[@]}"
77+
78+
- name: Retrieve list of coverage files
79+
id: coverage_files
80+
if: ${{ matrix.coverage }}
81+
run: |
82+
FILES=$(find "$GITHUB_WORKSPACE/build/logs" -path '*.*' | paste -s -d "," -)
83+
echo "files=$FILES" >> $GITHUB_OUTPUT
84+
85+
- name: Upload code coverage report
86+
if: ${{ matrix.coverage }}
87+
uses: codecov/codecov-action@v5.4.0
88+
with:
89+
# Because somehow providing `directory: build/logs` doesn't work for these files
90+
files: ${{ steps.coverage_files.outputs.files }}
91+
flags: feature
92+
token: ${{ secrets.CODECOV_TOKEN }}
5393

5494
unit: #-----------------------------------------------------------------------
5595
name: Unit test / PHP ${{ matrix.php }}
5696
strategy:
5797
matrix:
5898
php: [ '8.2' ]
99+
coverage: [ false ]
100+
include:
101+
- php: '8.3'
102+
coverage: true
59103
runs-on: ubuntu-latest
60104

61105
steps:
@@ -67,7 +111,7 @@ jobs:
67111
with:
68112
php-version: '${{ matrix.php }}'
69113
ini-values: zend.assertions=1, error_reporting=-1, display_errors=On
70-
coverage: none
114+
coverage: ${{ matrix.coverage && 'xdebug' || 'none' }}
71115
tools: composer,cs2pr
72116

73117
- name: Install Composer dependencies & cache dependencies
@@ -93,4 +137,17 @@ jobs:
93137
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
94138

95139
- name: Run PHPUnit
96-
run: composer phpunit
140+
run: |
141+
if [[ ${{ matrix.coverage == true }} == true ]]; then
142+
composer phpunit -- --coverage-clover build/logs/unit-coverage.xml
143+
else
144+
composer phpunit
145+
fi
146+
147+
- name: Upload code coverage report
148+
if: ${{ matrix.coverage }}
149+
uses: codecov/codecov-action@v5.4.0
150+
with:
151+
directory: build/logs
152+
flags: unit
153+
token: ${{ secrets.CODECOV_TOKEN }}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.DS_Store
22
wp-cli.local.yml
3+
build/
34
node_modules/
45
vendor/
56
src/vendor/

0 commit comments

Comments
 (0)