Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
54 changes: 54 additions & 0 deletions .github/workflows/php-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Unit Testing

on:
push:
branches:
- trunk
# Only run if PHP-related files changed.
paths:
- '.github/workflows/php-test.yml'
- '**.php'
- 'phpunit.xml.dist'
- 'tests/multisite.xml'
- 'composer.json'
- 'composer.lock'
pull_request:
branches:
- trunk
# Only run if PHP-related files changed.
paths:
- '.github/workflows/php-test.yml'
- '**.php'
- 'phpunit.xml.dist'
- 'tests/multisite.xml'
- 'composer.json'
- 'composer.lock'
types:
- opened
- reopened
- synchronize

jobs:
php-test:
name: PHP
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: styfle/cancel-workflow-action@0.8.0
- uses: actions/checkout@v2
- name: Read .nvmrc
run: echo "##[set-output name=NVMRC;]$(cat .nvmrc)"
id: nvm
- name: Setup Node.js (.nvmrc)
uses: actions/setup-node@v1
with:
node-version: '${{ steps.nvm.outputs.NVMRC }}'
cache: npm
- 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
- name: Running multisite unit tests
run: npm run test-php-multisite
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
14
4 changes: 4 additions & 0 deletions .wp-env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"core": null,
"plugins": [ "." ]
}
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,18 @@

Monorepo for the [WordPress Performance Group](https://make.wordpress.org/core/tag/performance/), primarily for the overall performance plugin, which is a collection of standalone performance modules.

## Useful commands

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would it makes sense to mention we need to have Docker up and running before running the wp-env commands. And/or link to the handbook (https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1 to that, for someone without Docker this npm run wp-env start and everything after fails.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Great point, I added a note about both Node.js and Docker being required.

In order to run the following commands, you need to have [Node.js](https://nodejs.org) (including `npm`) and [Docker](https://www.docker.com) installed, and Docker needs to be up and running. The Docker configuration used relies on the [`@wordpress/env` package](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/).

* `npm install`: Installs local development dependencies.
* `npm run wp-env start`: Starts the local development environment.
* `npm run wp-env stop`: Stops the local development environment.
* `npm run lint-php`: Lints all PHP code.
* `npm run format-php`: Formats all PHP code.
* `npm run test-php`: Runs PHPUnit tests for all PHP code.
* `npm run test-php-multisite`: Runs PHPUnit tests in multisite for all PHP code.

## Documentation

[See the `/docs` folder for documentation.](https://github.com/WordPress/performance/blob/trunk/docs/README.md)
58 changes: 30 additions & 28 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
{
"name": "wordpress/performance",
"type": "wordpress-plugin",
"license": "GPL-2.0-or-later",
"description": "Performance plugin from the WordPress Performance Group, which is a collection of standalone performance modules.",
"homepage": "https://wordpress.org/plugins/performance-lab/",
"keywords": [
"performance",
"wordpress"
],
"support": {
"issues": "https://github.com/WordPress/performance/issues"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.7",
"phpcompatibility/php-compatibility": "^9.3",
"phpunit/phpunit": "^8.5",
"squizlabs/php_codesniffer": "^3.5",
"wp-coding-standards/wpcs": "^2.2",
"wp-phpunit/wp-phpunit": "^5.8"
},
"require": {
"composer/installers": "~1.0"
},
"scripts": {
"format": "phpcbf --standard=phpcs.xml.dist --report-summary --report-source",
"lint": "phpcs --standard=phpcs.xml.dist",
"test": "phpunit"
}
"name": "wordpress/performance",
"type": "wordpress-plugin",
"license": "GPL-2.0-or-later",
"description": "Performance plugin from the WordPress Performance Group, which is a collection of standalone performance modules.",
"homepage": "https://wordpress.org/plugins/performance-lab/",
"keywords": [
"performance",
"wordpress"
],
"support": {
"issues": "https://github.com/WordPress/performance/issues"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.7",
"phpcompatibility/php-compatibility": "^9.3",
"phpunit/phpunit": "^8.5",
"squizlabs/php_codesniffer": "^3.5",
"wp-coding-standards/wpcs": "^2.2",
"wp-phpunit/wp-phpunit": "^5.8",
"yoast/phpunit-polyfills": "^1.0"
},
"require": {
"composer/installers": "~1.0"
},
"scripts": {
"format": "phpcbf --standard=phpcs.xml.dist --report-summary --report-source",
"lint": "phpcs --standard=phpcs.xml.dist",
"test": "phpunit -c phpunit.xml.dist --verbose",
"test-multisite": "WP_MULTISITE=1 phpunit -c tests/multisite.xml --verbose"
}
}
60 changes: 58 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 15 additions & 2 deletions load.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,25 @@ function perflab_register_modules_setting() {
* @return array Sanitized modules setting value.
*/
function perflab_sanitize_modules_setting( $value ) {
// TODO: Make this more error-proof.
if ( ! is_array( $value ) ) {
return array();
}

return $value;
// Ensure that every element is an array with an 'enabled' key.
return array_filter(
array_map(
function( $module_settings ) {
if ( ! is_array( $module_settings ) ) {
return array();
}
return array_merge(
array( 'enabled' => false ),
$module_settings
);
},
$value
)
);
}

/**
Expand Down
Loading