Skip to content

Commit a80d5e0

Browse files
Merge pull request #8 from wp-cli/update-testing-framework
Update testing framework.
2 parents 7d2c1dc + 6822f51 commit a80d5e0

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

features/bootstrap/FeatureContext.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,10 @@ class FeatureContext extends BehatContext implements ClosuredContextInterface {
5959
*/
6060
private static function get_process_env_variables() {
6161
// Ensure we're using the expected `wp` binary
62-
$bin_dir = getenv( 'WP_CLI_BIN_DIR' ) ?: realpath( __DIR__ . "/../../bin" );
62+
$bin_dir = getenv( 'WP_CLI_BIN_DIR' ) ?: realpath( __DIR__ . '/../../bin' );
63+
$vendor_dir = realpath( __DIR__ . '/../../vendor/bin' );
6364
$env = array(
64-
'PATH' => $bin_dir . ':' . getenv( 'PATH' ),
65+
'PATH' => $bin_dir . ':' . $vendor_dir . ':' . getenv( 'PATH' ),
6566
'BEHAT_RUN' => 1,
6667
'HOME' => '/tmp/wp-cli-home',
6768
);
@@ -218,9 +219,21 @@ public function create_run_dir() {
218219
public function build_phar( $version = 'same' ) {
219220
$this->variables['PHAR_PATH'] = $this->variables['RUN_DIR'] . '/' . uniqid( "wp-cli-build-", TRUE ) . '.phar';
220221

222+
// Test running against WP-CLI proper
223+
$make_phar_path = __DIR__ . '/../../utils/make-phar.php';
224+
if ( ! file_exists( $make_phar_path ) ) {
225+
// Test running against a package installed as a WP-CLI dependency
226+
// WP-CLI installed as a project dependency
227+
$make_phar_path = __DIR__ . '/../../../../../utils/make-phar.php';
228+
if ( ! file_exists( $make_phar_path ) ) {
229+
// WP-CLI as a dependency of this project
230+
$make_phar_path = __DIR__ . '/../../vendor/wp-cli/wp-cli/utils/make-phar.php';
231+
}
232+
}
233+
221234
$this->proc( Utils\esc_cmd(
222235
'php -dphar.readonly=0 %1$s %2$s --version=%3$s && chmod +x %2$s',
223-
__DIR__ . '/../../utils/make-phar.php',
236+
$make_phar_path,
224237
$this->variables['PHAR_PATH'],
225238
$version
226239
) )->run_check();

features/bootstrap/utils.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ function extract_from_phar( $path ) {
3535

3636
function load_dependencies() {
3737
if ( inside_phar() ) {
38-
require WP_CLI_ROOT . '/vendor/autoload.php';
38+
if ( file_exists( WP_CLI_ROOT . '/vendor/autoload.php' ) ) {
39+
require WP_CLI_ROOT . '/vendor/autoload.php';
40+
} elseif ( file_exists( dirname( dirname( WP_CLI_ROOT ) ) . '/autoload.php' ) ) {
41+
require dirname( dirname( WP_CLI_ROOT ) ) . '/autoload.php';
42+
}
3943
return;
4044
}
4145

utils/behat-tags.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,26 @@ function version_tags( $prefix, $current, $operator = '<' ) {
4040
# Skip Github API tests by default because of rate limiting. See https://github.com/wp-cli/wp-cli/issues/1612
4141
$skip_tags[] = '@github-api';
4242

43+
# Require PHP extension, eg 'imagick'.
44+
function extension_tags() {
45+
$extension_tags = array();
46+
exec( "grep '@require-extension-[A-Za-z_]*' -h -o features/*.feature | uniq", $extension_tags );
47+
48+
$skip_tags = array();
49+
50+
$substr_start = strlen( '@require-extension-' );
51+
foreach ( $extension_tags as $tag ) {
52+
$extension = substr( $tag, $substr_start );
53+
if ( ! extension_loaded( $extension ) ) {
54+
$skip_tags[] = $tag;
55+
}
56+
}
57+
58+
return $skip_tags;
59+
}
60+
61+
$skip_tags = array_merge( $skip_tags, extension_tags() );
62+
4363
if ( !empty( $skip_tags ) ) {
4464
echo '--tags=~' . implode( '&&~', $skip_tags );
4565
}

0 commit comments

Comments
 (0)