Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PHP CI including PHPCS and PHPUnit; bump PHP/WP versions #1095

Merged
merged 24 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
76b4c72
Bump minimum WP and PHP versions; update test matrix
westonruter Jan 18, 2024
4ec1374
Run composer update
westonruter Jan 18, 2024
a112b86
Upgrade yoast/wp-test-utils to 1.2.0
westonruter Jan 18, 2024
31f1ebe
Upgrade wp-coding-standards/wpcs:3.0.1 automattic/vipwpcs:3.0.0
westonruter Jan 18, 2024
f84c05b
Run wpcs update
westonruter Jan 18, 2024
8716706
Run phpcbf
westonruter Jan 18, 2024
43ee911
Fix phpcs issues
westonruter Jan 18, 2024
2ed35c9
Bump platform.php to 7.0 and run composer update
westonruter Jan 18, 2024
0b0e41f
Set platform.php to 8.0
westonruter Jan 18, 2024
531f897
Use set_up and tear_down in tests
westonruter Jan 18, 2024
94f0288
Update test:php commands for latest wp-env
westonruter Jan 18, 2024
4fc0200
Normalize composer.json
westonruter Jan 18, 2024
9ffbeab
Add .phpunit.result.cache
thelovekesh Jan 18, 2024
72b797c
Fix dynamic property deprecation warnings
thelovekesh Jan 18, 2024
92abfc5
Setup global phpunit in workflows
thelovekesh Jan 18, 2024
5c5b8dd
Fix WP_CLI logger class not found issue
thelovekesh Jan 18, 2024
fb95cfa
Fix local phpunit conflict with global
thelovekesh Jan 18, 2024
96a6b84
Update WP laoding in testsuite
thelovekesh Jan 18, 2024
100e281
Add WP_TESTS_DIR env to workflows
thelovekesh Jan 18, 2024
e513906
Update coverage driver to xdebug
thelovekesh Jan 18, 2024
b7486c7
Downgrade php emulation to 7.0
thelovekesh Jan 18, 2024
cdc2d49
Update version compare to skip tests
thelovekesh Jan 18, 2024
bff5dcd
Add verbosity to phpunit command
thelovekesh Jan 18, 2024
9fa812d
Add PHPUnit 9 phar for local development
thelovekesh Jan 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 35 additions & 24 deletions .github/workflows/build-test-measure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ jobs:
if: needs.pre-run.outputs.changed-file-count > 0
env:
WP_CORE_DIR: /tmp/wordpress
WP_TESTS_DIR: /tmp/wordpress-tests-lib
WP_ENVIRONMENT_TYPE: local
services:
mysql:
image: mariadb:latest
Expand All @@ -226,31 +228,42 @@ jobs:
coverage: [false]
php: ['7.3', '7.2', '7.1']
wp: ['latest']
phpunit: ['7']
include:
- php: '8.0'
- php: '8.3'
wp: 'trunk'
experimental: true
coverage: false
phpunit: '9.6'

- php: '8.2'
wp: 'trunk'
coverage: false
phpunit: '9.6'

- php: '8.1'
wp: 'latest'
coverage: false
phpunit: '9.6'

- php: '8.0'
wp: 'latest'
coverage: false
phpunit: '9.3'

- php: '7.4'
wp: 'latest'
coverage: false
phpunit: '9.3'

- php: '7.4'
wp: 'latest'
coverage: true
phpunit: '9.3'

- php: '7.0'
wp: '5.1'
coverage: false

- php: '5.6'
wp: '5.0'
coverage: false

- php: '5.6'
wp: '4.9'
wp: '6.3'
coverage: false
phpunit: '6'

steps:
- name: Checkout
Expand All @@ -261,8 +274,8 @@ jobs:
with:
php-version: ${{ matrix.php }}
extensions: curl, date, dom, gd, iconv, json, libxml, mysql, spl
coverage: ${{ matrix.coverage && 'pcov' || 'none' }}
ini-values: pcov.directory=.
coverage: ${{ matrix.coverage && 'xdebug' || 'none' }}
tools: phpunit:${{ matrix.phpunit }}

- name: Shutdown default MySQL service
run: sudo service mysql stop
Expand Down Expand Up @@ -302,6 +315,13 @@ jobs:
- name: Build plugin
run: npm run build

# Avoid conflicts with globally installed PHPUnit.
- name: Remove locally installed PHPUnit
if: needs.pre-run.outputs.changed-php-count > 0
run: |
rm -rf vendor/phpunit
composer dump-autoload -o

# Scan the logs for failing tests and surface that information by creating annotations and log file decorations.
- name: Setup problem matcher to provide annotations for PHPUnit
# The JSON file is provided by the `shivammathur/setup-php` action. See https://github.com/shivammathur/setup-php#problem-matchers.
Expand All @@ -310,26 +330,17 @@ jobs:
- name: Install WP tests
run: bash bin/ci/install-wp-tests.sh wordpress_test root '' 127.0.0.1:${{ job.services.mysql.ports['3306'] }} ${{ matrix.wp }} true

