Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ cache:

env:
global:
- WP_CLI_BIN_DIR=/tmp/wp-cli-phar
- PATH="$TRAVIS_BUILD_DIR/vendor/bin:$PATH"
- WP_CLI_BIN_DIR="$TRAVIS_BUILD_DIR/vendor/bin"

matrix:
include:
Expand All @@ -32,9 +33,16 @@ matrix:
- php: 5.3
env: WP_VERSION=latest

before_script:
before_install:
- phpenv config-rm xdebug.ini
- composer validate

install:
- composer require wp-cli/wp-cli:dev-master
- composer install
- bash bin/install-package-tests.sh

script: ./vendor/bin/behat --format progress --strict
before_script:
- composer validate

script:
- ./bin/test.sh
30 changes: 0 additions & 30 deletions bin/install-package-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,9 @@

set -ex

WP_CLI_BIN_DIR=${WP_CLI_BIN_DIR-/tmp/wp-cli-phar}

PACKAGE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/../ && pwd )"

download() {
if [ `which curl` ]; then
curl -s "$1" > "$2";
elif [ `which wget` ]; then
wget -nv -O "$2" "$1"
fi
}

install_wp_cli() {

# the Behat test suite will pick up the executable found in $WP_CLI_BIN_DIR
mkdir -p $WP_CLI_BIN_DIR
download https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli-nightly.phar $WP_CLI_BIN_DIR/wp
chmod +x $WP_CLI_BIN_DIR/wp

}

download_behat() {

cd $PACKAGE_DIR
composer require --dev behat/behat='~2.5'

}

install_db() {
mysql -e 'CREATE DATABASE IF NOT EXISTS wp_cli_test;' -uroot
mysql -e 'GRANT ALL PRIVILEGES ON wp_cli_test.* TO "wp_cli_test"@"localhost" IDENTIFIED BY "password1"' -uroot
}

install_wp_cli
download_behat
install_db
7 changes: 7 additions & 0 deletions bin/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

set -ex

