Skip to content

Commit bd2fd7f

Browse files
Use Composer to install WP-CLI in tests
Doing so ensures tests run against local copy of command, instead of Phar bundled version.
1 parent 28841da commit bd2fd7f

File tree

4 files changed

+18
-36
lines changed

4 files changed

+18
-36
lines changed

.travis.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ cache:
1717

1818
env:
1919
global:
20-
- WP_CLI_BIN_DIR=/tmp/wp-cli-phar
20+
- PATH="$TRAVIS_BUILD_DIR/vendor/bin:$PATH"
21+
- WP_CLI_BIN_DIR="$TRAVIS_BUILD_DIR/vendor/bin"
2122

2223
matrix:
2324
include:
@@ -32,9 +33,15 @@ matrix:
3233
- php: 5.3
3334
env: WP_VERSION=latest
3435

35-
before_script:
36+
before_install:
3637
- phpenv config-rm xdebug.ini
37-
- composer validate
38+
39+
install:
40+
- composer install
3841
- bash bin/install-package-tests.sh
3942

40-
script: ./vendor/bin/behat --format progress --strict
43+
before_script:
44+
- composer validate
45+
46+
script:
47+
- behat --format progress --strict

bin/install-package-tests.sh

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,9 @@
22

33
set -ex
44

5-
WP_CLI_BIN_DIR=${WP_CLI_BIN_DIR-/tmp/wp-cli-phar}
6-
7-
PACKAGE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/../ && pwd )"
8-
9-
download() {
10-
if [ `which curl` ]; then
11-
curl -s "$1" > "$2";
12-
elif [ `which wget` ]; then
13-
wget -nv -O "$2" "$1"
14-
fi
15-
}
16-
17-
install_wp_cli() {
18-
19-
# the Behat test suite will pick up the executable found in $WP_CLI_BIN_DIR
20-
mkdir -p $WP_CLI_BIN_DIR
21-
download https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli-nightly.phar $WP_CLI_BIN_DIR/wp
22-
chmod +x $WP_CLI_BIN_DIR/wp
23-
24-
}
25-
26-
download_behat() {
27-
28-
cd $PACKAGE_DIR
29-
composer require --dev behat/behat='~2.5'
30-
31-
}
32-
335
install_db() {
346
mysql -e 'CREATE DATABASE IF NOT EXISTS wp_cli_test;' -uroot
357
mysql -e 'GRANT ALL PRIVILEGES ON wp_cli_test.* TO "wp_cli_test"@"localhost" IDENTIFIED BY "password1"' -uroot
368
}
379

38-
install_wp_cli
39-
download_behat
4010
install_db

composer.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,16 @@
2222
},
2323
"files": [ "search-replace-command.php" ]
2424
},
25-
"require": {},
25+
"require": {
26+
"wp-cli/wp-cli": "dev-master"
27+
},
2628
"require-dev": {
2729
"behat/behat": "~2.5"
2830
},
2931
"extra": {
32+
"branch-alias": {
33+
"dev-master": "1.0.x-dev"
34+
},
3035
"commands": [
3136
"search-replace"
3237
]

search-replace-command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
}
66

77
$autoload = dirname( __FILE__ ) . '/vendor/autoload.php';
8-
if ( file_exists( $autoload ) ) {
8+
if ( file_exists( $autoload ) && ! class_exists( 'Search_Replace_Command' ) ) {
99
require_once $autoload;
1010
}
1111

0 commit comments

Comments
 (0)