Skip to content

Commit 181144c

Browse files
committed
Build/Test Tools: Backport the local Docker environment to the 4.7 branch.
This commit introduces the Docker-based local WordPress development environment to the 4.7 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 4.7 branch. See #48301, #47767. git-svn-id: https://develop.svn.wordpress.org/branches/4.7@49532 602fd350-edb4-49c9-b593-d223f7449a82
1 parent bbfaa06 commit 181144c

File tree

15 files changed

+2840
-79
lines changed

15 files changed

+2840
-79
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.1-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 & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,129 @@
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.1
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.1-fpm WP_TRAVISCI=test:php
25+
name: "PHPUnit Tests: PHP 7.1"
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+
name: "PHPUnit Tests: PHP 5.2"
32+
fast_finish: true
33+
2334
before_install:
24-
- |
25-
if [[ "$WP_TRAVISCI" == "travis:phpunit" ]]; then
35+
- |
36+
if [[ "$WP_TRAVISCI" == "test:php" ]]; then
37+
travis_retry svn checkout https://plugins.svn.wordpress.org/wordpress-importer/tags/0.6.3/ tests/phpunit/data/plugins/wordpress-importer
38+
fi
39+
- |
40+
if [[ "$WP_TRAVISCI" != "travis:phpunit" ]]; then
41+
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
42+
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
43+
sudo apt-get update
44+
sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce
45+
fi
46+
- |
47+
sudo rm /usr/local/bin/docker-compose
48+
curl -L https://github.com/docker/compose/releases/download/1.24.0/docker-compose-`uname -s`-`uname -m` > docker-compose
49+
chmod +x docker-compose
50+
sudo mv docker-compose /usr/local/bin
51+
- |
52+
if [[ "$WP_TRAVISCI" == "travis:phpunit" ]]; then
2653
mysql -u root -e "CREATE DATABASE wordpress_tests;"
2754
cp wp-tests-config-sample.php wp-tests-config.php
2855
sed -i "s/youremptytestdbnamehere/wordpress_tests/" wp-tests-config.php
2956
sed -i "s/yourusernamehere/root/" wp-tests-config.php
3057
sed -i "s/yourpasswordhere//" wp-tests-config.php
31-
svn checkout https://plugins.svn.wordpress.org/wordpress-importer/trunk tests/phpunit/data/plugins/wordpress-importer
32-
fi
33-
- |
34-
if [[ "$WP_TRAVIS_OBJECT_CACHE" == "true" ]]; then
35-
curl https://raw.githubusercontent.com/tollmanz/wordpress-pecl-memcached-object-cache/584392b56dc4adbe52bd2c7b86f875e23a3e5f75/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+
travis_retry svn checkout https://plugins.svn.wordpress.org/wordpress-importer/tags/0.6.3/ tests/phpunit/data/plugins/wordpress-importer
59+
fi
60+
3861
before_script:
39-
- |
40-
# Remove Xdebug for a huge performance increase, but not from nightly:
41-
stable='^[0-9\.]+$'
42-
if [[ "$TRAVIS_PHP_VERSION" =~ $stable ]]; then
43-
phpenv config-rm xdebug.ini
44-
fi
45-
- |
46-
# Export Composer's global bin dir to PATH, but not on PHP 5.2:
47-
if [[ ${TRAVIS_PHP_VERSION:0:3} != "5.2" ]]; then
48-
composer config --list --global
49-
export PATH=`composer config --list --global | grep '\[home\]' | { read a; echo "${a#* }/vendor/bin:$PATH"; }`
50-
fi
51-
- |
52-
# Install the specified version of PHPUnit depending on the PHP version:
53-
if [[ "$WP_TRAVISCI" == "travis:phpunit" ]]; then
54-
case "$TRAVIS_PHP_VERSION" in
55-
7.1|7.0|nightly)
56-
echo "Using PHPUnit 6.x"
57-
composer global require "phpunit/phpunit:^6"
58-
;;
59-
5.6|5.5|5.4|5.3)
60-
echo "Using PHPUnit 4.x"
61-
composer global require "phpunit/phpunit:^4"
62-
;;
63-
5.2)
64-
# Do nothing, use default PHPUnit 3.6.x
65-
echo "Using default PHPUnit, hopefully 3.6"
66-
;;
67-
*)
68-
echo "No PHPUnit version handling for PHP version $TRAVIS_PHP_VERSION"
69-
exit 1
70-
;;
71-
esac
72-
fi
73-
- npm --version
74-
- node --version
75-
- nvm install 6.9.1
76-
- npm install -g grunt-cli
77-
- npm install
78-
- npm prune
79-
- mysql --version
80-
- phpenv versions
81-
- php --version
82-
- php -m
83-
- npm --version
84-
- node --version
85-
- which phpunit
86-
- phpunit --version
87-
- curl --version
88-
- grunt --version
89-
- git --version
90-
- svn --version
91-
script: grunt $WP_TRAVISCI
62+
- npm --version
63+
- node --version
64+
- nvm install
65+
- |
66+
if [[ "$WP_TRAVISCI" == "travis:phpunit" ]]; then
67+
phpenv config-rm xdebug.ini
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+
docker run --name memcached --net $(basename "$PWD")_wpdevnet -d memcached
90+
fi
91+
- |
92+
if [[ "$WP_INSTALL" == "true" ]]; then
93+
# Run the install process after memcached has started.
94+
npm run env:install
95+
fi
96+
- npm --version
97+
- node --version
98+
- curl --version
99+
- git --version
100+
- svn --version
101+
- php --version
102+
- php -i
103+
- locale -a
104+
105+
script:
106+
- |
107+
if [[ "$WP_TRAVISCI" == "test:php" ]]; then
108+
npm run test:php -- --verbose -c phpunit.xml.dist &&
109+
npm run test:php -- --verbose -c phpunit.xml.dist --group ajax &&
110+
npm run test:php -- --verbose -c tests/phpunit/multisite.xml &&
111+
npm run test:php -- --verbose -c tests/phpunit/multisite.xml --group ms-files &&
112+
npm run test:php -- --verbose -c phpunit.xml.dist --group external-http &&
113+
npm run test:php -- --verbose -c phpunit.xml.dist --group restapi-jsclient &&
114+
# __fakegroup__ is excluded to force PHPUnit to ignore the <exclude> settings in phpunit.xml.dist.
115+
LOCAL_PHP_XDEBUG=true npm run test:php -- -v --group xdebug --exclude-group __fakegroup__
116+
else
117+
npm run grunt $WP_TRAVISCI
118+
fi
119+
120+
after_script:
121+
- |
122+
if [[ "$WP_TEST_REPORTER" == "true" ]]; then
123+
git clone https://github.com/WordPress/phpunit-test-runner.git test-runner
124+
docker-compose run --rm -e WPT_PREPARE_DIR=/var/www -e WPT_TEST_DIR=/var/www php php test-runner/report.php
125+
fi
126+
92127
notifications:
93128
slack:
94129
rooms:

0 commit comments

Comments
 (0)