From 1cb3cf995c66e98852ec44b7efb519f07d71ea19 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Wed, 3 Feb 2016 14:21:59 -0800 Subject: [PATCH 1/2] Reintroduce autoload so that `wp package` can load the command --- composer.json | 3 +++ features/bootstrap/FeatureContext.php | 16 +++++++++++++--- wp-cli.yml | 2 -- 3 files changed, 16 insertions(+), 5 deletions(-) delete mode 100644 wp-cli.yml diff --git a/composer.json b/composer.json index 958af5a..a3dab83 100644 --- a/composer.json +++ b/composer.json @@ -9,6 +9,9 @@ } ], "minimum-stability": "dev", + "autoload": { + "files": [ "wp-rest-cli.php" ] + }, "require": {}, "require-dev": { "behat/behat": "~2.5" diff --git a/features/bootstrap/FeatureContext.php b/features/bootstrap/FeatureContext.php index f693ddc..16e8227 100644 --- a/features/bootstrap/FeatureContext.php +++ b/features/bootstrap/FeatureContext.php @@ -11,9 +11,19 @@ if ( file_exists( __DIR__ . '/utils.php' ) ) { require_once __DIR__ . '/utils.php'; require_once __DIR__ . '/Process.php'; - $project_config = dirname( dirname( dirname( __FILE__ ) ) ) . '/wp-cli.yml'; - if ( file_exists( $project_config ) && ! getenv( 'WP_CLI_CONFIG_PATH' ) ) { - putenv( 'WP_CLI_CONFIG_PATH=' . $project_config ); + $project_composer = dirname( dirname( dirname( __FILE__ ) ) ) . '/composer.json'; + if ( file_exists( $project_composer ) ) { + $composer = json_decode( file_get_contents( $project_composer ) ); + if ( ! empty( $composer->autoload->files ) ) { + $contents = 'require:' . PHP_EOL; + foreach( $composer->autoload->files as $file ) { + $contents .= ' - ' . dirname( dirname( dirname( __FILE__ ) ) ) . '/' . $file; + } + mkdir( sys_get_temp_dir() . '/wp-cli-package-test/' ); + $project_config = sys_get_temp_dir() . '/wp-cli-package-test/config.yml'; + file_put_contents( $project_config, $contents ); + putenv( 'WP_CLI_CONFIG_PATH=' . $project_config ); + } } // Inside WP-CLI } else { diff --git a/wp-cli.yml b/wp-cli.yml deleted file mode 100644 index f551138..0000000 --- a/wp-cli.yml +++ /dev/null @@ -1,2 +0,0 @@ -require: - - wp-rest-cli.php From a941ff0fccbca7072da6c93ca8d9880ddce350a4 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Wed, 3 Feb 2016 14:38:10 -0800 Subject: [PATCH 2/2] Wrap in a conditional so test suite doesn't load it. --- wp-rest-cli.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/wp-rest-cli.php b/wp-rest-cli.php index cabb906..50e2485 100644 --- a/wp-rest-cli.php +++ b/wp-rest-cli.php @@ -6,6 +6,7 @@ require_once __DIR__ . '/inc/RestCommand.php'; require_once __DIR__ . '/inc/Runner.php'; -\WP_REST_CLI\Runner::load_remote_commands(); -WP_CLI::add_hook( 'after_wp_load', '\WP_REST_CLI\Runner::after_wp_load' ); - +if ( class_exists( 'WP_CLI' ) ) { + \WP_REST_CLI\Runner::load_remote_commands(); + WP_CLI::add_hook( 'after_wp_load', '\WP_REST_CLI\Runner::after_wp_load' ); +}