I’m currently doing code coverage tests for a WordPress child theme and having issue to cover php files in the patterns folder. example below is for patterns/header.php.
If I created a test file and included the file using require, I got risky warning from phpunit
There was 1 risky test:
1) headerTest::testheader
This test executed code that is not listed as code to be covered or used:
- /opt/homebrew/var/www/wp-content/themes/flex/patterns/header.php:10
- /opt/homebrew/var/www/wp-content/themes/flex/patterns/header.php:11
- /opt/homebrew/var/www/wp-content/themes/flex/patterns/header.php:12
- /opt/homebrew/var/www/wp-content/themes/flex/patterns/header.php:13
- /opt/homebrew/var/www/wp-content/themes/flex/patterns/header.php:14
- /opt/homebrew/var/www/wp-content/themes/flex/patterns/header.php:15
- /opt/homebrew/var/www/wp-content/themes/flex/patterns/header.php:16
- /opt/homebrew/var/www/wp-content/themes/flex/patterns/header.php:29
/opt/homebrew/var/www/wp-content/tests/themes/patterns/headerTest.php:23
And it didn’t get counted in the coverage data.
<file name="/opt/homebrew/var/www/wp-content/themes/flex/patterns/header.php">
<line num="10" type="stmt" count="0"/>
<line num="11" type="stmt" count="0"/>
<line num="12" type="stmt" count="0"/>
<line num="13" type="stmt" count="0"/>
<line num="14" type="stmt" count="0"/>
<line num="15" type="stmt" count="0"/>
<line num="16" type="stmt" count="0"/>
<line num="29" type="stmt" count="0"/>
<metrics loc="41" ncloc="35" classes="0" methods="0" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="8" coveredstatements="0" elements="8" coveredelements="0"/>
</file>
Other themes files we successfuly covered with test files using attributes such as #[CoversFunction] and #[CoversClass].
You need to sign in to view this answers
Leave feedback about this