Skip to content

Commit c812f63

Browse files
committed
Build/Test Tools: Allow the desired version of PHPUnit to be passed to the local Docker environment.
This reintroduces [49358] with a modification to the `.travis.yml` file to avoid an issue with `dotenv-expand` being unable to expand variables into `process.env` only on Travis. The `LOCAL_PHPUNIT` environment variabl allows the desired version of PHPUnit to be specified when running the PHP tests within the local Docker environment. Because support for newer versions of PHPUnit is not backported, some versions of PHP need the ability to run multiple versions of PHPUnit for different branches. This adds the flexibility needed to use the Docker environment within those older branches to run the PHP tests. Props johnbillion, SergeyBiryukov. See #50042. git-svn-id: https://develop.svn.wordpress.org/trunk@49362 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 26278f1 commit c812f63

8 files changed

Lines changed: 61 additions & 27 deletions

File tree

.env

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
#
44
# All of these options can be overridden by setting them as environment variables before starting
55
# the environment. You will need to restart your environment when changing any of these.
6+
#
7+
# Below, the following substitutions can be made:
8+
# - '{version}': any major.minor PHP version from 5.2 onwards.
9+
# - '{phpunit_version}': any major PHPUnit version starting with 4.
610
##
711

812
# The site will be available at http://localhost:LOCAL_PORT
@@ -11,10 +15,30 @@ LOCAL_PORT=8889
1115
# Where to run WordPress from. Valid options are 'src' and 'build'.
1216
LOCAL_DIR=src
1317

14-
# The PHP version to use. Valid options are 'latest', and '{version}-fpm', where '{version}' is any
15-
# x.y PHP version from 5.2 onwards.
18+
# The PHP version to use. Valid options are 'latest', and '{version}-fpm'.
1619
LOCAL_PHP=latest
1720

21+
##
22+
# The PHPUnit version to use when running tests.
23+
#
24+
# Support for new PHPUnit versions is not backported to past versions, so some old WordPress branches require an older
25+
# version to run tests.
26+
#
27+
# Valid versions are:
28+
# - 'latest' for the highest version of PHPUnit supported on the highest version of PHP supported.
29+
# - '{version}-fpm' for the highest version of PHPUnit supported on the specified version of PHP.
30+
# - '{phpunit_version}-php-{version}-fpm' for a specific version of PHPUnit on the specified version of PHP. This format
31+
# is only available for PHP versions 5.6 and higher.
32+
#
33+
# For the full list of available options, see https://hub.docker.com/r/wordpressdevelop/phpunit/tags.
34+
#
35+
# For full documentation on PHPUnit compatibility and WordPress versions, see
36+
# https://make.wordpress.org/core/handbook/references/phpunit-compatibility-and-wordpress-versions/.
37+
#
38+
# This defaults to the value assigned to the value of LOCAL_PHP.
39+
##
40+
LOCAL_PHPUNIT=${LOCAL_PHP}
41+
1842
# Whether or not to enable XDebug.
1943
LOCAL_PHP_XDEBUG=false
2044

.travis.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ env:
2929

3030
jobs:
3131
include:
32-
- env: WP_TRAVISCI=test:e2e PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=
32+
- env: WP_TRAVISCI=test:e2e LOCAL_PHPUNIT=latest PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=
3333
name: E2E Tests
3434
- env: WP_TRAVISCI=lint:php COMPOSER_INSTALL=true NPM_INSTALL=false WP_INSTALL=false
3535
name: PHP Linting
3636
- env: WP_TRAVISCI=test:compat COMPOSER_INSTALL=true NPM_INSTALL=false WP_INSTALL=false
3737
name: "PHP Compatibility Check"
3838
- env: WP_TRAVISCI=travis:js WP_INSTALL=false PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=
3939
name: JS Tests
40-
- env: LOCAL_PHP=8.0-fpm COMPOSER_INSTALL=true WP_TRAVISCI=test:php
40+
- env: LOCAL_PHP=8.0-fpm LOCAL_PHPUNIT=8.0-fpm COMPOSER_INSTALL=true WP_TRAVISCI=test:php
4141
name: "PHPUnit Tests: PHP 8.0"
4242
script:
4343
# The PHPUnit 7.x phar is not compatible with PHP 8 and won't be updated,
@@ -53,19 +53,19 @@ jobs:
5353
# Once Xdebug 3.0 is released and included in the Docker image, this should be uncommented again.
5454
# - LOCAL_PHP_XDEBUG=true docker-compose run --rm phpunit phpunit -v --group xdebug --exclude-group __fakegroup__
5555

