Skip to content

Commit f375e1c

Browse files
committed
Fixed PCOV not reporting coverage.
1 parent 3cf5ceb commit f375e1c

File tree

10 files changed

+49
-14
lines changed

10 files changed

+49
-14
lines changed

.ahoy.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -61,28 +61,28 @@ commands:
6161
usage: Run tests.
6262
cmd: |
6363
pushd "build" >/dev/null || exit 1
64-
vendor/bin/phpunit
64+
php -d pcov.directory=.. vendor/bin/phpunit
6565
popd >/dev/null || exit 1
6666
6767
test-unit:
6868
usage: Run unit tests.
6969
cmd: |
7070
pushd "build" >/dev/null || exit 1
71-
vendor/bin/phpunit --testsuite unit "$@"
71+
php -d pcov.directory=.. vendor/bin/phpunit --testsuite unit "$@"
7272
popd >/dev/null || exit 1
7373
7474
test-kernel:
7575
usage: Run kernel tests.
7676
cmd: |
7777
pushd "build" >/dev/null || exit 1
78-
vendor/bin/phpunit --testsuite kernel "$@"
78+
php -d pcov.directory=.. vendor/bin/phpunit --testsuite kernel "$@"
7979
popd >/dev/null || exit 1
8080
8181
test-functional:
8282
usage: Run functional tests.
8383
cmd: |
8484
pushd "build" >/dev/null || exit 1
85-
vendor/bin/phpunit --testsuite functional "$@"
85+
php -d pcov.directory=.. vendor/bin/phpunit --testsuite functional "$@"
8686
popd >/dev/null || exit 1
8787
8888
reset:

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ job-test: &job-test
8484

8585
- run:
8686
name: Run tests
87-
command: vendor/bin/phpunit || [ "${CI_TEST_IGNORE_FAILURE:-0}" -eq 1 ]
87+
command: php -d pcov.directory=.. vendor/bin/phpunit || [ "${CI_TEST_IGNORE_FAILURE:-0}" -eq 1 ]
8888
working_directory: build
8989
environment:
9090
BROWSERTEST_OUTPUT_DIRECTORY: /tmp

.github/workflows/test.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ jobs:
111111
php-version: ${{ matrix.php-version }}
112112
extensions: gd, sqlite, pdo_sqlite
113113
coverage: pcov
114-
ini-values: pcov.directory=.
115114

116115
# Disable Symfony deprecations helper for PHP 8.4+ until minor
117116
# versions of Drupal 10 and 11 fully support PHP 8.4.
@@ -156,7 +155,7 @@ jobs:
156155

157156
- name: Run tests
158157
working-directory: build
159-
run: vendor/bin/phpunit || [ "${CI_TEST_IGNORE_FAILURE:-0}" -eq 1 ]
158+
run: php -d pcov.directory=.. vendor/bin/phpunit || [ "${CI_TEST_IGNORE_FAILURE:-0}" -eq 1 ]
160159
env:
161160
BROWSERTEST_OUTPUT_DIRECTORY: /tmp
162161

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Functional assertions.
4+
#
5+
6+
assert_test_coverage() {
7+
local dir="${1:-$(pwd)}"
8+
pushd "${dir}" >/dev/null || exit 1
9+
10+
assert_file_exists ".logs/coverage/phpunit/cobertura.xml"
11+
assert_file_not_contains ".logs/coverage/phpunit/cobertura.xml" 'coverage line-rate="0"'
12+
13+
assert_file_exists ".logs/coverage/phpunit/.coverage-html/index.html"
14+
assert_file_contains ".logs/coverage/phpunit/.coverage-html/index.html" "33.33% covered"
15+
16+
popd >/dev/null || exit 1
17+
}

.scaffold/tests/bats/_assert_init.bash

+13
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,16 @@ assert_workflow_run() {
185185

186186
popd >/dev/null || exit 1
187187
}
188+
189+
assert_test_coverage() {
190+
local dir="${1:-$(pwd)}"
191+
pushd "${dir}" >/dev/null || exit 1
192+
193+
assert_file_exists ".logs/coverage/phpunit/cobertura.xml"
194+
assert_file_not_contains ".logs/coverage/phpunit/cobertura.xml" 'coverage line-rate="0"'
195+
196+
assert_file_exists ".logs/coverage/phpunit/.coverage-html/index.html"
197+
assert_file_contains ".logs/coverage/phpunit/.coverage-html/index.html" "33.33% covered"
198+
199+
popd >/dev/null || exit 1
200+
}

