Fix unit test: set up add_action mock before Admin instantiation and use Mockery::type('callable') for callback argument

This commit is contained in:
2025-04-18 18:47:42 +01:00
parent a0df887d5c
commit b2b8af4216

View File

@@ -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);
}
/**