[wp-trac] [WordPress Trac] #36786: Can't pass filter names to `MockAction::get_call_count()`

WordPress Trac noreply at wordpress.org
Fri Sep 3 08:15:41 UTC 2021


#36786: Can't pass filter names to `MockAction::get_call_count()`
-------------------------------------------------+-------------------------
 Reporter:  dlh                                  |       Owner:  (none)
     Type:  defect (bug)                         |      Status:  new
 Priority:  normal                               |   Milestone:  Future
                                                 |  Release
Component:  Build/Test Tools                     |     Version:
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch needs-testing needs-       |     Focuses:
  refresh                                        |
-------------------------------------------------+-------------------------
Changes (by gaambo):

 * keywords:  has-patch needs-testing has-unit-tests => has-patch needs-
     testing needs-refresh


Comment:

 Actually, it's not the `action` and `filter` key that need to be compared
 (that was my first thought too), but the `tag` key. Naming of
 `action`/`filter`/`tag` in the `MockAction` class is kind of confusing on
 first look.
 The `events` array stores all called hooks in an array, where the key
 `action` or `filter` is the callback function and `tag` is the action
 -/filter-name (as the first parameter in `do_action`/`apply_filters`),
 that's kind of confusing, but I didn't want to change all of the naming in
 this class, because that might be a bigger change and the event property
 is also public (and may be used in other ways I can't find). If I should
 do the renaming, just let me know.

 I also had to fix some rest-api tests because they were using this
 function in a wrong way. If I understand the function comment correctly,
 `$tag` is the hook name (action/filter as the first parameter in
 `do_action` and `apply_filters`). But the tests were passing the callback
 function as parameter (to get the call count of this specific function). I
 removed the attribute from the function callings in the rest-api test and
 all tests are running fine.
 I don't see any other place in which `get_call_count` is called in this
 way. But if needed, we could add a `get_function_call_count` function to
 check for the call count of the function.

 Here is the refreshed patch.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/36786#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list