Skip to content

Commit 34dfe45

Browse files
committed
Build/Test Tools: Backport the local Docker environment to the 5.0 branch.
This commit introduces the Docker-based local WordPress development environment to the 5.0 branch and converts the Travis test jobs to utilize this environment for easier and more consistent testing. Until existing blockers with the PHP 5.2 Docker container can be solved, the PHP 5.2 test job will remain using the Travis `precise` image. Merges [45745,45762,45783-45784,45800,45819,45885,46320,46999,47225,47912,48121,49335,49358,49360,49362] to the 5.0 branch. See #48301, #47767. git-svn-id: https://develop.svn.wordpress.org/branches/5.0@49529 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 61afa63 commit 34dfe45

File tree

13 files changed

+548
-78
lines changed

13 files changed

+548
-78
lines changed

.env

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
##
2+
# Default configuration options for the local dev environment.
3+
#
4+
# All of these options can be overridden by setting them as environment variables before starting
5+
# 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.
10+
##
11+
12+
# The site will be available at http://localhost:LOCAL_PORT
13+
LOCAL_PORT=8889
14+
15+
# Where to run WordPress from. Valid options are 'src' and 'build'.
16+
LOCAL_DIR=src
17+
18+
# The PHP version to use. Valid options are 'latest', and '{version}-fpm'.
19+
LOCAL_PHP=7.3-fpm
20+
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=6-php-${LOCAL_PHP}
41+
42+
# Whether or not to enable XDebug.
43+
LOCAL_PHP_XDEBUG=false
44+
45+
# Whether or not to enable Memcached.
46+
LOCAL_PHP_MEMCACHED=false
47+
48+
# The MySQL version to use. See https://hub.docker.com/_/mysql/ for valid versions.
49+
LOCAL_MYSQL=5.7
50+
51+
# The debug settings to add to `wp-config.php`.
52+
LOCAL_WP_DEBUG=true
53+
LOCAL_WP_DEBUG_LOG=true
54+
LOCAL_WP_DEBUG_DISPLAY=true
55+
LOCAL_SCRIPT_DEBUG=true
56+
LOCAL_WP_ENVIRONMENT_TYPE=local
57+
58+
# The URL to use when running e2e tests.
59+
WP_BASE_URL=http://localhost:${LOCAL_PORT}

.travis.yml

