Make WordPress Core

Changeset 58738


Ignore:
Timestamp:
07/16/2024 06:20:43 PM (3 months ago)
Author:
hellofromTonya
Message:

Tests: Don't declare nested named function in Tests_Interactivity_API_wpInteractivityAPIFunctions.

Once the test_process_directives_when_block_is_filtered() method has run, the named test_render_block_data() function declared nested within becomes part of the global namespace, which could cause problems for other tests.

Quite apart from the fact that the name starting with test_ is confusing (as methods prefixed with test_ are supposed to be test methods to be run by PHPUnit).

Using a closure for this callback fixes the issue. Declared as static for a micro-optimization.

Follow-up to [57826].

Props jrf, hellofromTonya.
See #61530.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPIFunctions.php

    r58594 r58738  
    333333            )
    334334        );
    335         function test_render_block_data( $parsed_block ) {
     335
     336        $test_render_block_data = static function ( $parsed_block ) {
    336337            $parsed_block['testKey'] = true;
    337338            return $parsed_block;
    338         }
    339         add_filter( 'render_block_data', 'test_render_block_data' );
     339        };
     340
     341        add_filter( 'render_block_data', $test_render_block_data );
    340342        $post_content      = '<!-- wp:test/custom-directive-block /-->';
    341343        $processed_content = do_blocks( $post_content );
    342344        $processor         = new WP_HTML_Tag_Processor( $processed_content );
    343345        $processor->next_tag( array( 'data-wp-interactive' => 'nameSpace' ) );
    344         remove_filter( 'render_block_data', 'test_render_block_data' );
     346        remove_filter( 'render_block_data', $test_render_block_data );
    345347        unregister_block_type( 'test/custom-directive-block' );
    346348        $this->assertSame( 'test', $processor->get_attribute( 'value' ) );
Note: See TracChangeset for help on using the changeset viewer.