Skip to content

Commit 77552bd

Browse files
authored
Merge pull request #106 from wp-cli/92-oldest-wp-version
Run tests against oldest supported WP version
2 parents b87c4c8 + baf8cbb commit 77552bd

File tree

6 files changed

+181
-22
lines changed

6 files changed

+181
-22
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ matrix:
2929
env: WP_VERSION=latest
3030
- php: 5.6
3131
env: WP_VERSION=latest
32+
- php: 5.6
33+
env: WP_VERSION=3.7.11
3234
- php: 5.6
3335
env: WP_VERSION=trunk
3436
- php: 5.3

features/bootstrap/FeatureContext.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,14 +239,40 @@ public function build_phar( $version = 'same' ) {
239239
) )->run_check();
240240
}
241241

242+
public function download_phar( $version = 'same' ) {
243+
if ( 'same' === $version ) {
244+
$version = WP_CLI_VERSION;
245+
}
246+
247+
$download_url = sprintf(
248+
'https://github.com/wp-cli/wp-cli/releases/download/v%1$s/wp-cli-%1$s.phar',
249+
$version
250+
);
251+
252+
$this->variables['PHAR_PATH'] = $this->variables['RUN_DIR'] . '/'
253+
. uniqid( 'wp-cli-download-', true )
254+
. '.phar';
255+
256+
Process::create( \WP_CLI\Utils\esc_cmd(
257+
'curl -sSL %s > %s',
258+
$download_url,
259+
$this->variables['PHAR_PATH']
260+
) )->run_check();
261+
262+
Process::create( \WP_CLI\Utils\esc_cmd(
263+
'chmod +x %s',
264+
$this->variables['PHAR_PATH']
265+
) )->run_check();
266+
}
267+
242268
private function set_cache_dir() {
243269
$path = sys_get_temp_dir() . '/wp-cli-test-cache';
244270
$this->proc( Utils\esc_cmd( 'mkdir -p %s', $path ) )->run_check();
245271
$this->variables['CACHE_DIR'] = $path;
246272
}
247273

