Skip to content

Commit a7bc939

Browse files
authored
Merge pull request #118 from wp-cli/fix/gracefully-handle-missing-db-credentials
Handle missing DB credentials gracefully
2 parents 6b6f201 + 7ec79e7 commit a7bc939

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/Context/FeatureContext.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,9 +510,17 @@ public function __construct() {
510510
$this->variables['MYSQL_HOST'] = getenv( 'MYSQL_HOST' );
511511
}
512512

513-
self::$db_settings['dbuser'] = $this->variables['DB_USER'];
514-
self::$db_settings['dbpass'] = $this->variables['DB_PASSWORD'];
515-
self::$db_settings['dbhost'] = $this->variables['DB_HOST'];
513+
self::$db_settings['dbuser'] = array_key_exists( 'DB_USER', $this->variables )
514+
? $this->variables['DB_USER']
515+
: 'wp_cli_test';
516+
517+
self::$db_settings['dbpass'] = array_key_exists( 'DB_PASSWORD', $this->variables )
518+
? $this->variables['DB_PASSWORD']
519+
: 'password1';
520+
521+
self::$db_settings['dbhost'] = array_key_exists( 'DB_HOST', $this->variables )
522+
? $this->variables['DB_HOST']
523+
: 'localhost';
516524

517525
$this->variables['CORE_CONFIG_SETTINGS'] = Utils\assoc_args_to_str( self::$db_settings );
518526

0 commit comments

Comments
 (0)