56-
- env: LOCAL_PHP=7.4-fpm WP_TRAVISCI=test:php
56+
- env: LOCAL_PHP=7.4-fpm LOCAL_PHPUNIT=7.4-fpm WP_TRAVISCI=test:php
5757
name: "PHPUnit Tests: PHP 7.4"
58-
- env: LOCAL_PHP=7.3-fpm WP_TRAVISCI=test:php
58+
- env: LOCAL_PHP=7.3-fpm LOCAL_PHPUNIT=7.3-fpm WP_TRAVISCI=test:php
5959
name: "PHPUnit Tests: PHP 7.3"
60-
- env: LOCAL_PHP=7.3-fpm LOCAL_PHP_MEMCACHED=true WP_TRAVISCI=test:php
60+
- env: LOCAL_PHP=7.3-fpm LOCAL_PHPUNIT=7.3-fpm LOCAL_PHP_MEMCACHED=true WP_TRAVISCI=test:php
6161
name: "PHPUnit Tests: PHP 7.3 with Memcached"
62-
- env: LOCAL_PHP=7.2-fpm WP_TRAVISCI=test:php
62+
- env: LOCAL_PHP=7.2-fpm LOCAL_PHPUNIT=7.2-fpm WP_TRAVISCI=test:php
6363
name: "PHPUnit Tests: PHP 7.2"
64-
- env: LOCAL_PHP=7.1-fpm WP_TRAVISCI=test:php
64+
- env: LOCAL_PHP=7.1-fpm LOCAL_PHPUNIT=7.1-fpm WP_TRAVISCI=test:php
6565
name: "PHPUnit Tests: PHP 7.1"
66-
- env: LOCAL_PHP=7.0-fpm WP_TEST_REPORTER=true WP_TRAVISCI=test:php
66+
- env: LOCAL_PHP=7.0-fpm LOCAL_PHPUNIT=7.0-fpm WP_TEST_REPORTER=true WP_TRAVISCI=test:php
6767
name: "PHPUnit Tests: PHP 7.0"
68-
- env: LOCAL_PHP=5.6-fpm WP_TRAVISCI=test:php
68+
- env: LOCAL_PHP=5.6-fpm LOCAL_PHPUNIT=5.6-fpm WP_TRAVISCI=test:php
6969
name: "PHPUnit Tests: PHP 5.6"
7070
allow_failures:
7171
fast_finish: true

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ services:
9696
# The PHPUnit container.
9797
##
9898
phpunit:
99-
image: wordpressdevelop/phpunit:${LOCAL_PHP-latest}
99+
image: wordpressdevelop/phpunit:${LOCAL_PHPUNIT-latest}
100100

101101
networks:
102102
- wpdevnet

package-lock.json

Lines changed: 14 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"check-node-version": "4.0.1",
3636
"copy-webpack-plugin": "^5.1.1",
3737
"cssnano": "4.1.10",
38-
"dotenv": "8.1.0",
38+
"dotenv": "8.2.0",
3939
"dotenv-expand": "5.1.0",
4040
"grunt": "~1.1.0",
4141
"grunt-banner": "^0.6.0",

tools/local-env/scripts/docker.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
const dotenv = require( 'dotenv' );
1+
const dotenv = require( 'dotenv' );
2+
const dotenvExpand = require( 'dotenv-expand' );
23
const { execSync } = require( 'child_process' );
3-
dotenv.config();
4+
5+
dotenvExpand( dotenv.config() );
46

57
// Execute any docker-compose command passed to this script.
68
execSync( 'docker-compose ' + process.argv.slice( 2 ).join( ' ' ), { stdio: 'inherit' } );

tools/local-env/scripts/install.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
const dotenv = require( 'dotenv' );
1+
const dotenv = require( 'dotenv' );
2+
const dotenvExpand = require( 'dotenv-expand' );
23
const wait_on = require( 'wait-on' );
34
const { execSync } = require( 'child_process' );
45
const { renameSync, readFileSync, writeFileSync } = require( 'fs' );
56

6-
dotenv.config();
7+
dotenvExpand( dotenv.config() );
78

89
// Create wp-config.php.
910
wp_cli( 'config create --dbname=wordpress_develop --dbuser=root --dbpass=password --dbhost=mysql --path=/var/www/src --force' );

tools/local-env/scripts/start.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
const dotenv = require( 'dotenv' );
1+
const dotenv = require( 'dotenv' );
2+
const dotenvExpand = require( 'dotenv-expand' );
23
const { execSync } = require( 'child_process' );
34

4-
dotenv.config();
5+
dotenvExpand( dotenv.config() );
56

67
// Start the local-env containers.
78
execSync( 'docker-compose up -d wordpress-develop', { stdio: 'inherit' } );

0 commit comments

Comments
 (0)