.scaffold/tests/bats/ahoy.bats renamed to .scaffold/tests/bats/functional.ahoy.bats

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env bats
22

33
load _helper
4+
load _assert_functional
45

56
export BATS_FIXTURE_EXPORT_CODEBASE_ENABLED=1
67

@@ -121,6 +122,8 @@ export BATS_FIXTURE_EXPORT_CODEBASE_ENABLED=1
121122
run ahoy test-unit
122123
assert_success
123124

125+
assert_test_coverage
126+
124127
sed -i -e "s/assertEquals/assertNotEquals/g" "${BUILD_DIR}/tests/src/Unit/YourExtensionServiceUnitTest.php"
125128
run ahoy test-unit
126129
assert_failure

.scaffold/tests/bats/make.bats renamed to .scaffold/tests/bats/functional.make.bats

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env bats
22

33
load _helper
4+
load _assert_functional
45

56
export BATS_FIXTURE_EXPORT_CODEBASE_ENABLED=1
67

@@ -127,6 +128,8 @@ export BATS_FIXTURE_EXPORT_CODEBASE_ENABLED=1
127128
run make test-unit
128129
assert_success
129130

131+
assert_test_coverage
132+
130133
sed -i -e "s/assertEquals/assertNotEquals/g" "${BUILD_DIR}/tests/src/Unit/YourExtensionServiceUnitTest.php"
131134
run make test-unit
132135
assert_failure

Makefile

+4-4
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,22 @@ lint-fix:
6666

6767
test:
6868
pushd "build" >/dev/null || exit 1 && \
69-
BROWSERTEST_OUTPUT_DIRECTORY=/tmp vendor/bin/phpunit && \
69+
BROWSERTEST_OUTPUT_DIRECTORY=/tmp php -d pcov.directory=.. vendor/bin/phpunit && \
7070
popd >/dev/null || exit 1
7171

7272
test-unit:
7373
pushd "build" >/dev/null || exit 1 && \
74-
vendor/bin/phpunit --testsuite unit && \
74+
php -d pcov.directory=.. vendor/bin/phpunit --testsuite unit && \
7575
popd >/dev/null || exit 1
7676

7777
test-kernel:
7878
pushd "build" >/dev/null || exit 1 && \
79-
vendor/bin/phpunit --testsuite kernel && \
79+
php -d pcov.directory=.. vendor/bin/phpunit --testsuite kernel && \
8080
popd >/dev/null || exit 1
8181

8282
test-functional:
8383
pushd "build" >/dev/null || exit 1 && \
84-
BROWSERTEST_OUTPUT_DIRECTORY=/tmp vendor/bin/phpunit --testsuite functional && \
84+
BROWSERTEST_OUTPUT_DIRECTORY=/tmp php -d pcov.directory=.. vendor/bin/phpunit --testsuite functional && \
8585
popd >/dev/null || exit 1
8686

8787
reset:

README.dist.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ You may also run tests using the `phpunit` command directly:
170170

171171
```bash
172172
cd build
173-
./vendor/bin/phpunit tests/src/Unit/MyUnitTest.php
174-
./vendor/bin/phpunit --group=wip
173+
php -d pcov.directory=.. vendor/bin/phpunit tests/src/Unit/MyUnitTest.php
174+
php -d pcov.directory=.. vendor/bin/phpunit --group=wip
175175
```
176176

177177
---

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ and push the code to [Drupal.org](https://drupal.org).
5050
- Drupal version matrix: `stable`, `canary` and `legacy`.
5151
- CI providers: [GitHub Actions](.github/workflows/test.yml)
5252
and [CircleCI](.circleci/config.yml)
53-
- Code coverage with [codecov.io](https://codecov.io).
53+
- Code coverage with https://github.com/krakjoe/pcov pushed to [codecov.io](https://codecov.io).
5454
- Develop locally using PHP running on your host using
5555
identical [`.devtools`](.devtools) scripts as in CI:
5656
- Uses [drupal-composer/drupal-project](https://github.com/drupal-composer/drupal-project)

0 commit comments

Comments
 (0)