@@ -688,21 +688,52 @@ Feature: WP-CLI Commands
688688 Scenario : Override command bundled with current source
689689
690690 Given an empty directory
691- And a cli-override.php file:
691+ And a cli-command- override/cli .php file:
692692 """
693693 <?php
694- WP_CLI::add_command( 'cli', function(){
695- WP_CLI::success( "WP-Override-CLI" );
696- }, array( 'when' => 'before_wp_load' ) );
694+ if ( ! class_exists( 'WP_CLI' ) ) {
695+ return;
696+ }
697+ $autoload = dirname( __FILE__ ) . '/vendor/autoload.php';
698+ if ( file_exists( $autoload ) ) {
699+ require_once $autoload;
700+ }
701+ WP_CLI::add_command( 'cli', 'CLI_Command', array( 'when' => 'before_wp_load' ) );
702+ """
703+ And a cli-command-override/src/CLI_Command.php file:
704+ """
705+ <?php
706+ class CLI_Command extends WP_CLI_Command {
707+ public function version() {
708+ WP_CLI::success( "WP-Override-CLI" );
709+ }
710+ }
697711 """
712+ And a cli-command-override/composer.json file:
713+ """
714+ {
715+ "name": "wp-cli/cli-override",
716+ "description": "A command that overrides the bundled 'cli' command.",
717+ "autoload": {
718+ "psr-4": { "": "src/" },
719+ "files": [ "cli.php" ]
720+ },
721+ "extra": {
722+ "commands": [
723+ "cli"
724+ ]
725+ }
726+ }
727+ """
728+ And I run `composer install --working-dir={RUN_DIR}/cli-command-override --no-interaction`
698729
699730 When I run `wp cli version`
700731 Then STDOUT should contain:
701732 """
702733 WP-CLI
703734 """
704735
705- When I run `wp --require=cli-override.php cli version`
736+ When I run `wp --require=cli-command- override/cli .php cli version`
706737 Then STDOUT should contain:
707738 """
708739 WP-Override-CLI
@@ -713,21 +744,52 @@ Feature: WP-CLI Commands
713744
714745 Given an empty directory
715746 And a new Phar
716- And a cli-override.php file:
747+ And a cli-command-override/cli.php file:
748+ """
749+ <?php
750+ if ( ! class_exists( 'WP_CLI' ) ) {
751+ return;
752+ }
753+ $autoload = dirname( __FILE__ ) . '/vendor/autoload.php';
754+ if ( file_exists( $autoload ) ) {
755+ require_once $autoload;
756+ }
757+ WP_CLI::add_command( 'cli', 'CLI_Command', array( 'when' => 'before_wp_load' ) );
758+ """
759+ And a cli-command-override/src/CLI_Command.php file:
717760 """
718761 <?php
719- WP_CLI::add_command( 'cli', function(){
720- WP_CLI::success( "WP-Override-CLI" );
721- }, array( 'when' => 'before_wp_load' ) );
762+ class CLI_Command extends WP_CLI_Command {
763+ public function version() {
764+ WP_CLI::success( "WP-Override-CLI" );
765+ }
766+ }
767+ """
768+ And a cli-command-override/composer.json file:
722769 """
770+ {
771+ "name": "wp-cli/cli-override",
772+ "description": "A command that overrides the bundled 'cli' command.",
773+ "autoload": {
774+ "psr-4": { "": "src/" },
775+ "files": [ "cli.php" ]
776+ },
777+ "extra": {
778+ "commands": [
779+ "cli"
780+ ]
781+ }
782+ }
783+ """
784+ And I run `composer install --working-dir={RUN_DIR}/cli-command-override --no-interaction`
723785
724786 When I run `{PHAR_PATH} cli version`
725787 Then STDOUT should contain:
726788 """
727789 WP-CLI
728790 """
729791
730- When I run `{PHAR_PATH} --require=cli-override.php cli version`
792+ When I run `{PHAR_PATH} --require=cli-command- override/cli .php cli version`
731793 Then STDOUT should contain:
732794 """
733795 WP-Override-CLI
@@ -738,56 +800,52 @@ Feature: WP-CLI Commands
738800
739801 Given an empty directory
740802 And a downloaded Phar with version "1.0.0"
741- And a cli-override.php file:
803+ And a cli-command- override/cli .php file:
742804 """
743805 <?php
744- WP_CLI::add_command( 'cli', function(){
745- WP_CLI::success( "WP-Override-CLI" );
746- }, array( 'when' => 'before_wp_load' ) );
806+ if ( ! class_exists( 'WP_CLI' ) ) {
807+ return;
808+ }
809+ $autoload = dirname( __FILE__ ) . '/vendor/autoload.php';
810+ if ( file_exists( $autoload ) ) {
811+ require_once $autoload;
812+ }
813+ WP_CLI::add_command( 'cli', 'CLI_Command', array( 'when' => 'before_wp_load' ) );
747814 """
748-
749- When I run `{PHAR_PATH} cli version`
750- Then STDOUT should contain:
751- """
752- WP-CLI 1.0.0
753- """
754-
755- When I run `{PHAR_PATH} --require=cli-override.php cli version`
756- Then STDOUT should contain:
757- """
758- WP-Override-CLI
759- """
760-
761- @bootstrap
762- Scenario : Override command bundled with Composer stack
763-
764- Given an empty directory
765- And a composer.json file:
815+ And a cli-command-override/src/CLI_Command.php file:
766816 """
767- {
768- "name": "wp-cli/composer-test",
769- "type": "project",
770- "require": {
771- "wp-cli/wp-cli": "1.1.0"
772- }
817+ <?php
818+ class CLI_Command extends WP_CLI_Command {
819+ public function version() {
820+ WP_CLI::success( "WP-Override-CLI" );
821+ }
773822 }
774823 """
775- And a cli-override.php file:
824+ And a cli-command- override/composer.json file:
776825 """
777- <?php
778- WP_CLI::add_command( 'cli', function(){
779- WP_CLI::success( "WP-Override-CLI" );
780- }, array( 'when' => 'before_wp_load' ) );
826+ {
827+ "name": "wp-cli/cli-override",
828+ "description": "A command that overrides the bundled 'cli' command.",
829+ "autoload": {
830+ "psr-4": { "": "src/" },
831+ "files": [ "cli.php" ]
832+ },
833+ "extra": {
834+ "commands": [
835+ "cli"
836+ ]
837+ }
838+ }
781839 """
782- And I run `composer install --no-interaction`
840+ And I run `composer install --working-dir={RUN_DIR}/cli-command-override -- no-interaction`
783841
784- When I run `vendor/bin/wp cli version`
842+ When I run `{PHAR_PATH} cli version`
785843 Then STDOUT should contain:
786844 """
787- WP-CLI 1.1 .0
845+ WP-CLI 1.0 .0
788846 """
789847
790- When I run `vendor/bin/wp --require=cli-override.php cli version`
848+ When I run `{PHAR_PATH} --require=cli-command- override/cli .php cli version`
791849 Then STDOUT should contain:
792850 """
793851 WP-Override-CLI
0 commit comments