From b2b8af4216eee67a5340390b314f53e6a9b30a8b Mon Sep 17 00:00:00 2001 From: marcusquinn <6428977+marcusquinn@users.noreply.github.com> Date: Fri, 18 Apr 2025 18:47:42 +0100 Subject: [PATCH] Fix unit test: set up add_action mock before Admin instantiation and use Mockery::type('callable') for callback argument --- tests/test-admin.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test-admin.php b/tests/test-admin.php index 56a4b31..2c72548 100644 --- a/tests/test-admin.php +++ b/tests/test-admin.php @@ -39,14 +39,14 @@ class AdminTest extends \WP_Mock\Tools\TestCase { // Mock Core class $this->core = $this->createMock(Core::class); - // Instantiate the class under test first - $this->admin = new Admin($this->core); - - // Set up WordPress function mocks after instantiation to use the correct object reference + // Set up WordPress function mocks BEFORE instantiating Admin WP_Mock::userFunction('add_action', [ 'times' => 1, - 'args' => ['admin_enqueue_scripts', [$this->admin, 'enqueue_admin_assets']] + 'args' => ['admin_enqueue_scripts', \Mockery::type('callable')] ]); + + // Instantiate the class under test + $this->admin = new Admin($this->core); } /**