Fix: Correct AdminTest setup and PHPCS docblock formatting

This commit is contained in:
2025-04-18 19:16:11 +01:00
parent 6d9a9658ea
commit 95e4361cd5
2 changed files with 13 additions and 11 deletions

View File

@@ -42,9 +42,7 @@ class Admin {
* Enqueues admin scripts and styles. * 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 * @phpcs:ignore WordPress.CodeAnalysis.UnusedFunctionParameter.Found */
*
*/
public function enqueue_admin_assets( $hook_suffix ) { public function enqueue_admin_assets( $hook_suffix ) {
// Enqueue admin styles. // Enqueue admin styles.
\wp_enqueue_style( \wp_enqueue_style(

View File

@@ -28,18 +28,24 @@ class AdminTest extends \WP_Mock\Tools\TestCase {
private $core; private $core;
/** /**
* Set up test environment * Set up the test environment.
*/ */
public function setUp(): void { public function setUp(): void
{
parent::setUp(); parent::setUp();
// Set up mocks // Set up mocks
WP_Mock::setUp(); WP_Mock::setUp();
// Mock Core class // Mock the Core class dependency using Mockery.
$this->core = $this->createMock(Core::class); $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 // 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 ); $this->admin = new Admin( $this->core );
} }
@@ -57,8 +63,6 @@ class AdminTest extends \WP_Mock\Tools\TestCase {
public function test_constructor() { public function test_constructor() {
// Verify that the constructor initializes hooks // Verify that the constructor initializes hooks
$this->assertInstanceOf(Admin::class, $this->admin); $this->assertInstanceOf(Admin::class, $this->admin);
WP_Mock::expectActionAdded('admin_enqueue_scripts', [$this->admin, 'enqueue_admin_assets']);
} }
/** /**