File tree 10 files changed +49
-14
lines changed
10 files changed +49
-14
lines changed Original file line number Diff line number Diff line change @@ -61,28 +61,28 @@ commands:
61
61
usage : Run tests.
62
62
cmd : |
63
63
pushd "build" >/dev/null || exit 1
64
- vendor/bin/phpunit
64
+ php -d pcov.directory=.. vendor/bin/phpunit
65
65
popd >/dev/null || exit 1
66
66
67
67
test-unit :
68
68
usage : Run unit tests.
69
69
cmd : |
70
70
pushd "build" >/dev/null || exit 1
71
- vendor/bin/phpunit --testsuite unit "$@"
71
+ php -d pcov.directory=.. vendor/bin/phpunit --testsuite unit "$@"
72
72
popd >/dev/null || exit 1
73
73
74
74
test-kernel :
75
75
usage : Run kernel tests.
76
76
cmd : |
77
77
pushd "build" >/dev/null || exit 1
78
- vendor/bin/phpunit --testsuite kernel "$@"
78
+ php -d pcov.directory=.. vendor/bin/phpunit --testsuite kernel "$@"
79
79
popd >/dev/null || exit 1
80
80
81
81
test-functional :
82
82
usage : Run functional tests.
83
83
cmd : |
84
84
pushd "build" >/dev/null || exit 1
85
- vendor/bin/phpunit --testsuite functional "$@"
85
+ php -d pcov.directory=.. vendor/bin/phpunit --testsuite functional "$@"
86
86
popd >/dev/null || exit 1
87
87
88
88
reset :
Original file line number Diff line number Diff line change @@ -84,7 +84,7 @@ job-test: &job-test
84
84
85
85
- run :
86
86
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 ]
88
88
working_directory : build
89
89
environment :
90
90
BROWSERTEST_OUTPUT_DIRECTORY : /tmp
Original file line number Diff line number Diff line change @@ -111,7 +111,6 @@ jobs:
111
111
php-version : ${{ matrix.php-version }}
112
112
extensions : gd, sqlite, pdo_sqlite
113
113
coverage : pcov
114
- ini-values : pcov.directory=.
115
114
116
115
# Disable Symfony deprecations helper for PHP 8.4+ until minor
117
116
# versions of Drupal 10 and 11 fully support PHP 8.4.
@@ -156,7 +155,7 @@ jobs:
156
155
157
156
- name : Run tests
158
157
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 ]
160
159
env :
161
160
BROWSERTEST_OUTPUT_DIRECTORY : /tmp
162
161
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -185,3 +185,16 @@ assert_workflow_run() {
185
185
186
186
popd > /dev/null || exit 1
187
187
}
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
+ }
Original file line number Diff line number Diff line change 1
1
#! /usr/bin/env bats
2
2
3
3
load _helper
4
+ load _assert_functional
4
5
5
6
export BATS_FIXTURE_EXPORT_CODEBASE_ENABLED=1
6
7
@@ -121,6 +122,8 @@ export BATS_FIXTURE_EXPORT_CODEBASE_ENABLED=1
121
122
run ahoy test-unit
122
123
assert_success
123
124
125
+ assert_test_coverage
126
+
124
127
sed -i -e " s/assertEquals/assertNotEquals/g" " ${BUILD_DIR} /tests/src/Unit/YourExtensionServiceUnitTest.php"
125
128
run ahoy test-unit
126
129
assert_failure
Original file line number Diff line number Diff line change 1
1
#! /usr/bin/env bats
2
2
3
3
load _helper
4
+ load _assert_functional
4
5
5
6
export BATS_FIXTURE_EXPORT_CODEBASE_ENABLED=1
6
7
@@ -127,6 +128,8 @@ export BATS_FIXTURE_EXPORT_CODEBASE_ENABLED=1
127
128
run make test-unit
128
129
assert_success
129
130
131
+ assert_test_coverage
132
+
130
133
sed -i -e " s/assertEquals/assertNotEquals/g" " ${BUILD_DIR} /tests/src/Unit/YourExtensionServiceUnitTest.php"
131
134
run make test-unit
132
135
assert_failure
Original file line number Diff line number Diff line change @@ -66,22 +66,22 @@ lint-fix:
66
66
67
67
test :
68
68
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 && \
70
70
popd > /dev/null || exit 1
71
71
72
72
test-unit :
73
73
pushd " build" > /dev/null || exit 1 && \
74
- vendor/bin/phpunit --testsuite unit && \
74
+ php -d pcov.directory=.. vendor/bin/phpunit --testsuite unit && \
75
75
popd > /dev/null || exit 1
76
76
77
77
test-kernel :
78
78
pushd " build" > /dev/null || exit 1 && \
79
- vendor/bin/phpunit --testsuite kernel && \
79
+ php -d pcov.directory=.. vendor/bin/phpunit --testsuite kernel && \
80
80
popd > /dev/null || exit 1
81
81
82
82
test-functional :
83
83
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 && \
85
85
popd > /dev/null || exit 1
86
86
87
87
reset :
Original file line number Diff line number Diff line change @@ -170,8 +170,8 @@ You may also run tests using the `phpunit` command directly:
170
170
171
171
``` bash
172
172
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
175
175
```
176
176
177
177
---
Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ and push the code to [Drupal.org](https://drupal.org).
50
50
- Drupal version matrix: ` stable ` , ` canary ` and ` legacy ` .
51
51
- CI providers: [ GitHub Actions] ( .github/workflows/test.yml )
52
52
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 ) .
54
54
- Develop locally using PHP running on your host using
55
55
identical [ ` .devtools ` ] ( .devtools ) scripts as in CI:
56
56
- Uses [ drupal-composer/drupal-project] ( https://github.com/drupal-composer/drupal-project )
You can’t perform that action at this time.
0 commit comments