Fix: Instantiate Admin before setting add_action mock to use correct object reference

This commit is contained in:
2025-04-18 18:44:29 +01:00
parent 4d69c446db
commit a0df887d5c

View File

@@ -39,14 +39,14 @@ class AdminTest extends \WP_Mock\Tools\TestCase {
// Mock Core class
$this->core = $this->createMock(Core::class);
// Set up WordPress function mocks
// 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
WP_Mock::userFunction('add_action', [
'times' => 1,
'args' => ['admin_enqueue_scripts', [$this->admin, 'enqueue_admin_assets']]
]);
// Instantiate the class under test *after* setting up mocks
$this->admin = new Admin($this->core);
}
/**