Skip to content

Commit

Permalink
Merge pull request #9 from Yoast/develop
Browse files Browse the repository at this point in the history
Release version 0.2.2
  • Loading branch information
jrfnl authored Jun 21, 2021
2 parents c5cdabd + 75b8e24 commit 896f764
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#
/.gitattributes export-ignore
/.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
Expand Down
42 changes: 42 additions & 0 deletions .github/workflows/cs.yml
Original file line number Diff line number Diff line change
@@ -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
55 changes: 55 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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
66 changes: 0 additions & 66 deletions .travis.yml

This file was deleted.

8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
23 changes: 15 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ WP Test Utils
=====================================================

[![Version](https://poser.pugx.org/yoast/wp-test-utils/version)](https://packagist.org/packages/yoast/wp-test-utils)
[![Travis Build Status](https://travis-ci.com/Yoast/wp-test-utils.svg?branch=main)](https://travis-ci.com/Yoast/wp-test-utils/branches)
[![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)
[![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)

Expand All @@ -24,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.5 or higher.
* [BrainMonkey] 2.6.0 or higher.

Installation
-------------------------------------------
Expand Down Expand Up @@ -164,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:
Expand Down Expand Up @@ -196,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.

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
},
"require" : {
"php" : ">=5.6",
"yoast/phpunit-polyfills": "^0.2.0",
"yoast/phpunit-polyfills": "^1.0.0",
"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"
},
Expand Down
8 changes: 4 additions & 4 deletions src/WPIntegration/Autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
}
Expand All @@ -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 ) {
Expand Down
3 changes: 1 addition & 2 deletions src/WPIntegration/bootstrap-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 896f764

Please sign in to comment.