Skip to content

Commit

Permalink
Merge pull request #544 from WordPress/fix/399-unit-tests-in-php-vers…
Browse files Browse the repository at this point in the history
…ions

Run tests in different versions of PHP
  • Loading branch information
swissspidy authored Jan 29, 2024
2 parents 0e7f285 + 20155d5 commit fc9ddfb
Show file tree
Hide file tree
Showing 23 changed files with 270 additions and 1,085 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/php-test-standalone-plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,38 @@ jobs:
name: PHP Integration Tests for Standalone Plugins
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
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
- name: Setup Node.js (.nvmrc)
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: npm
- name: npm install
run: npm ci
- name: General debug information
run: |
npm --version
node --version
composer --version
php -v
- name: Building standalone plugins
run: npm run build-plugins
- name: Running single site standalone plugin integration tests
Expand Down
17 changes: 16 additions & 1 deletion .github/workflows/php-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,22 @@ on:

jobs:
php-test:
name: PHP
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
Expand All @@ -50,6 +63,8 @@ jobs:
with:
node-version-file: '.nvmrc'
cache: npm
- name: Composer update
run: composer update
- name: npm install
run: npm ci
- name: Install WordPress
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ nbproject/

build
.wp-env.override.json
build-cs/vendor/
build-cs/composer.lock

############
## Vendor
Expand Down
3 changes: 1 addition & 2 deletions .wp-env.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"tests": {
"config": {
"FS_METHOD": "direct"
},
"phpVersion": "7.4"
}
}
}
}
23 changes: 19 additions & 4 deletions bin/plugin/commands/test-plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,18 @@ function doRunUnitTests( settings ) {
)
);

execSync(
`composer install --working-dir=${ settings.builtPluginsDir }${ plugin } --no-interaction`,
( err, output ) => {
if ( err ) {
log( formats.error( `${ err }` ) );
process.exit( 1 );
}
// log the output received from the command
log( output );
}
);

// Define multi site flag based on single vs multi sitetype arg.
const isMultiSite = 'multi' === settings.siteType;
let command = '';
Expand All @@ -325,8 +337,8 @@ function doRunUnitTests( settings ) {
'wp-env',
[
'run',
'phpunit',
`'WP_MULTISITE=1 phpunit -c /var/www/html/wp-content/plugins/${ plugin }/multisite.xml --verbose --testdox'`,
'tests-cli',
`--env-cwd=/var/www/html/wp-content/plugins/${ plugin } vendor/bin/phpunit -c multisite.xml --verbose --testdox`,
],
{ shell: true, encoding: 'utf8' }
);
Expand All @@ -335,8 +347,8 @@ function doRunUnitTests( settings ) {
'wp-env',
[
'run',
'phpunit',
`'phpunit -c /var/www/html/wp-content/plugins/${ plugin }/phpunit.xml --verbose --testdox'`,
'tests-cli',
`--env-cwd=/var/www/html/wp-content/plugins/${ plugin } vendor/bin/phpunit -c phpunit.xml --verbose --testdox`,
],
{ shell: true, encoding: 'utf8' }
);
Expand All @@ -345,6 +357,9 @@ function doRunUnitTests( settings ) {
log( command.stdout.replace( '\n', '' ) );

if ( 1 === command.status ) {
// Log error.
log( formats.error( command.stderr.replace( '\n', '' ) ) );

log(
formats.error(
`One or more tests failed for plugin ${ plugin }`
Expand Down
20 changes: 20 additions & 0 deletions build-cs/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.7",
"phpcompatibility/php-compatibility": "^9.3",
"phpstan/extension-installer": "^1.3.0",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-deprecation-rules": "^1.1",
"phpstan/phpstan-phpunit": "^1.3",
"slevomat/coding-standard": "^8.0",
"squizlabs/php_codesniffer": "^3.5",
"szepeviktor/phpstan-wordpress": "^1.3.0",
"wp-coding-standards/wpcs": "^3.0.0"
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"phpstan/extension-installer": true
}
}
}
33 changes: 16 additions & 17 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,34 @@
"issues": "https://github.com/WordPress/performance/issues"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.7",
"phpcompatibility/php-compatibility": "^9.3",
"phpstan/extension-installer": "^1.3.0",
"phpstan/phpstan": "^1.10",
"squizlabs/php_codesniffer": "^3.5",
"szepeviktor/phpstan-wordpress": "^1.3.0",
"wp-coding-standards/wpcs": "^3.0.0",
"wp-phpunit/wp-phpunit": "^5.8",
"yoast/phpunit-polyfills": "^1.0",
"phpstan/phpstan-phpunit": "^1.3",
"phpstan/phpstan-deprecation-rules": "^1.1",
"slevomat/coding-standard": "^8.0"
"yoast/phpunit-polyfills": "^1.0"
},
"require": {
"composer/installers": "~1.0",
"php": ">=7|^8"
},
"scripts": {
"phpstan": "phpstan analyze --ansi --memory-limit=2048M",
"format": "phpcbf --standard=phpcs.xml.dist --report-summary --report-source",
"lint": "phpcs --standard=phpcs.xml.dist",
"phpstan": [
"composer --working-dir=build-cs update --no-interaction",
"build-cs/vendor/bin/phpstan analyse --memory-limit=2048M -c phpstan.neon.dist"
],
"format": [
"composer --working-dir=build-cs update --no-interaction",
"build-cs/vendor/bin/phpcbf --standard=phpcs.xml.dist --report-summary --report-source"
],
"lint": [
"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": "WP_MULTISITE=1 phpunit -c tests/multisite.xml --verbose"
"test-multisite": "phpunit -c tests/multisite.xml --verbose"
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"composer/installers": true,
"phpstan/extension-installer": true
"phpstan/extension-installer": true,
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"autoload-dev": {
Expand Down
Loading

0 comments on commit fc9ddfb

Please sign in to comment.