Skip to content

Commit be0fb40

Browse files
committed
Tests: add code coverage configuration
* PHPUnit config: add code coverage configuration. By default, when there is a code coverage configuration and Xdebug is enabled, code coverage will be generated. For now, code coverage is set up for local use with an HTML code coverage report being generated in a `build/logs/` directory. Note: generating code coverage is slow. * Git ignore the `build` directory as created by PHPUnit to store the log files. * Adjust the "normal" test script to not generate code coverage information. * Add a `bin/unit-tests-coverage` to run the unit tests with code coverage enabled. * Add a Composer script to call the `unit-tests-coverage` script.
1 parent a3334db commit be0fb40

File tree

5 files changed

+38
-7
lines changed

5 files changed

+38
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
build/
12
vendor/
23
composer.lock
34
phpcs.xml

bin/unit-tests

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
# ./bin/unit-tests
1111
#
1212

13-
"$(pwd)/vendor/bin/phpunit" --filter WordPressVIPMinimum "$(pwd)/vendor/squizlabs/php_codesniffer/tests/AllTests.php"
13+
"$(pwd)/vendor/bin/phpunit" --filter WordPressVIPMinimum "$(pwd)/vendor/squizlabs/php_codesniffer/tests/AllTests.php" --no-coverage

bin/unit-tests-coverage

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Run the unit tests with code coverage.
4+
#
5+
# This ensures that the logic in the VIP sniffs is covered by unit tests.
6+
#
7+
# EXAMPLE TO RUN LOCALLY:
8+
#
9+
# ./bin/unit-tests-coverage
10+
#
11+
12+
"$(pwd)/vendor/bin/phpunit" --filter WordPressVIPMinimum "$(pwd)/vendor/squizlabs/php_codesniffer/tests/AllTests.php"

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
],
3939
"phpcs": "bin/phpcs",
4040
"phpunit": "bin/unit-tests",
41+
"coverage": "bin/unit-tests-coverage",
4142
"test": [
4243
"@lint",
4344
"@ruleset",

phpunit.xml.dist

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.2/phpunit.xsd"
5-
backupGlobals="true"
6-
bootstrap="./tests/bootstrap.php"
7-
beStrictAboutTestsThatDoNotTestAnything="false"
8-
colors="true">
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.2/phpunit.xsd"
5+
backupGlobals="true"
6+
bootstrap="./tests/bootstrap.php"
7+
beStrictAboutTestsThatDoNotTestAnything="false"
8+
colors="true"
9+
>
10+
<testsuites>
11+
<testsuite name="VIPCS_Sniffs">
12+
<directory suffix="UnitTest.php">./WordPressVIPMinimum/Tests/</directory>
13+
</testsuite>
14+
</testsuites>
15+
16+
<filter>
17+
<whitelist addUncoveredFilesFromWhitelist="true">
18+
<directory suffix=".php">./WordPressVIPMinimum/Sniffs/</directory>
19+
</whitelist>
20+
</filter>
21+
22+
<logging>
23+
<log type="coverage-html" target="./build/logs/"/>
24+
</logging>
25+
926
</phpunit>

0 commit comments

Comments
 (0)