From 17b38d561e4d8ad3d2a3f318f65e32c24676dbe2 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 27 Apr 2021 05:19:36 +0200 Subject: [PATCH 1/8] Composer: update PHP Parallel Lint Update version constraint for PHP Parallel Lint after new release. Refs: * https://github.com/php-parallel-lint/PHP-Parallel-Lint/releases/tag/v1.3.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 43ab6ac..06ae26c 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ "brain/monkey": "^2.6.0" }, "require-dev" : { - "php-parallel-lint/php-parallel-lint": "^1.2.0", + "php-parallel-lint/php-parallel-lint": "^1.3.0", "php-parallel-lint/php-console-highlighter": "^0.5", "yoast/yoastcs": "^2.1.0" }, From 5e5193c4d21728198546c3bb8d8e7725a4ea3e3f Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 27 Apr 2021 05:38:23 +0200 Subject: [PATCH 2/8] CS/QA: rename a function parameter ... to prevent using a reserved keyword as a parameter name. While this isn't forbidden, in PHP 8.0+ with named parameters this can lead to very confusing code, so better to use another name. --- src/WPIntegration/Autoload.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/WPIntegration/Autoload.php b/src/WPIntegration/Autoload.php index 1f6c9d6..f990b4e 100644 --- a/src/WPIntegration/Autoload.php +++ b/src/WPIntegration/Autoload.php @@ -35,11 +35,11 @@ final class Autoload { /** * Loads a class. * - * @param string $class The name of the class to load. + * @param string $class_name The name of the class to load. * * @return bool */ - public static function load( $class ) { + public static function load( $class_name ) { if ( \PHP_VERSION_ID < 80000 ) { // This autoloader is only needed when the tests are being run on PHP >= 8.0. @@ -55,7 +55,7 @@ public static function load( $class ) { return false; } - if ( isset( self::$supported_classes[ $class ] ) === false ) { + if ( isset( self::$supported_classes[ $class_name ] ) === false ) { // Bow out, not a class this autoloader handles. return false; } @@ -67,7 +67,7 @@ public static function load( $class ) { } // Try getting the overloaded file as included in WP 5.6/master. - $relative_filename = \strtr( \substr( $class, 18 ), '\\', \DIRECTORY_SEPARATOR ) . '.php'; + $relative_filename = \strtr( \substr( $class_name, 18 ), '\\', \DIRECTORY_SEPARATOR ) . '.php'; $file = \realpath( $wp_test_dir . 'includes/phpunit7/' . $relative_filename ); if ( $file === false || @\file_exists( $file ) === false ) { From 38629f40a77acda0a3933243da72f8dbfaf4c0d9 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 3 Jun 2021 05:09:09 +0200 Subject: [PATCH 3/8] CI: switch to GitHub Actions - step 1: sniff stage This commit: * Adds a GH Actions workflow for the CI checks which were previously run on Travis in the `sniff` stage. While these aren't 100% CS (= code style) checks, for the badge and workflow display, `CS` still seemed the most descriptive name. * Removes that part of the `.travis.yml` configuration. * Adds a "Build Status" badge in the Readme to use the results from this particular GH Actions runs. Notes: Builds will run on all pushes and on pull requests and can be manually triggered. --- .gitattributes | 1 + .github/workflows/cs.yml | 42 ++++++++++++++++++++++++++++++++++++++++ .travis.yml | 19 ------------------ README.md | 1 + 4 files changed, 44 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/cs.yml diff --git a/.gitattributes b/.gitattributes index a6c007a..68fde82 100644 --- a/.gitattributes +++ b/.gitattributes @@ -9,6 +9,7 @@ /.gitignore export-ignore /.travis.yml export-ignore /.cache/ export-ignore +/.github/ export-ignore /.phpcs.xml.dist export-ignore /phpunit.xml.dist export-ignore /tests/ export-ignore diff --git a/.github/workflows/cs.yml b/.github/workflows/cs.yml new file mode 100644 index 0000000..60e905b --- /dev/null +++ b/.github/workflows/cs.yml @@ -0,0 +1,42 @@ +name: CS + +on: + # Run on all pushes and on all pull requests. + push: + pull_request: + # Allow manually triggering the workflow. + workflow_dispatch: + +jobs: + checkcs: + name: 'Basic CS and QA checks' + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '7.4' + coverage: none + tools: cs2pr + + # Install dependencies and handle caching in one go. + # @link https://github.com/marketplace/actions/install-composer-dependencies + - name: Install Composer dependencies + uses: "ramsey/composer-install@v1" + + # Validate the composer.json file. + # @link https://getcomposer.org/doc/03-cli.md#validate + - name: Validate Composer installation + run: composer validate --no-check-all --strict + + # Check the code-style consistency of the PHP files. + - name: Check PHP code style + continue-on-error: true + run: composer check-cs -- --report-full --report-checkstyle=./phpcs-report.xml + + - name: Show PHPCS results in PR + run: cs2pr ./phpcs-report.xml diff --git a/.travis.yml b/.travis.yml index 909cb82..31f63a4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,8 +11,6 @@ cache: - $HOME/.composer/cache/files # Cache directory for more recent Composer versions. - $HOME/.cache/composer/files - # Cache CI tooling cache files. - - .cache php: - 5.6 @@ -24,25 +22,8 @@ php: - 8.0 - "nightly" -# Define the stages used. -stages: - - name: sniff - - name: test - jobs: fast_finish: true - include: - #### SNIFF STAGE #### - - stage: sniff - php: 7.4 - script: - # Validate the composer.json file. - # @link https://getcomposer.org/doc/03-cli.md#validate - - composer validate --no-check-all --strict - - # Check the code style of the code base. - - composer check-cs - allow_failures: # Allow failures for unstable builds. - php: "nightly" diff --git a/README.md b/README.md index afd0094..26e42e8 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ WP Test Utils ===================================================== [![Version](https://poser.pugx.org/yoast/wp-test-utils/version)](https://packagist.org/packages/yoast/wp-test-utils) +[![CS Build Status](https://github.com/Yoast/wp-test-utils/actions/workflows/cs.yml/badge.svg)](https://github.com/Yoast/wp-test-utils/actions/workflows/cs.yml) [![Travis Build Status](https://travis-ci.com/Yoast/wp-test-utils.svg?branch=main)](https://travis-ci.com/Yoast/wp-test-utils/branches) [![Minimum PHP Version](https://img.shields.io/packagist/php-v/yoast/wp-test-utils.svg?maxAge=3600)](https://packagist.org/packages/yoast/wp-test-utils) [![License: BSD3](https://poser.pugx.org/yoast/wp-test-utils/license)](https://github.com/Yoast/wp-test-utils/blob/master/LICENSE) From 84c73e1b0dfb4a89fc96ef0df0b64e19d7064e0d Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 3 Jun 2021 05:26:49 +0200 Subject: [PATCH 4/8] CI: switch to GitHub Actions - step 2: test and lint stage This commit: * Adds a GH Actions workflow for the CI checks which were previously run on Travis in the `test` stage. * Removes the, now redundant, `.travis.yml` configuration. * Updates the `.gitattributes` file. * Updates the "Build Status" badge in the Readme to use the results from the GH `Test` Actions runs. Notes: As there is one job which are "allowed to fail" (`experimental` = true), the build status _may_ unfortunately show as "failed" when that job would fail, even though all non-experimental jobs have succeeded. This is a known issue in GHA: https://github.com/actions/toolkit/issues/399 --- .gitattributes | 1 - .github/workflows/test.yml | 55 ++++++++++++++++++++++++++++++++++++++ .travis.yml | 47 -------------------------------- README.md | 2 +- 4 files changed, 56 insertions(+), 49 deletions(-) create mode 100644 .github/workflows/test.yml delete mode 100644 .travis.yml diff --git a/.gitattributes b/.gitattributes index 68fde82..074a6f2 100644 --- a/.gitattributes +++ b/.gitattributes @@ -7,7 +7,6 @@ # /.gitattributes export-ignore /.gitignore export-ignore -/.travis.yml export-ignore /.cache/ export-ignore /.github/ export-ignore /.phpcs.xml.dist export-ignore diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..e9cf20c --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,55 @@ +name: Test + +on: + # Run on all pushes and on all pull requests. + push: + pull_request: + # Allow manually triggering the workflow. + workflow_dispatch: + +jobs: + #### TEST STAGE #### + test: + runs-on: ubuntu-latest + + strategy: + matrix: + php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0'] + experimental: [false] + + include: + - php: '8.1' + experimental: true + + name: "Tests: PHP ${{ matrix.php }}" + + continue-on-error: ${{ matrix.experimental }} + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + coverage: none + + # Install dependencies and handle caching in one go. + # @link https://github.com/marketplace/actions/install-composer-dependencies + - name: Install Composer dependencies for PHP < 8.1 + if: ${{ matrix.php < 8.1 }} + uses: "ramsey/composer-install@v1" + + # For PHP 8.1 and above, we need to install with ignore platform reqs as not all dependencies allow it yet. + - name: Install Composer dependencies for PHP >= 8.1 + if: ${{ matrix.php >= 8.1 }} + uses: "ramsey/composer-install@v1" + with: + composer-options: --ignore-platform-reqs + + - name: Lint PHP files against parse errors + run: composer lint + + - name: Run the unit tests + run: composer test diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 31f63a4..0000000 --- a/.travis.yml +++ /dev/null @@ -1,47 +0,0 @@ -os: linux -dist: xenial - -language: php - -## Cache composer and apt downloads. -cache: - apt: true - directories: - # Cache directory for older Composer versions. - - $HOME/.composer/cache/files - # Cache directory for more recent Composer versions. - - $HOME/.cache/composer/files - -php: - - 5.6 - - 7.0 - - 7.1 - - 7.2 - - 7.3 - - 7.4 - - 8.0 - - "nightly" - -jobs: - fast_finish: true - allow_failures: - # Allow failures for unstable builds. - - php: "nightly" - - -before_install: - # Speed up build time by disabling Xdebug when its not needed. - - phpenv config-rm xdebug.ini || echo 'No xdebug config.' - - -install: - # Set up environment using Composer. - - travis_retry composer install --no-interaction - - -script: - # Lint PHP files against parse errors. - - composer lint - - # Run the unit tests. - - composer test diff --git a/README.md b/README.md index 26e42e8..ff18ac0 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ WP Test Utils [![Version](https://poser.pugx.org/yoast/wp-test-utils/version)](https://packagist.org/packages/yoast/wp-test-utils) [![CS Build Status](https://github.com/Yoast/wp-test-utils/actions/workflows/cs.yml/badge.svg)](https://github.com/Yoast/wp-test-utils/actions/workflows/cs.yml) -[![Travis Build Status](https://travis-ci.com/Yoast/wp-test-utils.svg?branch=main)](https://travis-ci.com/Yoast/wp-test-utils/branches) +[![Test Build Status](https://github.com/Yoast/wp-test-utils/actions/workflows/test.yml/badge.svg)](https://github.com/Yoast/wp-test-utils/actions/workflows/test.yml) [![Minimum PHP Version](https://img.shields.io/packagist/php-v/yoast/wp-test-utils.svg?maxAge=3600)](https://packagist.org/packages/yoast/wp-test-utils) [![License: BSD3](https://poser.pugx.org/yoast/wp-test-utils/license)](https://github.com/Yoast/wp-test-utils/blob/master/LICENSE) From a9479e076ee473a04ac57e247ed9778277597173 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 3 Jun 2021 04:33:35 +0200 Subject: [PATCH 5/8] Support test setup via WP CLI scaffold command The WP CLI `scaffold` command can create a basic unit test setup which includes a `bin/install-wp-tests.sh` script to download WP and select parts of the WP native test suite and set up the database. The test bootstrap created by the `scaffold` command, presumes the existence of a `WP_TESTS_DIR` environment variable, but this variable can point to an arbitrary directory. If the bash script was used, this directory, however, will contain the `data` and `includes` subdirectories from the WP native `tests/phpunit`, which is what is expected by WP Test Utils. By removing the "safety" check which made sure that the path the `WP_TESTS_DIR` environment variable pointed to ended with `tests/phpunit`, the WP Test Utils suite _should_ also work in a test environment created via the `bin/install-wp-tests.sh` script. Refs; * https://github.com/wp-cli/scaffold-command/ * https://make.wordpress.org/cli/handbook/misc/plugin-unit-tests/ --- README.md | 14 ++++++++++---- src/WPIntegration/bootstrap-functions.php | 3 +-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ff18ac0..3c4c6eb 100644 --- a/README.md +++ b/README.md @@ -197,10 +197,16 @@ In comes WP Test Utils... which offers: The functionality within these files presumes three things: 1. This package is installed as a dependency of a plugin via Composer and will be in the `vendor/yoast/wp-test-utils/` directory. -2. WordPress itself is available in its entirety, inclusing the `tests` directory. -3. Either the `WP_TESTS_DIR` environment variable (path to the WordPress Core `./tests/phpunit` directory) or the `WP_DEVELOP_DIR` environment variable (path to the WordPress Core root directory) will be set. - These environment variables can be set on the OS level or from within a `phpunit.xml[.dist]` file. - If neither of the environment variables is available, the plugin is presumed to be installed in a `src/wp-content/plugins/plugin-name` directory, with this package in the `src/wp-content/plugins/plugin-name/vendor/yoast/wp-test-utils` directory. +2. WordPress itself is available in its entirety, including the `includes` subdirectory of the WP native `tests/phpunit` directory. +3. The location of the test files from the WordPress installation is known. + +The location of the test files from the WordPress install can be made known in the following ways: +1. Either set a `WP_TESTS_DIR` environment variable to the path to the WordPress Core `./tests/phpunit` directory; or a directory containing the `includes` subdirectory from the WordPress Core `./tests/phpunit` directory, such as created by the WP CLI `scaffold` command. +2. Or set the `WP_DEVELOP_DIR` environment variable to the path to the WordPress Core root directory from a git/svn check-out. + +These environment variables can be set on the OS level or from within a `phpunit.xml[.dist]` file. + +If neither of the environment variables is available, the plugin is presumed to be installed within WordPress itself in a `src/wp-content/plugins/plugin-name` directory, with this package in the `src/wp-content/plugins/plugin-name/vendor/yoast/wp-test-utils` directory. This is in line with a typical integration test setup in the context of WordPress. diff --git a/src/WPIntegration/bootstrap-functions.php b/src/WPIntegration/bootstrap-functions.php index b9298f6..5dcc3bb 100644 --- a/src/WPIntegration/bootstrap-functions.php +++ b/src/WPIntegration/bootstrap-functions.php @@ -46,8 +46,7 @@ function get_path_to_wp_test_dir() { $tests_dir = \realpath( $tests_dir ); if ( $tests_dir !== false ) { $tests_dir = $normalize_path( $tests_dir ) . '/'; - if ( \substr( $tests_dir, -15 ) === '/tests/phpunit/' - && \is_dir( $tests_dir ) === true + if ( \is_dir( $tests_dir ) === true && @\file_exists( $tests_dir . 'includes/bootstrap.php' ) ) { return $tests_dir; From 71b94b9d9b4f0fcee31c7576521b89686878326c Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 20 Jun 2021 17:29:14 +0200 Subject: [PATCH 6/8] Composer: update PHPUnit Polyfills version constraints The PHPUnit Polyfills repo has released version 1.0.0. Ref: https://github.com/Yoast/PHPUnit-Polyfills/releases/tag/1.0.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 06ae26c..05c1ff0 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ }, "require" : { "php" : ">=5.6", - "yoast/phpunit-polyfills": "^0.2.0", + "yoast/phpunit-polyfills": "^1.0.0", "brain/monkey": "^2.6.0" }, "require-dev" : { From 595b35127da7bff01c51acee04c8048a699d235e Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 3 Jun 2021 06:27:13 +0200 Subject: [PATCH 7/8] Changelog for release 0.2.2 --- CHANGELOG.md | 8 ++++++++ README.md | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b9d64d..c3c590f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,13 @@ This projects adheres to [Keep a CHANGELOG](http://keepachangelog.com/) and uses _Nothing yet._ +## [0.2.2] - 2021-06-21 + +### Changed +* The [PHPUnit Polyfills] dependency has been updated to require [version `^1.0.0`](https://github.com/Yoast/PHPUnit-Polyfills/releases/tag/1.0.0) (was `^0.2.0`). +* Improved compatibility with the test setup as created via the WP CLI `scaffold` command. +* CI is now run via GitHub Actions. + ## [0.2.1] - 2020-12-09 @@ -40,6 +47,7 @@ Initial release. [Unreleased]: https://github.com/Yoast/wp-test-utils/compare/main...HEAD +[0.2.2]: https://github.com/Yoast/wp-test-utils/compare/0.2.1...0.2.2 [0.2.1]: https://github.com/Yoast/wp-test-utils/compare/0.2.0...0.2.1 [0.2.0]: https://github.com/Yoast/wp-test-utils/compare/0.1.1...0.2.0 [0.1.1]: https://github.com/Yoast/wp-test-utils/compare/0.1.0...0.1.1 diff --git a/README.md b/README.md index 3c4c6eb..47ef0fb 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Requirements The following packages will be automatically required via Composer: * [PHPUnit Polyfills] 0.2.0 or higher. * [PHPUnit] 5.7 - 9.x. -* [BrainMonkey] 2.5 or higher. +* [BrainMonkey] 2.6 or higher. Installation ------------------------------------------- From 4ddd94848a9f5687ecee8314b9fadff4e71b69cc Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 21 Jun 2021 05:41:51 +0200 Subject: [PATCH 8/8] Readme: minor tweaks --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 47ef0fb..9bb96d8 100644 --- a/README.md +++ b/README.md @@ -25,9 +25,9 @@ Requirements * PHP 5.6 or higher. The following packages will be automatically required via Composer: -* [PHPUnit Polyfills] 0.2.0 or higher. +* [PHPUnit Polyfills] 1.0.0 or higher. * [PHPUnit] 5.7 - 9.x. -* [BrainMonkey] 2.6 or higher. +* [BrainMonkey] 2.6.0 or higher. Installation ------------------------------------------- @@ -165,7 +165,7 @@ To tell PHPUnit to use this bootstrap file, use `--bootstrap tests/bootstrap.php Features of this `TestCase`: 1. Extends the WP native base test case `WP_UnitTestCase`, making all the WP Core test utilities available to your integration test classes. 2. Cross-version compatibility with PHPUnit 5.7 - 9.x via the [PHPUnit Polyfills] package. - _Note: WordPress Core limit tests to running on PHPUnit 7.5 max. However, using these polyfill you can already start using the up-to-date PHPUnit 9.x syntax, even though the tests don't use PHPUnit 9 yet._ + _Note: WordPress Core limit tests to running on PHPUnit 7.5 max. However, using these polyfills you can already start using the up-to-date PHPUnit 9.x syntax, even though the tests don't use PHPUnit 9 yet._ 3. Helper functions for setting expectations for generated output. Implementation example: