0

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?

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.