admin管理员组文章数量:1313598
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?
Share Improve this question asked Jan 31 at 2:00 RuslanRuslan 826 bronze badges1 Answer
Reset to default 0You 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
版权声明:本文标题:unit testing - PHPunit risky test with Unintentionally Covered Code in wordpress callbacks - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741928951a2405460.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论