From a6d5694cde82b6a39a53ca0e9e348b7794b7bd26 Mon Sep 17 00:00:00 2001 From: Tonya Mork Date: Tue, 16 Jul 2024 18:20:43 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@58738 602fd350-edb4-49c9-b593-d223f7449a82 --- .../interactivity-api/wpInteractivityAPIFunctions.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/phpunit/tests/interactivity-api/wpInteractivityAPIFunctions.php b/tests/phpunit/tests/interactivity-api/wpInteractivityAPIFunctions.php index 8a59f181a3b99..f5089dd04b86e 100644 --- a/tests/phpunit/tests/interactivity-api/wpInteractivityAPIFunctions.php +++ b/tests/phpunit/tests/interactivity-api/wpInteractivityAPIFunctions.php @@ -332,16 +332,18 @@ public function test_process_directives_when_block_is_filtered() { ), ) ); - function test_render_block_data( $parsed_block ) { + + $test_render_block_data = static function ( $parsed_block ) { $parsed_block['testKey'] = true; return $parsed_block; - } - add_filter( 'render_block_data', 'test_render_block_data' ); + }; + + add_filter( 'render_block_data', $test_render_block_data ); $post_content = ''; $processed_content = do_blocks( $post_content ); $processor = new WP_HTML_Tag_Processor( $processed_content ); $processor->next_tag( array( 'data-wp-interactive' => 'nameSpace' ) ); - remove_filter( 'render_block_data', 'test_render_block_data' ); + remove_filter( 'render_block_data', $test_render_block_data ); unregister_block_type( 'test/custom-directive-block' ); $this->assertSame( 'test', $processor->get_attribute( 'value' ) ); }