# Run the functional tests
BEHAT_TAGS=$(php utils/behat-tags.php)
behat --format progress $BEHAT_TAGS --strict
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,22 @@
}
],
"minimum-stability": "dev",
"prefer-stable": true,
"autoload": {
"psr-4": {"": "src/"},
"files": [ "package-command.php" ]
},
"require": {
"wp-cli/wp-cli": "*",
"composer/composer": "^1.2.0"
},
"require-dev": {
"behat/behat": "~2.5"
},
"extra": {
"branch-alias": {
"dev-master": "1.x-dev"
},
"commands": [
"package browse",
"package install",
Expand Down
22 changes: 18 additions & 4 deletions features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ class FeatureContext extends BehatContext implements ClosuredContextInterface {
*/
private static function get_process_env_variables() {
// Ensure we're using the expected `wp` binary
$bin_dir = getenv( 'WP_CLI_BIN_DIR' ) ?: realpath( __DIR__ . "/../../bin" );
$bin_dir = getenv( 'WP_CLI_BIN_DIR' ) ?: realpath( __DIR__ . '/../../bin' );
$vendor_dir = realpath( __DIR__ . '/../../vendor/bin' );
$env = array(
'PATH' => $bin_dir . ':' . getenv( 'PATH' ),
'PATH' => $bin_dir . ':' . $vendor_dir . ':' . getenv( 'PATH' ),
'BEHAT_RUN' => 1,
'HOME' => '/tmp/wp-cli-home',
);
Expand Down Expand Up @@ -218,9 +219,21 @@ public function create_run_dir() {
public function build_phar( $version = 'same' ) {
$this->variables['PHAR_PATH'] = $this->variables['RUN_DIR'] . '/' . uniqid( "wp-cli-build-", TRUE ) . '.phar';

// Test running against WP-CLI proper
$make_phar_path = __DIR__ . '/../../utils/make-phar.php';
if ( ! file_exists( $make_phar_path ) ) {
// Test running against a package installed as a WP-CLI dependency
// WP-CLI installed as a project dependency
$make_phar_path = __DIR__ . '/../../../../../utils/make-phar.php';
if ( ! file_exists( $make_phar_path ) ) {
// WP-CLI as a dependency of this project
$make_phar_path = __DIR__ . '/../../vendor/wp-cli/wp-cli/utils/make-phar.php';
}
}

$this->proc( Utils\esc_cmd(
'php -dphar.readonly=0 %1$s %2$s --version=%3$s && chmod +x %2$s',
__DIR__ . '/../../utils/make-phar.php',
$make_phar_path,
$this->variables['PHAR_PATH'],
$version
) )->run_check();
Expand Down Expand Up @@ -318,7 +331,8 @@ public function download_wp( $subdir = '' ) {

public function create_config( $subdir = '' ) {
$params = self::$db_settings;
$params['dbprefix'] = $subdir ?: 'wp_';
// Replaces all characters that are not alphanumeric or an underscore into an underscore.
$params['dbprefix'] = $subdir ? preg_replace( '#[^a-zA-Z\_0-9]#', '_', $subdir ) : 'wp_';

$params['skip-salts'] = true;
$this->proc( 'wp core config', $params, $subdir )->run_check();
Expand Down
6 changes: 5 additions & 1 deletion features/bootstrap/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ function extract_from_phar( $path ) {

function load_dependencies() {
if ( inside_phar() ) {
require WP_CLI_ROOT . '/vendor/autoload.php';
if ( file_exists( WP_CLI_ROOT . '/vendor/autoload.php' ) ) {
require WP_CLI_ROOT . '/vendor/autoload.php';
} elseif ( file_exists( dirname( dirname( WP_CLI_ROOT ) ) . '/autoload.php' ) ) {
require dirname( dirname( WP_CLI_ROOT ) ) . '/autoload.php';
}
return;
}

Expand Down
2 changes: 1 addition & 1 deletion features/package-update.feature
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Feature: Update WP-CLI packages
When I run `wp package update`
Then STDOUT should contain:
"""
Nothing to install or update
Package operations: 0 installs, 0 updates, 0 removals
"""
And STDOUT should contain:
"""
Expand Down
17 changes: 0 additions & 17 deletions features/package.feature
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,3 @@ Feature: Manage WP-CLI packages
"""
danielbachhuber/wp-cli-reset-post-date-command
"""

Scenario: Run package commands early, before any bad code can break them
Given an empty directory
And a bad-command.php file:
"""
<?php
WP_CLI::error( "Doing it wrong." );
"""

When I try `wp --require=bad-command.php option`
Then STDERR should contain:
"""
Error: Doing it wrong.
"""

When I run `wp --require=bad-command.php package list`
Then STDERR should be empty
2 changes: 1 addition & 1 deletion package-command.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
}

$autoload = dirname( __FILE__ ) . '/vendor/autoload.php';
if ( file_exists( $autoload ) ) {
if ( file_exists( $autoload ) && ! class_exists( 'Package_Command' ) ) {
require_once $autoload;
}
WP_CLI::add_command( 'package', 'Package_Command' );
20 changes: 20 additions & 0 deletions utils/behat-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,26 @@ function version_tags( $prefix, $current, $operator = '<' ) {
# Skip Github API tests by default because of rate limiting. See https://github.com/wp-cli/wp-cli/issues/1612
$skip_tags[] = '@github-api';

# Require PHP extension, eg 'imagick'.
function extension_tags() {
$extension_tags = array();
exec( "grep '@require-extension-[A-Za-z_]*' -h -o features/*.feature | uniq", $extension_tags );

$skip_tags = array();

$substr_start = strlen( '@require-extension-' );
foreach ( $extension_tags as $tag ) {
$extension = substr( $tag, $substr_start );
if ( ! extension_loaded( $extension ) ) {
$skip_tags[] = $tag;
}
}

return $skip_tags;
}

$skip_tags = array_merge( $skip_tags, extension_tags() );

if ( !empty( $skip_tags ) ) {
echo '--tags=~' . implode( '&&~', $skip_tags );
}
Expand Down