- name: Setup PCOV
if: ${{ matrix.coverage == true }}
# phpdocumentor/reflection has to be removed as it makes use of an outdated dependency, making pcov/clobber
# unable to be installed.
run: |
composer remove --dev phpdocumentor/reflection
composer require --dev --ignore-platform-reqs pcov/clobber
vendor/bin/pcov clobber

- name: Copy plugin to WP plugins directory
run: cp -r "$PWD" "$WP_CORE_DIR/src/wp-content/plugins/pwa"

- name: Run tests
if: ${{ matrix.coverage == false }}
run: vendor/bin/phpunit
run: phpunit --verbose
working-directory: ${{ env.WP_CORE_DIR }}/src/wp-content/plugins/pwa

- name: Run tests with coverage
if: ${{ matrix.coverage == true }}
run: vendor/bin/phpunit --coverage-clover build/logs/clover.xml
run: phpunit --verbose --coverage-clover build/logs/clover.xml
working-directory: ${{ env.WP_CORE_DIR }}/src/wp-content/plugins/pwa

- name: Upload code coverage report
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/wp-includes/js/workbox*
/wiki
.vscode
.phpunit.result.cache

# Generated via bin/transform-readme.php
/readme.txt
Expand Down
2 changes: 1 addition & 1 deletion .phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

<rule ref="WordPress.NamingConventions.ValidVariableName">
<properties>
<property name="customPropertiesWhitelist" value="childNodes,tagName,textContent,parentNode,nodeType,nodeName,nextSibling,firstChild,lastChild,nodeValue,DEFAULT_ARGS,documentElement,removeChild,ownerDocument,DEFAULT_WIDTH,DEFAULT_HEIGHT" />
<property name="allowed_custom_properties" value="childNodes,tagName,textContent,parentNode,nodeType,nodeName,nextSibling,firstChild,lastChild,nodeValue,DEFAULT_ARGS,documentElement,removeChild,ownerDocument,DEFAULT_WIDTH,DEFAULT_HEIGHT" />
</properties>
</rule>

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ WordPress feature plugin to bring Progressive Web App (PWA) capabilities to Core

