From 95e4361cd5a56e2c771618de8bc3fa9ef0c08bdd Mon Sep 17 00:00:00 2001 From: marcusquinn <6428977+marcusquinn@users.noreply.github.com> Date: Fri, 18 Apr 2025 19:16:11 +0100 Subject: [PATCH] Fix: Correct AdminTest setup and PHPCS docblock formatting --- includes/Admin/class-admin.php | 4 +--- tests/test-admin.php | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/includes/Admin/class-admin.php b/includes/Admin/class-admin.php index bd5dc67..3db946c 100644 --- a/includes/Admin/class-admin.php +++ b/includes/Admin/class-admin.php @@ -42,9 +42,7 @@ class Admin { * Enqueues admin scripts and styles. * * @param string $hook_suffix The current admin page. - * @phpcs:ignore WordPress.CodeAnalysis.UnusedFunctionParameter.Found - * - */ + * @phpcs:ignore WordPress.CodeAnalysis.UnusedFunctionParameter.Found */ public function enqueue_admin_assets( $hook_suffix ) { // Enqueue admin styles. \wp_enqueue_style( diff --git a/tests/test-admin.php b/tests/test-admin.php index 72bbd5e..c75dbd1 100644 --- a/tests/test-admin.php +++ b/tests/test-admin.php @@ -28,19 +28,25 @@ class AdminTest extends \WP_Mock\Tools\TestCase { private $core; /** - * Set up test environment + * Set up the test environment. */ - public function setUp(): void { + public function setUp(): void + { parent::setUp(); // Set up mocks WP_Mock::setUp(); - // Mock Core class - $this->core = $this->createMock(Core::class); + // Mock the Core class dependency using Mockery. + $this->core = \Mockery::mock( '\WPALLSTARS\PluginStarterTemplate\Core' ); + // Add expectation for get_plugin_version BEFORE Admin is instantiated. + $this->core->shouldReceive( 'get_plugin_version' )->andReturn( '1.0.0' ); - // Instantiate the class under test - $this->admin = new Admin($this->core); + // Expect the action hook to be added BEFORE Admin is instantiated. + \WP_Mock::expectActionAdded( 'admin_enqueue_scripts', array( \Mockery::any(), 'enqueue_admin_assets' ) ); + + // Instantiate the Admin class (this triggers the constructor and add_hooks). + $this->admin = new Admin( $this->core ); } /** @@ -57,8 +63,6 @@ class AdminTest extends \WP_Mock\Tools\TestCase { public function test_constructor() { // Verify that the constructor initializes hooks $this->assertInstanceOf(Admin::class, $this->admin); - WP_Mock::expectActionAdded('admin_enqueue_scripts', [$this->admin, 'enqueue_admin_assets']); - } /**