From 643f5c6d41525c58ea33ada91a55a8780eddb55c Mon Sep 17 00:00:00 2001 From: marcusquinn <6428977+marcusquinn@users.noreply.github.com> Date: Fri, 18 Apr 2025 19:07:05 +0100 Subject: [PATCH] Fix: Resolve CI dependency conflicts and PHPCS/PHPUnit errors --- .github/workflows/tests.yml | 16 +++++++++------- includes/Admin/class-admin.php | 17 +++++++++-------- tests/test-admin.php | 4 ++-- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3fd6c7d..8b3248b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -28,15 +28,17 @@ jobs: - name: Install dependencies run: | - if [[ "${{ matrix.php-versions }}" == "7.0" ]]; then + # Install base dependencies from lock file + composer install --prefer-dist --no-progress + + # Update specific dependencies for higher PHP versions if needed + if [[ "${{ matrix.php-versions }}" == "7.4" || "${{ matrix.php-versions }}" == "8.0" ]]; then + echo "Updating dependencies for PHP ${{ matrix.php-versions }}..." + composer require --dev phpunit/phpunit:"^9.5" 10up/wp_mock:"^1.0" --no-update --no-plugins --no-scripts + elif [[ "${{ matrix.php-versions }}" == "7.0" ]]; then # Force PHPUnit 6.5 for PHP 7.0 composer require --dev phpunit/phpunit:"^6.5" --update-with-dependencies - elif [[ "${{ matrix.php-versions }}" == "8.0" ]]; then - # Update PHPUnit and WP_Mock for PHP 8.0 - composer require --dev phpunit/phpunit:"^9.5" 10up/wp_mock:"^1.0" --no-update fi - # Update all dependencies based on composer.json/composer.lock and any modifications above - composer update --prefer-dist --no-progress - name: Run tests run: ./vendor/bin/phpunit @@ -57,7 +59,7 @@ jobs: tools: composer:v2, phpcs - name: Install dependencies - run: composer update --prefer-dist --no-progress + run: composer install --prefer-dist --no-progress - name: Run PHPCS run: ./vendor/bin/phpcs --standard=WordPress ./includes ./admin ./wp-plugin-starter-template.php diff --git a/includes/Admin/class-admin.php b/includes/Admin/class-admin.php index aabb4ce..cc4e669 100644 --- a/includes/Admin/class-admin.php +++ b/includes/Admin/class-admin.php @@ -27,7 +27,6 @@ class Admin { * @param Core $core Core instance. */ public function __construct( Core $core ) { - error_log('Admin::__construct called'); $this->core = $core; $this->initialize_hooks(); } @@ -36,32 +35,34 @@ class Admin { * Initializes WordPress hooks. */ private function initialize_hooks() { - error_log('Admin::initialize_hooks called'); \add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_assets' ) ); } /** - * Enqueues admin-specific assets. + * Enqueues admin scripts and styles. * * @param string $hook_suffix The current admin page. + * @phpcs:ignore WordPress.CodeAnalysis.UnusedFunctionParameter.Found */ public function enqueue_admin_assets( $hook_suffix ) { - // Enqueue admin styles + // Enqueue admin styles. \wp_enqueue_style( 'wpst-admin-style', - 'path/to/admin/css/admin-styles.css' + 'path/to/admin/css/admin-styles.css', + array(), // Dependencies + $this->core->get_plugin_version() // Version ); - // Enqueue admin scripts + // Enqueue admin scripts. \wp_enqueue_script( 'wpst-admin-script', 'path/to/admin/js/admin-scripts.js', array( 'jquery' ), - null, + $this->core->get_plugin_version(), // Version true ); - // Localize script + // Localize script. \wp_localize_script( 'wpst-admin-script', 'wpst_admin_params', diff --git a/tests/test-admin.php b/tests/test-admin.php index bdff9d3..72bbd5e 100644 --- a/tests/test-admin.php +++ b/tests/test-admin.php @@ -30,7 +30,7 @@ class AdminTest extends \WP_Mock\Tools\TestCase { /** * Set up test environment */ - public function setUp() { + public function setUp(): void { parent::setUp(); // Set up mocks @@ -46,7 +46,7 @@ class AdminTest extends \WP_Mock\Tools\TestCase { /** * Tear down test environment */ - public function tearDown() { + public function tearDown(): void { WP_Mock::tearDown(); parent::tearDown(); }