10up / wp_mock

WordPress API Mocking Framework
https://wp-mock.gitbook.io
Other
676 stars 70 forks source link

When WP_Mock is included as dev-dependency, the IDE or static analyzers might flag some WP functions with uncaught exceptions #248

Closed unfulvio closed 4 months ago

unfulvio commented 4 months ago

Bug report

WP_Mock adds some function mocks for some common WP functions (mostly gettext related) that are expected to return the arg they are passed to (such as in gettext, when no translations are applied).

In WP_Mock because they are funneled to an handler, this could technically throw an assertion exception (relevant to tests only). However, because these mocks have the same name as WP functions, the result is that the IDE or some static analyzers will assume they will throw an uncaught exception in the codebase, which isn't true. The solution in #245 improves phpdocs so that this false positive should no longer happen.

Replication steps

This happened to me when working at some WP codebase where WP Mock was included as dev dependency in PHPStorm.

Expected behavior

PHPStorm shouldn't flag those functions as throwing exceptions, because that's not what they do in WP.