248274
private static function run_sql( $sql ) {
249-
Utils\run_mysql_command( 'mysql --no-defaults', array(
275+
Utils\run_mysql_command( '/usr/bin/env mysql --no-defaults', array(
250276
'execute' => $sql,
251277
'host' => self::$db_settings['dbhost'],
252278
'user' => self::$db_settings['dbuser'],

features/bootstrap/support.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ function checkThatCsvStringContainsValues( $actualCSV, $expectedCSV ) {
182182
* @param[in] $expectedYaml the expected YAML string
183183
*/
184184
function checkThatYamlStringContainsYamlString( $actualYaml, $expectedYaml ) {
185-
$actualValue = spyc_load( $actualYaml );
186-
$expectedValue = spyc_load( $expectedYaml );
185+
$actualValue = Mustangostang\Spyc::YAMLLoad( $actualYaml );
186+
$expectedValue = Mustangostang\Spyc::YAMLLoad( $expectedYaml );
187187

188188
if ( !$actualValue ) {
189189
return false;

features/bootstrap/utils.php

Lines changed: 131 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
use \WP_CLI\Dispatcher;
1111
use \WP_CLI\Iterators\Transform;
1212

13+
const PHAR_STREAM_PREFIX = 'phar://';
14+
1315
function inside_phar() {
14-
return 0 === strpos( WP_CLI_ROOT, 'phar://' );
16+
return 0 === strpos( WP_CLI_ROOT, PHAR_STREAM_PREFIX );
1517
}
1618

1719
// Files that need to be read by external programs have to be extracted from the Phar archive.
@@ -87,19 +89,6 @@ function load_command( $name ) {
8789
}
8890
}
8991

90-
function load_all_commands() {
91-
$cmd_dir = WP_CLI_ROOT . '/php/commands';
92-
93-
$iterator = new \DirectoryIterator( $cmd_dir );
94-
95-
foreach ( $iterator as $filename ) {
96-
if ( '.php' != substr( $filename, -4 ) )
97-
continue;
98-
99-
include_once "$cmd_dir/$filename";
100-
}
101-
}
102-
10392
/**
10493
* Like array_map(), except it returns a new iterator, instead of a modified array.
10594
*
@@ -197,10 +186,15 @@ function assoc_args_to_str( $assoc_args ) {
197186
$str = '';
198187

199188
foreach ( $assoc_args as $key => $value ) {
200-
if ( true === $value )
189+
if ( true === $value ) {
201190
$str .= " --$key";
202-
else
191+
} elseif( is_array( $value ) ) {
192+
foreach( $value as $_ => $v ) {
193+
$str .= assoc_args_to_str( array( $key => $v ) );
194+
}
195+
} else {
203196
$str .= " --$key=" . escapeshellarg( $value );
197+
}
204198
}
205199

206200
return $str;
@@ -453,6 +447,19 @@ function run_mysql_command( $cmd, $assoc_args, $descriptors = null ) {
453447
* IMPORTANT: Automatic HTML escaping is disabled!
454448
*/
455449
function mustache_render( $template_name, $data = array() ) {
450+
// Transform absolute path to relative path inside of Phar
451+
if ( inside_phar() && 0 === stripos( $template_name, PHAR_STREAM_PREFIX ) ) {
452+
$search = '';
453+
$replace = '';
454+
if ( file_exists( WP_CLI_ROOT . '/vendor/autoload.php' ) ) {
455+
$search = dirname( __DIR__ );
456+
$replace = WP_CLI_ROOT;
457+
} elseif ( file_exists( dirname( dirname( WP_CLI_ROOT ) ) . '/autoload.php' ) ) {
458+
$search = dirname( dirname( dirname( __DIR__ ) ) );
459+
$replace = dirname( dirname( dirname( WP_CLI_ROOT ) ) );
460+
}
461+
$template_name = str_replace( $search, $replace, $template_name );
462+
}
456463
if ( ! file_exists( $template_name ) )
457464
$template_name = WP_CLI_ROOT . "/templates/$template_name";
458465

@@ -840,3 +847,111 @@ function parse_str_to_argv( $arguments ) {
840847
function basename( $path, $suffix = '' ) {
841848
return urldecode( \basename( str_replace( array( '%2F', '%5C' ), '/', urlencode( $path ) ), $suffix ) );
842849
}
850+
851+
/**
852+
* Checks whether the output of the current script is a TTY or a pipe / redirect
853+
*
854+
* Returns true if STDOUT output is being redirected to a pipe or a file; false is
855+
* output is being sent directly to the terminal.
856+
*
857+
* If an env variable SHELL_PIPE exists, returned result depends it's
858+
* value. Strings like 1, 0, yes, no, that validate to booleans are accepted.
859+
*
860+
* To enable ASCII formatting even when shell is piped, use the
861+
* ENV variable SHELL_PIPE=0
862+
*
863+
* @access public
864+
*
865+
* @return bool
866+
*/
867+
function isPiped() {
868+
$shellPipe = getenv('SHELL_PIPE');
869+
870+
if ($shellPipe !== false) {
871+
return filter_var($shellPipe, FILTER_VALIDATE_BOOLEAN);
872+
} else {
873+
return (function_exists('posix_isatty') && !posix_isatty(STDOUT));
874+
}
875+
}
876+
877+
/**
878+
* Expand within paths to their matching paths.
879+
*
880+
* Has no effect on paths which do not use glob patterns.
881+
*
882+
* @param string|array $paths Single path as a string, or an array of paths.
883+
* @param int $flags Flags to pass to glob.
884+
*
885+
* @return array Expanded paths.
886+
*/
887+
function expand_globs( $paths, $flags = GLOB_BRACE ) {
888+
$expanded = array();
889+
890+
foreach ( (array) $paths as $path ) {
891+
$matching = array( $path );
892+
893+
if ( preg_match( '/[' . preg_quote( '*?[]{}!', '/' ) . ']/', $path ) ) {
894+
$matching = glob( $path, $flags ) ?: array();
895+
}
896+
897+
$expanded = array_merge( $expanded, $matching );
898+
}
899+
900+
return array_unique( $expanded );
901+
}
902+
903+
/**
904+
* Get a Phar-safe version of a path.
905+
*
906+
* For paths inside a Phar, this strips the outer filesystem's location to
907+
* reduce the path to what it needs to be within the Phar archive.
908+
*
909+
* Use the __FILE__ or __DIR__ constants as a starting point.
910+
*
911+
* @param string $path An absolute path that might be within a Phar.
912+
*
913+
* @return string A Phar-safe version of the path.
914+
*/
915+
function phar_safe_path( $path ) {
916+
917+
if ( ! inside_phar() ) {
918+
return $path;
919+
}
920+
921+
return str_replace(
922+
PHAR_STREAM_PREFIX . WP_CLI_PHAR_PATH . '/',
923+
PHAR_STREAM_PREFIX,
924+
$path
925+
);
926+
}
927+
928+
/**
929+
* Check whether a given Command object is part of the bundled set of
930+
* commands.
931+
*
932+
* This function accepts both a fully qualified class name as a string as
933+
* well as an object that extends `WP_CLI\Dispatcher\CompositeCommand`.
934+
*
935+
* @param \WP_CLI\Dispatcher\CompositeCommand|string $command
936+
*
937+
* @return bool
938+
*/
939+
function is_bundled_command( $command ) {
940+
static $classes;
941+
942+
if ( null === $classes ) {
943+
$classes = array();
944+
$class_map = WP_CLI_VENDOR_DIR . '/composer/autoload_commands_classmap.php';
945+
if ( file_exists( WP_CLI_VENDOR_DIR . '/composer/') ) {
946+
$classes = include $class_map;
947+
}
948+
}
949+
950+
if ( is_object( $command ) ) {
951+
$command = get_class( $command );
952+
}
953+
954+
return is_string( $command )
955+
? array_key_exists( $command, $classes )
956+
: false;
957+
}

features/steps/given.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,18 @@ function ( $world, $stream, $output_filter, $key ) {
127127
}
128128
);
129129

130-
$steps->Given( '/^a new Phar(?: with version "([^"]+)")$/',
131-
function ( $world, $version ) {
130+
$steps->Given( '/^a new Phar with (?:the same version|version "([^"]+)")$/',
131+
function ( $world, $version = 'same' ) {
132132
$world->build_phar( $version );
133133
}
134134
);
135135

136+
$steps->Given( '/^a downloaded Phar with (?:the same version|version "([^"]+)")$/',
137+
function ( $world, $version = 'same' ) {
138+
$world->download_phar( $version );
139+
}
140+
);
141+
136142
$steps->Given( '/^save the (.+) file ([\'].+[^\'])?as \{(\w+)\}$/',
137143
function ( $world, $filepath, $output_filter, $key ) {
138144
$full_file = file_get_contents( $world->replace_variables( $filepath ) );

utils/behat-tags.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,25 @@ function version_tags( $prefix, $current, $operator = '<' ) {
3131
return $skip_tags;
3232
}
3333

34+
$wp_version_reqs = array();
35+
// Only apply @require-wp tags when WP_VERSION isn't 'latest' or 'nightly'
36+
// 'latest' and 'nightly' are expected to work with all features
37+
if ( ! in_array( getenv( 'WP_VERSION' ), array( 'latest', 'nightly', 'trunk' ), true ) ) {
38+
$wp_version_reqs = version_tags( 'require-wp', getenv( 'WP_VERSION' ), '<' );
39+
}
40+
3441
$skip_tags = array_merge(
35-
version_tags( 'require-wp', getenv( 'WP_VERSION' ), '<' ),
42+
$wp_version_reqs,
3643
version_tags( 'require-php', PHP_VERSION, '<' ),
3744
version_tags( 'less-than-php', PHP_VERSION, '>' )
3845
);
3946

4047
# Skip Github API tests by default because of rate limiting. See https://github.com/wp-cli/wp-cli/issues/1612
4148
$skip_tags[] = '@github-api';
4249

50+
# Skip tests known to be broken.
51+
$skip_tags[] = '@broken';
52+
4353
# Require PHP extension, eg 'imagick'.
4454
function extension_tags() {
4555
$extension_tags = array();

0 commit comments

Comments
 (0)