Skip to content
Open
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
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ language: php
env:
global:
- WP_CLI_BIN_DIR=/tmp/wp-cli-phar
matrix:
secure: AT4gaEJlw3atKF7Q40wxdVGrHMLj5GhYy3RNrSF3XiHoW2iQKKG/kmnArGd8x6YtHjjXfE/7Gvb+9hKfIDM15Rn75rBJWHRI0M+Y1+0kbZLWhrkkgx6zBRvbqFZO0maBYCOW1ov5FIQe6YSKfy/I+IUuNwdL4XMv6JqduyCxVN/+oxvF2zX5pP4ontXwze36GxGIebzj4dFgMXf2ra4z7HDcoYLCinymp7z1M8wgB9QioQfdkdQ6Oq8mQUX4eOE3uQKvsGDR3eVe74aL3l49Rrwarz0bkeOWrKwX8ljQNOc2CZv/vAF1bkj0si7V6DeZ1EL/hhCO5YVLFnK+cCV2V9nkKOJ0KG6KVrjQE5fr4Iw1wXSPgsjI5ta79e4jN2KwBzPADMlE1lK7Br6F9l5T+n2d85YL4im2x5ynCOAsMIsuJI8WJz9Ml2l+v6OUg765RhmvYMuGPom9TwJwl4MRHX3i6d2/C+1yoONXa3N582vyLuPAxaoS49DfnTKrBVsLsyuV4mpoZVYy40i5HJ1e2xL9PLmJFlj5qihWRXHylm5zp01+Zydrk+3lUc4HhvZG/pnxu0v1wUzf5d4JKrJfZY1srh+Xh6Z2wPgDnCYvs+XlQOWOJAElwjj/zlU42361GFQoeJpjCFoAK1505CTcmXpx3Nj2LjTriO6ms1sTK5c=

matrix:
include:
Expand Down
15 changes: 14 additions & 1 deletion features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use \WP_CLI\Process;
use \WP_CLI\Utils;

use Symfony\Component\Filesystem\Filesystem,
Symfony\Component\Filesystem\Exception\IOExceptionInterface;

// Inside a community package
if ( file_exists( __DIR__ . '/utils.php' ) ) {
require_once __DIR__ . '/utils.php';
Expand Down Expand Up @@ -44,7 +47,7 @@
*/
class FeatureContext extends BehatContext implements ClosuredContextInterface {

private static $cache_dir, $suite_cache_dir;
private static $cache_dir, $suite_cache_dir, $fs;

private static $db_settings = array(
'dbname' => 'wp_cli_test',
Expand Down Expand Up @@ -207,6 +210,9 @@ public function __construct( array $parameters ) {
$this->drop_db();
$this->set_cache_dir();
$this->variables['CORE_CONFIG_SETTINGS'] = Utils\assoc_args_to_str( self::$db_settings );
if ( ! self::$fs ) {
self::$fs = new FileSystem;
}
}

public function getStepDefinitionResources() {
Expand Down Expand Up @@ -390,6 +396,13 @@ public function move_files( $src, $dest ) {
rename( $this->variables['RUN_DIR'] . "/$src", $this->variables['RUN_DIR'] . "/$dest" );
}

/**
* Remove a directory (recursive).
*/
public function remove_dir( $dir ) {
self::$fs->remove( $dir );
}

public function add_line_to_wp_config( &$wp_config_code, $line ) {
$token = "/* That's all, stop editing!";

Expand Down
5 changes: 5 additions & 0 deletions features/cli-info.feature
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
Feature: Review CLI information

Background:
When I run `wp package path`
Then save STDOUT as {PACKAGE_PATH}

Scenario: Get the path to the packages directory
Given an empty directory
And an empty {PACKAGE_PATH} directory

When I run `wp cli info --format=json`
Then STDOUT should be JSON containing:
Expand Down
27 changes: 15 additions & 12 deletions features/cli.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ Feature: `wp cli` tasks
{TRUE_VERSION}
"""

@github-api
Scenario: Check for updates
Given an empty directory
And a new Phar with version "0.0.0"
Expand All @@ -27,7 +26,8 @@ Feature: `wp cli` tasks
"""
And STDERR should be empty

@github-api
# The latest 1.2.1 phar fails on Travis PHP 5.3 due to double slash in boot-phar.php path so need >= 5.4 to do cli update
@require-php-5.4
Scenario: Do WP-CLI Update
Given an empty directory
And a new Phar with version "0.0.0"
Expand Down Expand Up @@ -64,7 +64,6 @@ Feature: `wp cli` tasks
0.0.0
"""

@github-api
Scenario: Patch update from 0.14.0 to 0.14.1
Given an empty directory
And a new Phar with version "0.14.0"
Expand Down Expand Up @@ -93,7 +92,8 @@ Feature: `wp cli` tasks
WP-CLI 0.14.1
"""

@github-api
# See above
@require-php-5.4
Scenario: Not a patch update from 0.14.0
Given an empty directory
And a new Phar with version "0.14.0"
Expand All @@ -110,7 +110,8 @@ Feature: `wp cli` tasks
And STDERR should be empty
And the return code should be 0

@require-php-5.6
# See above
@require-php-5.4
Scenario: Install WP-CLI nightly
Given an empty directory
And a new Phar with version "0.14.0"
Expand All @@ -128,7 +129,8 @@ Feature: `wp cli` tasks
And STDERR should be empty
And the return code should be 0

@github-api @less-than-php-7
# See above
@require-php-5.4
Scenario: Install WP-CLI stable
Given an empty directory
And a new Phar with version "0.14.0"
Expand All @@ -137,7 +139,7 @@ Feature: `wp cli` tasks
y
"""

When I run `{PHAR_PATH} cli check-update --minor --field=version`
When I run `{PHAR_PATH} cli check-update --field=version | head -1`
Then STDOUT should not be empty
And save STDOUT as {UPDATE_VERSION}

Expand All @@ -157,11 +159,12 @@ Feature: `wp cli` tasks
And STDERR should be empty
And the return code should be 0

When I run `{PHAR_PATH} cli check-update`
Then STDOUT should be:
"""
Success: WP-CLI is at the latest version.
"""
# This can hit github rate limiting on Travis as the latest 1.2.1 phar doesn't use WP_CLI_GITHUB_TOKEN.
#When I run `{PHAR_PATH} cli check-update`
#Then STDOUT should be:
#"""
#Success: WP-CLI is at the latest version.
#"""

When I run `{PHAR_PATH} cli version`
Then STDOUT should be:
Expand Down
6 changes: 6 additions & 0 deletions features/steps/given.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ function ( $world ) {
}
);

$steps->Given( '/^an empty ([^\s]+) directory$/',
function ( $world, $dir ) {
$world->remove_dir( $world->replace_variables( $dir ) );
}
);

$steps->Given( '/^an empty cache/',
function ( $world ) {
$world->variables['SUITE_CACHE_DIR'] = FeatureContext::create_cache_dir();
Expand Down
7 changes: 6 additions & 1 deletion php/commands/src/CLI_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,12 @@ private function get_updates( $assoc_args ) {
$headers = array(
'Accept' => 'application/json'
);
$response = Utils\http_request( 'GET', $url, $headers, $options );

if ( $github_token = getenv( 'WP_CLI_GITHUB_TOKEN' ) ) {
$headers['Authorization'] = 'token ' . $github_token;
}

$response = Utils\http_request( 'GET', $url, null, $headers, $options );

if ( ! $response->success || 200 !== $response->status_code ) {
WP_CLI::error( sprintf( "Failed to get latest version (HTTP code %d).", $response->status_code ) );
Expand Down