Lines changed: 109 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,130 @@
1-
sudo: false
2-
dist: trusty
31
language: php
2+
3+
services:
4+
- docker
5+
46
cache:
57
apt: true
68
directories:
79
- $HOME/.npm
810
- vendor
9-
- $HOME/.composer/cache
11+
1012
env:
1113
global:
12-
- WP_TRAVISCI=travis:phpunit
14+
- LOCAL_DIR: build
15+
- NPM_INSTALL: true
16+
- WP_INSTALL: true
17+
- PHP_FPM_UID: "`id -u`"
18+
- PHP_FPM_GID: "`id -g`"
19+
1320
matrix:
1421
include:
15-
- php: 7.1
16-
env: WP_TRAVISCI=travis:js
17-
- php: 7.3
18-
- php: 5.6
19-
env: WP_TRAVIS_OBJECT_CACHE=true
20-
services: memcached
21-
- php: 5.2
22-
dist: precise
22+
- env: WP_TRAVISCI=travis:js LOCAL_PHP=7.1-fpm WP_INSTALL=false
23+
name: "JS Tests"
24+
- env: LOCAL_PHPUNIT=6-php-7.3-fpm WP_TRAVISCI=test:php
25+
name: "PHPUnit Tests: PHP 7.3"
26+
- env: LOCAL_PHP_MEMCACHED=true LOCAL_PHP=5.6-fpm LOCAL_PHPUNIT=4-php-5.6-fpm WP_TRAVISCI=test:php
27+
name: "PHPUnit Tests: PHP 5.6 with Memcached"
28+
- env: WP_TRAVISCI=travis:phpunit WP_INSTALL=false
29+
php: 5.2
30+
dist: precise
31+
fast_finish: true
32+
2333
before_install:
24-
- |
25-
if [[ "$WP_TRAVISCI" == "travis:phpunit" ]]; then
34+
- |
35+
if [[ "$WP_TRAVISCI" == "test:php" ]]; then
36+
travis_retry svn checkout https://plugins.svn.wordpress.org/wordpress-importer/tags/0.6.3/ tests/phpunit/data/plugins/wordpress-importer
37+
fi
38+
- |
39+
if [[ "$WP_TRAVISCI" != "travis:phpunit" ]]; then
40+
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
41+
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
42+
sudo apt-get update
43+
sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce
44+
fi
45+
- |
46+
sudo rm /usr/local/bin/docker-compose
47+
curl -L https://github.com/docker/compose/releases/download/1.24.0/docker-compose-`uname -s`-`uname -m` > docker-compose
48+
chmod +x docker-compose
49+
sudo mv docker-compose /usr/local/bin
50+
- |
51+
if [[ "$WP_TRAVISCI" == "travis:phpunit" ]]; then
2652
mysql -u root -e "CREATE DATABASE wordpress_tests;"
2753
cp wp-tests-config-sample.php wp-tests-config.php
2854
sed -i "s/youremptytestdbnamehere/wordpress_tests/" wp-tests-config.php
2955
sed -i "s/yourusernamehere/root/" wp-tests-config.php
3056
sed -i "s/yourpasswordhere//" wp-tests-config.php
3157
travis_retry svn checkout https://plugins.svn.wordpress.org/wordpress-importer/tags/0.6.3/ tests/phpunit/data/plugins/wordpress-importer
32-
fi
33-
- |
34-
if [[ "$WP_TRAVIS_OBJECT_CACHE" == "true" ]]; then
35-
cp tests/phpunit/includes/object-cache.php src/wp-content/object-cache.php
36-
echo "extension = memcached.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
37-
fi
58+
fi
59+
3860
before_script:
39-
- |
40-
# Remove Xdebug for a huge performance increase:
41-
if [ -f ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini ]; then
42-
phpenv config-rm xdebug.ini
43-
else
44-
echo "xdebug.ini does not exist"
45-
fi
46-
- |
47-
# Export Composer's global bin dir to PATH, but not on PHP 5.2:
48-
if [[ ${TRAVIS_PHP_VERSION:0:3} != "5.2" ]]; then
49-
composer config --list --global
50-
export PATH=`composer config --list --global | grep '\[home\]' | { read a; echo "${a#* }/vendor/bin:$PATH"; }`
51-
fi
52-
- |
53-
# Install the specified version of PHPUnit depending on the PHP version:
54-
if [[ "$WP_TRAVISCI" == "travis:phpunit" ]]; then
55-
case "$TRAVIS_PHP_VERSION" in
56-
7.3|7.2|7.1|7.0|nightly)
57-
echo "Using PHPUnit 6.x"
58-
travis_retry composer global require "phpunit/phpunit:^6"
59-
;;
60-
5.6|5.5|5.4|5.3)
61-
echo "Using PHPUnit 4.x"
62-
travis_retry composer global require "phpunit/phpunit:^4"
63-
;;
64-
5.2)
65-
# Do nothing, use default PHPUnit 3.6.x
66-
echo "Using default PHPUnit, hopefully 3.6"
67-
;;
68-
*)
69-
echo "No PHPUnit version handling for PHP version $TRAVIS_PHP_VERSION"
70-
exit 1
71-
;;
72-
esac
73-
fi
74-
- npm --version
75-
- node --version
76-
- nvm install
77-
- npm install -g grunt-cli
78-
- npm install
79-
- npm prune
80-
- mysql --version
81-
- phpenv versions
82-
- php --version
83-
- php -m
84-
- npm --version
85-
- node --version
86-
- which phpunit
87-
- phpunit --version
88-
- curl --version
89-
- grunt --version
90-
- git --version
91-
- svn --version
92-
- locale -a
93-
script: grunt $WP_TRAVISCI
61+
- npm --version
62+
- node --version
63+
- nvm install
64+
- |
65+
if [[ "$WP_TRAVISCI" == "travis:phpunit" ]]; then
66+
phpenv config-rm xdebug.ini
67+
npm install -g grunt-cli
68+
mysql --version
69+
phpenv versions
70+
php --version
71+
php -m
72+
fi
73+
- |
74+
if [[ "$NPM_INSTALL" == "true" ]]; then
75+
npm install
76+
fi
77+
- |
78+
if [[ "$WP_TRAVISCI" == "test:php" ]]; then
79+
npm run env:start
80+
npm run build
81+
docker-compose run --rm mysql mysql --version
82+
docker-compose run --rm php php --version
83+
docker-compose run --rm php php -m
84+
docker-compose run --rm phpunit phpunit --version
85+
fi
86+
- |
87+
if [[ "$LOCAL_PHP_MEMCACHED" == "true" ]]; then
88+
cp tests/phpunit/includes/object-cache.php build/wp-content/object-cache.php
89+
# The memcached server needs to start after `npm run env:start`, which sets up the Docker network.
90+
docker run --name memcached --net $(basename "$PWD")_wpdevnet -d memcached
91+
fi
92+
- |
93+
if [[ "$WP_INSTALL" == "true" ]]; then
94+
# Run the install process after memcached has started.
95+
npm run env:install
96+
fi
97+
- npm --version
98+
- node --version
99+
- curl --version
100+
- git --version
101+
- svn --version
102+
- php --version
103+
- php -i
104+
- locale -a
105+
106+
script:
107+
- |
108+
if [[ "$WP_TRAVISCI" == "test:php" ]]; then
109+
npm run test:php -- --verbose -c phpunit.xml.dist &&
110+
npm run test:php -- --verbose -c phpunit.xml.dist --group ajax &&
111+
npm run test:php -- --verbose -c tests/phpunit/multisite.xml &&
112+
npm run test:php -- --verbose -c tests/phpunit/multisite.xml --group ms-files &&
113+
npm run test:php -- --verbose -c phpunit.xml.dist --group external-http &&
114+
npm run test:php -- --verbose -c phpunit.xml.dist --group restapi-jsclient &&
115+
# __fakegroup__ is excluded to force PHPUnit to ignore the <exclude> settings in phpunit.xml.dist.
116+
LOCAL_PHP_XDEBUG=true npm run test:php -- -v --group xdebug --exclude-group __fakegroup__
117+
else
118+
npm run grunt $WP_TRAVISCI
119+
fi
120+
121+
after_script:
122+
- |
123+
if [[ "$WP_TEST_REPORTER" == "true" ]]; then
124+
git clone https://github.com/WordPress/phpunit-test-runner.git test-runner
125+
docker-compose run --rm -e WPT_PREPARE_DIR=/var/www -e WPT_TEST_DIR=/var/www php php test-runner/report.php
126+
fi
127+
94128
notifications:
95129
slack:
96130
rooms:

0 commit comments

Comments
 (0)