From dbe1a99bc1dfe89ed93538b0dd3c8a4c2e665a6c Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Mon, 29 Jan 2024 17:04:54 +0530 Subject: [PATCH 1/9] Plugin test suite --- .github/workflows/php-test-plugins.yml | 75 ++++++++++++++++++++++++++ phpunit.xml.dist | 6 ++- 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/php-test-plugins.yml diff --git a/.github/workflows/php-test-plugins.yml b/.github/workflows/php-test-plugins.yml new file mode 100644 index 0000000000..42ec733803 --- /dev/null +++ b/.github/workflows/php-test-plugins.yml @@ -0,0 +1,75 @@ +name: Unit Testing for Plugins + +on: + push: + branches: + - trunk + - 'release/**' + # Only run if PHP-related files changed. + paths: + - '.github/workflows/php-test-plugins.yml' + - '**.php' + - '.wp-env.json' + - '**/package.json' + - 'package-lock.json' + - 'phpunit.xml.dist' + - 'tests/multisite.xml' + - 'composer.json' + - 'composer.lock' + pull_request: + branches: + - trunk + - 'release/**' + - 'feature/**' + # Only run if PHP-related files changed. + paths: + - '.github/workflows/php-test-plugins.yml' + - '**.php' + - '.wp-env.json' + - '**/package.json' + - 'package-lock.json' + - 'phpunit.xml.dist' + - 'tests/multisite.xml' + - 'composer.json' + - 'composer.lock' + types: + - opened + - reopened + - synchronize + +jobs: + php-test-plugins: + name: "PHP ${{ matrix.php }} / WP ${{ matrix.wp }}" + runs-on: ubuntu-latest + timeout-minutes: 20 + strategy: + fail-fast: false + matrix: + php: ['8.2', '8.1', '8.0', '7.4', '7.3', '7.2', '7.1', '7.0'] + wp: [ 'latest' ] + include: + - php: '7.4' + wp: '6.3' + - php: '8.3' + wp: 'trunk' + env: + WP_ENV_PHP_VERSION: ${{ matrix.php }} + WP_ENV_CORE: ${{ matrix.wp == 'trunk' && 'WordPress/WordPress' || format( 'https://wordpress.org/wordpress-{0}.zip', matrix.wp ) }} + steps: + - uses: styfle/cancel-workflow-action@0.11.0 + - uses: actions/checkout@v3 + - name: Setup Node.js (.nvmrc) + uses: actions/setup-node@v3 + with: + node-version-file: '.nvmrc' + cache: npm + - name: Composer update + run: composer update + - name: npm install + run: npm ci + - name: Install WordPress + run: npm run wp-env start + - name: Running single site unit tests + run: npm run test-php -- -- --testsuite=webp-uploads + - name: Running multisite unit tests + run: npm run test-php-multisite -- -- --testsuite=webp-uploads diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 2f7d70a9ec..783f03b849 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -9,7 +9,11 @@ ./tests - ./tests/utils + ./tests/utils + ./tests/plugins + + + ./tests/plugins/webp-uploads From cef64a3060a069fd15fae1af3bb5820924e7d5ba Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Mon, 29 Jan 2024 17:18:01 +0530 Subject: [PATCH 2/9] Add test file --- tests/plugins/webp-uploads/test-plugins.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 tests/plugins/webp-uploads/test-plugins.php diff --git a/tests/plugins/webp-uploads/test-plugins.php b/tests/plugins/webp-uploads/test-plugins.php new file mode 100644 index 0000000000..d5ca85241b --- /dev/null +++ b/tests/plugins/webp-uploads/test-plugins.php @@ -0,0 +1,16 @@ +assertTrue( true ); + } +} From 8a40b2c485f9090c59e5988cbbecfca9f78e7f32 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Mon, 29 Jan 2024 17:28:13 +0530 Subject: [PATCH 3/9] Run test for branch --- .github/workflows/php-test-plugins.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/php-test-plugins.yml b/.github/workflows/php-test-plugins.yml index 42ec733803..f20737db1d 100644 --- a/.github/workflows/php-test-plugins.yml +++ b/.github/workflows/php-test-plugins.yml @@ -21,6 +21,7 @@ on: - trunk - 'release/**' - 'feature/**' + - 'fix/399-unit-tests-in-php-versions' # Only run if PHP-related files changed. paths: - '.github/workflows/php-test-plugins.yml' From 43b630a07476cef8d035b276e1994e4e762f3eb6 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Tue, 30 Jan 2024 10:11:45 +0530 Subject: [PATCH 4/9] Update test command --- .github/workflows/php-test-plugins.yml | 7 +++---- composer.json | 4 ++-- phpunit.xml.dist | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/php-test-plugins.yml b/.github/workflows/php-test-plugins.yml index f20737db1d..97e779549e 100644 --- a/.github/workflows/php-test-plugins.yml +++ b/.github/workflows/php-test-plugins.yml @@ -1,4 +1,4 @@ -name: Unit Testing for Plugins +name: Unit Testing for WebP Uploads Plugin on: push: @@ -21,7 +21,6 @@ on: - trunk - 'release/**' - 'feature/**' - - 'fix/399-unit-tests-in-php-versions' # Only run if PHP-related files changed. paths: - '.github/workflows/php-test-plugins.yml' @@ -71,6 +70,6 @@ jobs: - name: Install WordPress run: npm run wp-env start - name: Running single site unit tests - run: npm run test-php -- -- --testsuite=webp-uploads + run: npm run test-php -- -- -- --testsuite webp-uploads - name: Running multisite unit tests - run: npm run test-php-multisite -- -- --testsuite=webp-uploads + run: npm run test-php-multisite -- -- -- --testsuite webp-uploads diff --git a/composer.json b/composer.json index f2071e17e7..cfc380bf5d 100644 --- a/composer.json +++ b/composer.json @@ -32,8 +32,8 @@ "composer --working-dir=build-cs update --no-interaction", "build-cs/vendor/bin/phpcs --standard=phpcs.xml.dist" ], - "test": "phpunit -c phpunit.xml.dist --verbose", - "test-multisite": "phpunit -c tests/multisite.xml --verbose" + "test": "phpunit -c phpunit.xml.dist --verbose --testsuite=performance-lab", + "test-multisite": "phpunit -c tests/multisite.xml --verbose --testsuite=performance-lab" }, "config": { "allow-plugins": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 783f03b849..f527f02bae 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -7,7 +7,7 @@ convertWarningsToExceptions="true" > - + ./tests ./tests/utils ./tests/plugins From 54ca2e65690f139645dbd78f050a68c3152ea697 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Tue, 30 Jan 2024 10:27:03 +0530 Subject: [PATCH 5/9] Update unit test command --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index cfc380bf5d..a159d41960 100644 --- a/composer.json +++ b/composer.json @@ -32,8 +32,8 @@ "composer --working-dir=build-cs update --no-interaction", "build-cs/vendor/bin/phpcs --standard=phpcs.xml.dist" ], - "test": "phpunit -c phpunit.xml.dist --verbose --testsuite=performance-lab", - "test-multisite": "phpunit -c tests/multisite.xml --verbose --testsuite=performance-lab" + "test": "phpunit -c phpunit.xml.dist --verbose --testsuite performance-lab", + "test-multisite": "phpunit -c tests/multisite.xml --verbose --testsuite performance-lab" }, "config": { "allow-plugins": { From 4d186630e5d10666da53dc0c119d236453eea843 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Mon, 5 Feb 2024 14:04:32 +0530 Subject: [PATCH 6/9] Add another test --- tests/plugins/webp-uploads/test-plugins.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/plugins/webp-uploads/test-plugins.php b/tests/plugins/webp-uploads/test-plugins.php index d5ca85241b..8b5f80e809 100644 --- a/tests/plugins/webp-uploads/test-plugins.php +++ b/tests/plugins/webp-uploads/test-plugins.php @@ -13,4 +13,8 @@ class PluginTest extends WP_UnitTestCase { public function test_plugin_does_not_fatal() { $this->assertTrue( true ); } + + public function test_another_plugin_does_not_fatal() { + $this->assertTrue( true ); + } } From c75b3dc2cb6df13ca3ae3605ea69bb4c89fd8ba5 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Mon, 5 Feb 2024 21:36:44 +0530 Subject: [PATCH 7/9] Revert changes --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index acb638d468..991a107f24 100644 --- a/composer.json +++ b/composer.json @@ -25,8 +25,8 @@ "phpstan": "build-cs/vendor/bin/phpstan analyse --memory-limit=2048M -c phpstan.neon.dist", "format": "build-cs/vendor/bin/phpcbf --standard=phpcs.xml.dist --report-summary --report-source", "lint": "build-cs/vendor/bin/phpcs --standard=phpcs.xml.dist", - "test": "phpunit -c phpunit.xml.dist --verbose", - "test-multisite": "phpunit -c tests/multisite.xml --verbose" + "test": "phpunit -c phpunit.xml.dist --verbose --testsuite performance-lab", + "test-multisite": "phpunit -c tests/multisite.xml --verbose --testsuite performance-lab" }, "config": { "allow-plugins": { From ecd9d21199dc45c3466c8e685b4cf9365ece363b Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Mon, 5 Feb 2024 21:48:09 +0530 Subject: [PATCH 8/9] Adjust composer update --- .github/workflows/php-test-plugins.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/php-test-plugins.yml b/.github/workflows/php-test-plugins.yml index 97e779549e..59e7a9698b 100644 --- a/.github/workflows/php-test-plugins.yml +++ b/.github/workflows/php-test-plugins.yml @@ -63,12 +63,15 @@ jobs: with: node-version-file: '.nvmrc' cache: npm - - name: Composer update - run: composer update - name: npm install run: npm ci - name: Install WordPress run: npm run wp-env start + # Note that `composer update` is required instead of `composer install` + # for the sake of PHP versions older than 8.1, which is the version of + # PHP that the composer.lock was created for. + - name: Composer update + run: npm run wp-env run tests-cli -- --env-cwd="wp-content/plugins/$(basename $(pwd))" composer update --no-interaction - name: Running single site unit tests run: npm run test-php -- -- -- --testsuite webp-uploads - name: Running multisite unit tests From 500fb914f2e7998e8435cb22bf0dcc2ee6bc7477 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Tue, 6 Feb 2024 09:28:59 +0530 Subject: [PATCH 9/9] Update plugin name to Test Plugin --- .github/workflows/php-test-plugins.yml | 6 +++--- phpunit.xml.dist | 4 ++-- .../test-plugins.php => test-plugin/test-plugin.php} | 0 3 files changed, 5 insertions(+), 5 deletions(-) rename tests/plugins/{webp-uploads/test-plugins.php => test-plugin/test-plugin.php} (100%) diff --git a/.github/workflows/php-test-plugins.yml b/.github/workflows/php-test-plugins.yml index 59e7a9698b..679acf7383 100644 --- a/.github/workflows/php-test-plugins.yml +++ b/.github/workflows/php-test-plugins.yml @@ -1,4 +1,4 @@ -name: Unit Testing for WebP Uploads Plugin +name: Unit Testing for Test Plugin on: push: @@ -73,6 +73,6 @@ jobs: - name: Composer update run: npm run wp-env run tests-cli -- --env-cwd="wp-content/plugins/$(basename $(pwd))" composer update --no-interaction - name: Running single site unit tests - run: npm run test-php -- -- -- --testsuite webp-uploads + run: npm run test-php -- -- -- --testsuite test-plugin - name: Running multisite unit tests - run: npm run test-php-multisite -- -- -- --testsuite webp-uploads + run: npm run test-php-multisite -- -- -- --testsuite test-plugin diff --git a/phpunit.xml.dist b/phpunit.xml.dist index f527f02bae..081f11cdba 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -12,8 +12,8 @@ ./tests/utils ./tests/plugins - - ./tests/plugins/webp-uploads + + ./tests/plugins/test-plugin diff --git a/tests/plugins/webp-uploads/test-plugins.php b/tests/plugins/test-plugin/test-plugin.php similarity index 100% rename from tests/plugins/webp-uploads/test-plugins.php rename to tests/plugins/test-plugin/test-plugin.php