Skip to content

Commit d6620d5

Browse files
author
Felix Arntz
committed
Fix tests setup to work on old PHP versions and be more performant.
1 parent d6d9803 commit d6620d5

File tree

3 files changed

+89
-150
lines changed

3 files changed

+89
-150
lines changed

.travis.yml

Lines changed: 68 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,89 @@
1+
sudo: false
12
language: php
2-
dist: precise
3-
3+
cache:
4+
directories:
5+
- node_modules
6+
- vendor
7+
- php52/vendor
8+
- $HOME/.composer/cache
49
php:
5-
- 5.2
6-
- 5.3
10+
- 5.4
711
- 5.5
812
- 5.6
913
- 7.0
1014
- 7.1
11-
1215
env:
13-
- WP_VERSION=latest WP_MULTISITE=0
14-
- WP_VERSION=4.5 WP_MULTISITE=0
15-
16+
- WP_VERSION=latest
17+
- WP_VERSION=4.5
18+
dist: trusty
1619
matrix:
1720
include:
21+
- php: 5.2
22+
env: WP_VERSION=latest
23+
dist: precise
24+
- php: 5.2
25+
env: WP_VERSION=4.5
26+
dist: precise
27+
- php: 5.3
28+
env: WP_VERSION=latest
29+
dist: precise
30+
- php: 5.3
31+
env: WP_VERSION=4.5
32+
dist: precise
1833
- php: 5.6
1934
env: WP_VERSION=latest WP_MULTISITE=1
35+
- php: 5.6
36+
env: WP_VERSION=4.5 WP_MULTISITE=1
2037
allow_failures:
2138
- php: 5.2
2239

2340
before_script:
24-
- rm -rf ~/.nvm && git clone https://github.com/creationix/nvm.git ~/.nvm && (cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`) && source ~/.nvm/nvm.sh && nvm install 8
25-
- composer install
41+
- |
42+
stable='^[0-9\.]+$'
43+
if [[ "$TRAVIS_PHP_VERSION" =~ $stable ]]; then
44+
if [ -f ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini ]; then
45+
phpenv config-rm xdebug.ini
46+
fi
47+
fi
48+
- PLUGIN_SLUG=$(basename $(pwd))
49+
- export WP_DEVELOP_DIR=/tmp/wordpress/
50+
- git clone --depth=50 --branch="$WP_VERSION" git://develop.git.wordpress.org/ /tmp/wordpress
51+
- cd ..
52+
- cp -r "$PLUGIN_SLUG" "/tmp/wordpress/src/wp-content/plugins/$PLUGIN_SLUG"
53+
- cd /tmp/wordpress/
54+
- cp wp-tests-config-sample.php wp-tests-config.php
55+
- sed -i "s/youremptytestdbnamehere/wordpress_tests/" wp-tests-config.php
56+
- sed -i "s/yourusernamehere/travis/" wp-tests-config.php
57+
- sed -i "s/yourpasswordhere//" wp-tests-config.php
58+
- mysql -e "CREATE DATABASE wordpress_tests;" -uroot
59+
- cd "/tmp/wordpress/src/wp-content/plugins/$PLUGIN_SLUG"
60+
- phpenv rehash
61+
- |
62+
case "$TRAVIS_PHP_VERSION" in
63+
5.6|5.5|5.4|5.3)
64+
composer global require "phpunit/phpunit:^4"
65+
composer install
66+
;;
67+
5.2)
68+
;;
69+
*)
70+
composer global require "phpunit/phpunit:^6"
71+
composer install
72+
;;
73+
esac
2674
- cd php52
2775
- composer install
2876
- cd ..
29-
- npm install
30-
- bash tests/bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION
31-
- export PATH="$HOME/.composer/vendor/bin:$PATH"
3277
- |
33-
if [[ ${TRAVIS_PHP_VERSION:0:2} == "7." ]]; then
34-
composer global require "phpunit/phpunit=5.7.*"
35-
else
36-
composer global require "phpunit/phpunit=4.8.*"
37-
fi
38-
39-
78+
rm -rf ~/.nvm
79+
git clone https://github.com/creationix/nvm.git ~/.nvm
80+
cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`
81+
source ~/.nvm/nvm.sh
82+
nvm install 8
83+
- npm install
4084
script:
4185
- phpunit
42-
- npm test
86+
- |
87+
if [[ "$TRAVIS_PHP_VERSION" != "5.2" ]]; then
88+
npm test
89+
fi

tests/bin/install-wp-tests.sh

Lines changed: 0 additions & 120 deletions
This file was deleted.

tests/phpunit/bootstrap.php

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
<?php
2-
$_tests_dir = getenv('WP_TESTS_DIR');
3-
if ( !$_tests_dir ) $_tests_dir = '/tmp/wordpress-tests-lib';
4-
require_once $_tests_dir . '/includes/functions.php';
5-
// Include our plugin.
6-
function _manually_load_plugin() {
7-
require dirname( __FILE__ ) . '/../../wpengine-phpcompat.php';
2+
3+
// Disable xdebug backtrace.
4+
if ( function_exists( 'xdebug_disable' ) ) {
5+
xdebug_disable();
6+
}
7+
8+
if ( false !== getenv( 'WP_PLUGIN_DIR' ) ) {
9+
define( 'WP_PLUGIN_DIR', getenv( 'WP_PLUGIN_DIR' ) );
10+
}
11+
12+
$GLOBALS['wp_tests_options'] = array(
13+
'active_plugins' => array( basename( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/wpengine-phpcompat.php' ),
14+
);
15+
16+
if ( false !== getenv( 'WP_DEVELOP_DIR' ) ) {
17+
$test_root = getenv( 'WP_DEVELOP_DIR' ) . '/tests/phpunit';
18+
} elseif ( file_exists( '/tmp/wordpress-tests-lib/includes/bootstrap.php' ) ) {
19+
$test_root = '/tmp/wordpress-tests-lib';
20+
} else {
21+
$test_root = '../../../../../../../tests/phpunit';
822
}
9-
tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
1023

11-
// Bootstrap WordPress.
12-
require $_tests_dir . '/includes/bootstrap.php';
24+
require $test_root . '/includes/bootstrap.php';

0 commit comments

Comments
 (0)