I am writing tests that execute some of WordPress hooks / actions
My hook example
add_filter("asdasd", static function() {
echo 'asdf';
});
It's complaining:
This test executed code that is not listed as code to be covered or used:
- /var/www/html/wp-content/themes/theme-1/init.php:123
Where line 123 is echo
I can get around this by using a named function like this
function my_asdasd() {
echo 'asdf';
}
add_filter("asdasd", 'my_asdasd');
And then add my_asdasd to CoversFunction tag in the test suite
My question, how do I use closure function from example 1 while pleasing phpunit that I intended to cover the code?
I am writing tests that execute some of WordPress hooks / actions
My hook example
add_filter("asdasd", static function() {
echo 'asdf';
});
It's complaining:
This test executed code that is not listed as code to be covered or used:
- /var/www/html/wp-content/themes/theme-1/init.php:123
Where line 123 is echo
I can get around this by using a named function like this
function my_asdasd() {
echo 'asdf';
}
add_filter("asdasd", 'my_asdasd');
And then add my_asdasd to CoversFunction tag in the test suite
My question, how do I use closure function from example 1 while pleasing phpunit that I intended to cover the code?
You can try wrapping the function, put all of the filters / actions there For example
function my_init()
{
add_filter("asdasd", static function() {
echo 'asdf';
});
}
my_init();
Then on phpunit you can declare to collect coverage from my_init