**Contributors:** [google](https://profiles.wordpress.org/google), [xwp](https://profiles.wordpress.org/xwp), [rtcamp](https://profiles.wordpress.org/rtcamp), [westonruter](https://profiles.wordpress.org/westonruter), [albertomedina](https://profiles.wordpress.org/albertomedina)
**Tags:** [pwa](https://wordpress.org/plugins/tags/pwa), [progressive web apps](https://wordpress.org/plugins/tags/progressive-web-apps), [service workers](https://wordpress.org/plugins/tags/service-workers), [web app manifest](https://wordpress.org/plugins/tags/web-app-manifest)
**Requires at least:** 5.5
**Requires at least:** 6.3
**Tested up to:** 6.3
**Stable tag:** 0.7.1
**License:** [GPLv2 or later](http://www.gnu.org/licenses/gpl-2.0.html)
**Requires PHP:** 5.6
**Requires PHP:** 7.0

[![Build Status](https://github.com/GoogleChromeLabs/pwa-wp/workflows/Build,%20test%20&%20measure/badge.svg)](https://github.com/GoogleChromeLabs/pwa-wp/actions?query=branch%3Adevelop+workflow%3A%22Build%2C+test+%26+measure%22)
[![Built with Grunt](https://gruntjs.com/cdn/builtwith.svg)](http://gruntjs.com)
Expand Down
4 changes: 2 additions & 2 deletions bin/verify-version-consistency.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@

$versions = array();

$readme_md = file_get_contents( dirname( __FILE__ ) . '/../README.md' );
$readme_md = file_get_contents( __DIR__ . '/../README.md' );
if ( ! preg_match( '/\*\*Stable tag:\*\*\s+(?P<version>\S+)/i', $readme_md, $matches ) ) {
echo "Could not find stable tag in readme\n";
exit( 1 );
}
$versions['README.md#stable-tag'] = $matches['version'];

$plugin_file = file_get_contents( dirname( __FILE__ ) . '/../pwa.php' );
$plugin_file = file_get_contents( __DIR__ . '/../pwa.php' );
if ( ! preg_match( '/\*\s*Version:\s*(?P<version>\d+\.\d+(?:.\d+)?(-\w+)?)/', $plugin_file, $matches ) ) {
echo "Could not find version in readme metadata\n";
exit( 1 );
Expand Down
2 changes: 1 addition & 1 deletion bundled-theme-support/twentynineteen/offline.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// Add the body class for the 404 template for the sake of styling.
add_filter(
'body_class',
function( $body_classes ) {
function ( $body_classes ) {
$body_classes[] = 'error404';
return $body_classes;
}
Expand Down
2 changes: 1 addition & 1 deletion bundled-theme-support/twentysixteen/offline.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// Add the body class for the 404 template for the sake of styling.
add_filter(
'body_class',
function( $body_classes ) {
function ( $body_classes ) {
$body_classes[] = 'error404';
return $body_classes;
}
Expand Down
2 changes: 1 addition & 1 deletion bundled-theme-support/twentytwenty/offline.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function () {
// Add the body class for the 404 template for the sake of styling.
add_filter(
'body_class',
function( $body_classes ) {
function ( $body_classes ) {
$body_classes[] = 'error404';
return $body_classes;
}
Expand Down
28 changes: 19 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,27 @@
"type": "wordpress-plugin",
"homepage": "https://github.com/GoogleChromeLabs/pwa-wp",
"require": {
"php": "^5.6 || ^7.0 || ^8.0",
"php": "^7.0 || ^8.0",
"ext-json": "*"
},
"require-dev": {
"automattic/vipwpcs": "^2.3",
"automattic/vipwpcs": "3.0.0",
"civicrm/composer-downloads-plugin": "^3.0",
"dealerdirect/phpcodesniffer-composer-installer": "0.7.2",
"php-stubs/wordpress-stubs": "^6.3.2",
"phpcompatibility/phpcompatibility-wp": "2.1.4",
"wp-cli/wp-cli": "^2.9",
"wp-coding-standards/wpcs": "2.3.0",
"yoast/wp-test-utils": "^0.2.2"
"wp-coding-standards/wpcs": "3.0.1",
"yoast/wp-test-utils": "1.2.0"
},
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"civicrm/composer-downloads-plugin": true
"civicrm/composer-downloads-plugin": true,
"dealerdirect/phpcodesniffer-composer-installer": true
},
"platform": {
"php": "5.6"
"php": "7.0"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to emulate it to 7.0 else it can download deps that don't support PHP 7.0.

Copy link
Collaborator Author

@westonruter westonruter Jan 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Humm. I had updated the composer.lock file for PHP 8.0 so we'll need to update it for 7.0. However, when I do so then I get errors when running tests locally:

$ npm run test:php

> test:php
> wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/pwa/ env WORDPRESS_TABLE_PREFIX=wptests_ vendor/bin/phpunit

ℹ Starting 'env WORDPRESS_TABLE_PREFIX=wptests_ vendor/bin/phpunit' on the tests-cli container. 

[18-Jan-2024 22:34:19 UTC] PHP Warning:  Private methods cannot be final as they are never overridden by other classes in /var/www/html/wp-content/plugins/pwa/vendor/phpunit/phpunit/src/Util/Configuration.php on line 176
[18-Jan-2024 22:34:19 UTC] PHP Fatal error:  Cannot acquire reference to $GLOBALS in /var/www/html/wp-content/plugins/pwa/vendor/phpunit/phpunit/src/Util/Configuration.php on line 543
✖ Command failed with exit code 255

If I change it to 7.4 and run composer update then I can run PHPUnit successfully, even when I'm running PHP 8.1.

Can we change this then to (and run composer update):

Suggested change
"php": "7.0"
"php": "7.4"

If that means removing tests for PHP 7.0-7.3, I'm fine with that.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's because the PHPUnit version is not compatible with the PHP version inside the container. So I think we need to use updated PHPUnit for local testing.

So we have two options now:

  • We save PHPUnit 9.6 PHAR in bin like we do for PHPStan and keep 7.0 tests.
  • Remove 7.0 tests and bump PHP emulation to 7.1.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now PHPUnit version is customizable in local development with - 9fa812d

With this, we can download any PHPUnit version and keep the tests for PHP 7.0.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clever!

},
"sort-packages": true
},
Expand All @@ -41,13 +40,24 @@
"path": "vendor/bin/phpstan",
"type": "phar",
"url": "https://github.com/phpstan/phpstan/releases/latest/download/phpstan.phar"
},
"phpunit": {
"path": "vendor/bin/_phpunit",
"type": "phar",
"url": "https://phar.phpunit.de/phpunit-9.phar"
}
}
},
"scripts": {
"post-install-cmd": [
"@php -r \"if (file_exists('vendor/bin/_phpunit')) { rename('vendor/bin/_phpunit', 'vendor/bin/phpunit'); }\""
],
"post-update-cmd": [
"composer run-script post-install-cmd"
],
"analyze": "if [ -z $TEST_SKIP_PHPSTAN ]; then phpstan --version; phpstan analyze --ansi --memory-limit=1G; fi",
"pre-commit": [
"npm run lint:staged"
]
}
}
}
Loading
Loading