Make WordPress Core

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#47407 closed enhancement (fixed)

Documentation `tests_add_filter` function incorrect

Reported by: remcotolsma's profile remcotolsma Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 5.4 Priority: normal
Severity: normal Version:
Component: Build/Test Tools Keywords: has-patch
Focuses: Cc:

Description (last modified by SergeyBiryukov)

In [43555] some documentation was added for the tests_add_filter function. According the documentation the second parameter $function_to_add should be an array or an object:

@param object|array $function_to_add The function/callback to execute on call.

Should this not be changed to callable? Same as the add_filter function?
https://core.trac.wordpress.org/browser/trunk/src/wp-includes/plugin.php#L99

Scrutinizer is complaining about this:

'_manually_load_plugin' of type string is incompatible with the type array|object expected by parameter $function_to_add of tests_add_filter().

https://scrutinizer-ci.com/g/pronamic/wp-money/inspections/3724dc22-f4fb-46cd-90bc-0928063ae820/issues/files/tests/bootstrap.php?status=failed&conditionIds%5B0%5D=367219#

Attachments (1)

47407.diff (739 bytes) - added by donmhico 5 years ago.

Download all attachments as: .zip

Change History (7)

#1 @dkarfa
5 years ago

<?php
        
tests_add_filter( 'muplugins_loaded', array( $this, '_manually_load_plugin' ) );

public function _manually_load_plugin() {
    // Function to do.
} 

#2 @SergeyBiryukov
5 years ago

  • Description modified (diff)
  • Milestone changed from Awaiting Review to 5.4

@donmhico
5 years ago

#3 @donmhico
5 years ago

  • Keywords has-patch added; needs-patch removed

@remcotolsma - Thanks for the ticket report. What you said make sense, looking at tests_add_filter() code, it does pass $function_to_add to add_filter() so the param docs should be identical.

#4 @SergeyBiryukov
5 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 46801:

Docs: Correct @param type for the function parameter in tests_add_filter() and _test_filter_build_unique_id().

Synchronize documentation for add_filter(), tests_add_filter(), _wp_filter_build_unique_id(), _test_filter_build_unique_id().

Add a note that $tag and $priority are no longer used in _wp_filter_build_unique_id() since [46220], and the function always returns a string now.

Props donmhico, remcotolsma, SergeyBiryukov.
Fixes #47407. See #48303.

#5 @SergeyBiryukov
5 years ago

In 46805:

Plugins: In _wp_filter_build_unique_id(), remove $wp_filter global and $filter_id_count static variable, unused since [46220].

See #47407, #48074.

#6 @SergeyBiryukov
5 years ago

In 46806:

Tests: Merge [24251] from _wp_filter_build_unique_id() to _test_filter_build_unique_id(), for consistency.

See #47407.

Note: See TracTickets for help on using tickets.