Skip to content

Commit

Permalink
Merge pull request #956 from WordPress/add/plugins-test-suite
Browse files Browse the repository at this point in the history
Add test suite for Plugins folder
  • Loading branch information
mukeshpanchal27 authored Feb 6, 2024
2 parents 8c04816 + 500fb91 commit 4c21e8f
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 4 deletions.
78 changes: 78 additions & 0 deletions .github/workflows/php-test-plugins.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Unit Testing for Test Plugin

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/[email protected]
- uses: actions/checkout@v3
- name: Setup Node.js (.nvmrc)
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: npm
- 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 test-plugin
- name: Running multisite unit tests
run: npm run test-php-multisite -- -- -- --testsuite test-plugin
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
8 changes: 6 additions & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
convertWarningsToExceptions="true"
>
<testsuites>
<testsuite name="default">
<testsuite name="performance-lab">
<directory suffix=".php">./tests</directory>
<exclude>./tests/utils</exclude>
<exclude>./tests/utils</exclude>
<exclude>./tests/plugins</exclude>
</testsuite>
<testsuite name="test-plugin">
<directory suffix=".php">./tests/plugins/test-plugin</directory>
</testsuite>
</testsuites>
<groups>
Expand Down
20 changes: 20 additions & 0 deletions tests/plugins/test-plugin/test-plugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* Class Plugin Test Suite
*
* @package performance-lab
*/

/**
* Plugin test case.
*/
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 );
}
}

0 comments on commit 4c21e8f

Please sign in to comment.