diff --git a/.travis.yml b/.travis.yml index e3c0571b72..3fadddac3c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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: diff --git a/features/bootstrap/FeatureContext.php b/features/bootstrap/FeatureContext.php index fd7c014077..b7d64c5dd7 100644 --- a/features/bootstrap/FeatureContext.php +++ b/features/bootstrap/FeatureContext.php @@ -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'; @@ -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', @@ -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() { @@ -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!"; diff --git a/features/cli-info.feature b/features/cli-info.feature index b5cedc1457..19cd0a09e0 100644 --- a/features/cli-info.feature +++ b/features/cli-info.feature @@ -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: diff --git a/features/cli.feature b/features/cli.feature index 4634b09ab7..74373f1572 100644 --- a/features/cli.feature +++ b/features/cli.feature @@ -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" @@ -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" @@ -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" @@ -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" @@ -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" @@ -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" @@ -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} @@ -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: diff --git a/features/steps/given.php b/features/steps/given.php index 6522e8b303..837a565d3a 100644 --- a/features/steps/given.php +++ b/features/steps/given.php @@ -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(); diff --git a/php/commands/src/CLI_Command.php b/php/commands/src/CLI_Command.php index 36d8953eab..f6b6c71149 100644 --- a/php/commands/src/CLI_Command.php +++ b/php/commands/src/CLI_Command.php @@ -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 ) );