@@ -92,6 +92,11 @@ class FeatureContext implements SnippetAcceptingContext {
9292 */
9393 private static $ db_type = 'mysql ' ;
9494
95+ /**
96+ * Name of mysql binary to use (mysql or mariadb). Default to mysql
97+ */
98+ private static $ mysql_binary = 'mysql ' ;
99+
95100 /**
96101 * Array of background process ids started by the current scenario. Used to terminate them at the end of the scenario.
97102 */
@@ -552,6 +557,7 @@ public static function prepare( BeforeSuiteScope $scope ) {
552557 self ::log_run_times_before_suite ( $ scope );
553558 }
554559 self ::$ behat_run_dir = getcwd ();
560+ self ::$ mysql_binary = Utils \get_mysql_binary_path ();
555561
556562 $ result = Process::create ( 'wp cli info ' , null , self ::get_process_env_variables () )->run_check ();
557563 echo "{$ result ->stdout }\n" ;
@@ -603,6 +609,12 @@ public function beforeScenario( BeforeScenarioScope $scope ) {
603609 self ::get_behat_internal_variables ()
604610 );
605611
612+ $ mysql_binary = Utils \get_mysql_binary_path ();
613+ $ sql_dump_command = Utils \get_sql_dump_command ();
614+
615+ $ this ->variables ['MYSQL_BINARY ' ] = $ mysql_binary ;
616+ $ this ->variables ['SQL_DUMP_COMMAND ' ] = $ sql_dump_command ;
617+
606618 // Used in the names of the RUN_DIR and SUITE_CACHE_DIR directories.
607619 self ::$ temp_dir_infix = null ;
608620 $ file = self ::get_event_file ( $ scope , $ line );
@@ -959,9 +971,6 @@ private function set_cache_dir() {
959971 * @param bool $add_database Optional. Whether to add dbname to the $sql_cmd. Default false.
960972 */
961973 private static function run_sql ( $ sql_cmd , $ assoc_args = [], $ add_database = false ) {
962- $ binary = 'mariadb ' === Utils \get_db_type () ? 'mariadb ' : 'mysql ' ;
963- $ sql_cmd = "$ binary $ sql_cmd " ;
964-
965974 $ default_assoc_args = [
966975 'host ' => self ::$ db_settings ['dbhost ' ],
967976 'user ' => self ::$ db_settings ['dbuser ' ],
@@ -983,15 +992,15 @@ public function create_db() {
983992 }
984993
985994 $ dbname = self ::$ db_settings ['dbname ' ];
986- self ::run_sql ( ' --no-defaults ' , [ 'execute ' => "CREATE DATABASE IF NOT EXISTS $ dbname " ] );
995+ self ::run_sql ( self :: $ mysql_binary . ' --no-defaults ' , [ 'execute ' => "CREATE DATABASE IF NOT EXISTS $ dbname " ] );
987996 }
988997
989998 public function drop_db () {
990999 if ( 'sqlite ' === self ::$ db_type ) {
9911000 return ;
9921001 }
9931002 $ dbname = self ::$ db_settings ['dbname ' ];
994- self ::run_sql ( ' --no-defaults ' , [ 'execute ' => "DROP DATABASE IF EXISTS $ dbname " ] );
1003+ self ::run_sql ( self :: $ mysql_binary . ' --no-defaults ' , [ 'execute ' => "DROP DATABASE IF EXISTS $ dbname " ] );
9951004 }
9961005
9971006 public function proc ( $ command , $ assoc_args = [], $ path = '' ) {
@@ -1182,7 +1191,7 @@ public function install_wp( $subdir = '' ) {
11821191 if ( 'sqlite ' === self ::$ db_type ) {
11831192 copy ( "{$ install_cache_path }.sqlite " , "$ run_dir/wp-content/database/.ht.sqlite " );
11841193 } else {
1185- self ::run_sql ( ' --no-defaults ' , [ 'execute ' => "source {$ install_cache_path }.sql " ], true /*add_database*/ );
1194+ self ::run_sql ( self :: $ mysql_binary . ' --no-defaults ' , [ 'execute ' => "source {$ install_cache_path }.sql " ], true /*add_database*/ );
11861195 }
11871196 } else {
11881197 $ this ->proc ( 'wp core install ' , $ install_args , $ subdir )->run_check ();
@@ -1193,7 +1202,7 @@ public function install_wp( $subdir = '' ) {
11931202 self ::dir_diff_copy ( $ run_dir , self ::$ cache_dir , $ install_cache_path );
11941203
11951204 if ( 'sqlite ' !== self ::$ db_type ) {
1196- $ mysqldump_binary = ' mariadb ' === Utils \get_db_type () ? ' mariadb-dump ' : ' mysqldump ' ;
1205+ $ mysqldump_binary = Utils \get_sql_dump_command () ;
11971206 $ mysqldump_binary = Utils \force_env_on_nix_systems ( $ mysqldump_binary );
11981207 $ support_column_statistics = exec ( "{$ mysqldump_binary } --help | grep 'column-statistics' " );
11991208 $ command = "{$ mysqldump_binary } --no-defaults --no-tablespaces " ;
0 commit comments