From ed7d33e2aa8fe7336c258f958d7a46aff1bac356 Mon Sep 17 00:00:00 2001 From: marcusquinn <6428977+marcusquinn@users.noreply.github.com> Date: Fri, 18 Apr 2025 19:53:40 +0100 Subject: [PATCH] Fix: Mock wp_localize_script in AdminTest - Adds WP_Mock::userFunction for wp_localize_script to resolve PHPUnit error. Fix: Revert underscore prefix for unused param - Removes underscore from hook_suffix in Admin class. - Relies on existing @phpcs:ignore directive. --- includes/Admin/class-admin.php | 4 ++-- tests/test-admin.php | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/includes/Admin/class-admin.php b/includes/Admin/class-admin.php index f9a4b60..649cb57 100644 --- a/includes/Admin/class-admin.php +++ b/includes/Admin/class-admin.php @@ -41,11 +41,11 @@ class Admin { /** * Enqueues admin scripts and styles. * - * @param string $_hook_suffix The current admin page. + * @param string $hook_suffix The current admin page. * * @phpcs:ignore WordPress.CodeAnalysis.UnusedFunctionParameter.Found */ - public function enqueue_admin_assets( string $_hook_suffix ) { + public function enqueue_admin_assets( string $hook_suffix ) { // Enqueue admin styles. \wp_enqueue_style( 'wpst-admin-style', diff --git a/tests/test-admin.php b/tests/test-admin.php index 48d3f6e..7e61580 100644 --- a/tests/test-admin.php +++ b/tests/test-admin.php @@ -95,6 +95,19 @@ class AdminTest extends \WP_Mock\Tools\TestCase { ] ); + // Expect wp_localize_script to be called + \WP_Mock::userFunction( + 'wp_localize_script', + [ + 'times' => 1, + 'args' => [ + $script_handle, + 'wpst_admin_params', + \Mockery::type( 'array' ), // We don't need to assert the exact array content here + ], + ] + ); + // Call the method under test. $this->admin->enqueue_admin_assets( 'test-hook' );