Skip to content

Commit 8b064c7

Browse files
authored
Merge pull request #6069 from wp-cli/fix/override-test
Fix unstable package override tests
2 parents aadb773 + 5444e22 commit 8b064c7

File tree

2 files changed

+36
-18
lines changed

2 files changed

+36
-18
lines changed

features/bootstrap.feature

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ Feature: Bootstrap WP-CLI
6060
return;
6161
}
6262
// Override bundled command.
63-
WP_CLI::add_command( 'eval', 'Eval_Command', array( 'when' => 'before_wp_load' ) );
63+
WP_CLI::add_command( 'eval', 'Custom_Eval_Command', array( 'when' => 'before_wp_load' ) );
6464
"""
65-
And a override/src/Eval_Command.php file:
65+
And a override/src/Custom_Eval_Command.php file:
6666
"""
6767
<?php
68-
class Eval_Command extends WP_CLI_Command {
68+
class Custom_Eval_Command extends WP_CLI_Command {
6969
public function __invoke() {
7070
WP_CLI::success( "WP-Override-Eval" );
7171
}
@@ -105,27 +105,36 @@ Feature: Bootstrap WP-CLI
105105
return;
106106
}
107107
$autoload = dirname( __FILE__ ) . '/vendor/autoload.php';
108-
if ( file_exists( $autoload ) && ! class_exists( 'CLI_Command' ) ) {
108+
if ( file_exists( $autoload ) && ! class_exists( 'Custom_CLI_Command' ) ) {
109109
require_once $autoload;
110110
}
111111
// Override framework command.
112-
WP_CLI::add_command( 'cli', 'CLI_Command', array( 'when' => 'before_wp_load' ) );
112+
WP_CLI::add_command( 'cli', 'Custom_CLI_Command', array( 'when' => 'before_wp_load' ) );
113113
// Override bundled command.
114-
WP_CLI::add_command( 'eval', 'Eval_Command', array( 'when' => 'before_wp_load' ) );
114+
WP_CLI::add_hook(
115+
'after_add_command:eval',
116+
static function () {
117+
static $added = false;
118+
if ( ! $added ) {
119+
$added = true;
120+
WP_CLI::add_command( 'eval', 'Custom_Eval_Command', array( 'when' => 'before_wp_load' ) );
121+
}
122+
}
123+
);
115124
"""
116-
And a override/src/CLI_Command.php file:
125+
And a override/src/Custom_CLI_Command.php file:
117126
"""
118127
<?php
119-
class CLI_Command extends WP_CLI_Command {
128+
class Custom_CLI_Command extends WP_CLI_Command {
120129
public function version() {
121130
WP_CLI::success( "WP-Override-CLI" );
122131
}
123132
}
124133
"""
125-
And a override/src/Eval_Command.php file:
134+
And a override/src/Custom_Eval_Command.php file:
126135
"""
127136
<?php
128-
class Eval_Command extends WP_CLI_Command {
137+
class Custom_Eval_Command extends WP_CLI_Command {
129138
public function __invoke() {
130139
WP_CLI::success( "WP-Override-Eval" );
131140
}
@@ -184,27 +193,36 @@ Feature: Bootstrap WP-CLI
184193
return;
185194
}
186195
$autoload = dirname( __FILE__ ) . '/vendor/autoload.php';
187-
if ( file_exists( $autoload ) && ! class_exists( 'CLI_Command' ) ) {
196+
if ( file_exists( $autoload ) && ! class_exists( 'Custom_CLI_Command' ) ) {
188197
require_once $autoload;
189198
}
190199
// Override framework command.
191-
WP_CLI::add_command( 'cli', 'CLI_Command', array( 'when' => 'before_wp_load' ) );
200+
WP_CLI::add_command( 'cli', 'Custom_CLI_Command', array( 'when' => 'before_wp_load' ) );
192201
// Override bundled command.
193-
WP_CLI::add_command( 'eval', 'Eval_Command', array( 'when' => 'before_wp_load' ) );
202+
WP_CLI::add_hook(
203+
'after_add_command:eval',
204+
static function () {
205+
static $added = false;
206+
if ( ! $added ) {
207+
$added = true;
208+
WP_CLI::add_command( 'eval', 'Custom_Eval_Command', array( 'when' => 'before_wp_load' ) );
209+
}
210+
}
211+
);
194212
"""
195-
And a override/src/CLI_Command.php file:
213+
And a override/src/Custom_CLI_Command.php file:
196214
"""
197215
<?php
198-
class CLI_Command extends WP_CLI_Command {
216+
class Custom_CLI_Command extends WP_CLI_Command {
199217
public function version() {
200218
WP_CLI::success( "WP-Override-CLI" );
201219
}
202220
}
203221
"""
204-
And a override/src/Eval_Command.php file:
222+
And a override/src/Custom_Eval_Command.php file:
205223
"""
206224
<?php
207-
class Eval_Command extends WP_CLI_Command {
225+
class Custom_Eval_Command extends WP_CLI_Command {
208226
public function __invoke() {
209227
WP_CLI::success( "WP-Override-Eval" );
210228
}

features/utils.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ Feature: Utilities that do NOT depend on WordPress code
161161
Then save STDOUT as {SKIP_COLUMN_STATISTICS_FLAG}
162162
163163
# This throws a warning because of the password.
164-
When I try `{INVOKE_WP_CLI_WITH_PHP_ARGS--dmemory_limit=50M -ddisable_functions=ini_set} eval '\WP_CLI\Utils\run_mysql_command("/usr/bin/env {SQL_DUMP_COMMAND} {SKIP_COLUMN_STATISTICS_FLAG} --no-tablespaces {DB_NAME}", [ "user" => "{DB_USER}", "pass" => "{DB_PASSWORD}", "host" => "{DB_HOST}" ], null, true);'`
164+
When I try `{INVOKE_WP_CLI_WITH_PHP_ARGS--dmemory_limit=256M -ddisable_functions=ini_set} eval '\WP_CLI\Utils\run_mysql_command("/usr/bin/env {SQL_DUMP_COMMAND} {SKIP_COLUMN_STATISTICS_FLAG} --no-tablespaces {DB_NAME}", [ "user" => "{DB_USER}", "pass" => "{DB_PASSWORD}", "host" => "{DB_HOST}" ], null, true);'`
165165
Then the return code should be 0
166166
And STDOUT should not be empty
167167
And STDOUT should contain:

0 commit comments

Comments
 (0)