@@ -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 );
@@ -980,15 +992,15 @@ public function create_db() {
980992 }
981993
982994 $ dbname = self ::$ db_settings ['dbname ' ];
983- self ::run_sql ( ' mysql --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 " ] );
984996 }
985997
986998 public function drop_db () {
987999 if ( 'sqlite ' === self ::$ db_type ) {
9881000 return ;
9891001 }
9901002 $ dbname = self ::$ db_settings ['dbname ' ];
991- self ::run_sql ( ' mysql --no-defaults ' , [ 'execute ' => "DROP DATABASE IF EXISTS $ dbname " ] );
1003+ self ::run_sql ( self :: $ mysql_binary . ' --no-defaults ' , [ 'execute ' => "DROP DATABASE IF EXISTS $ dbname " ] );
9921004 }
9931005
9941006 public function proc ( $ command , $ assoc_args = [], $ path = '' ) {
@@ -1149,7 +1161,7 @@ public function install_wp( $subdir = '' ) {
11491161 // Disable WP Cron by default to avoid bogus HTTP requests in CLI context.
11501162 $ config_extra_php = "if ( ! defined( 'DISABLE_WP_CRON' ) ) { define( 'DISABLE_WP_CRON', true ); } \n" ;
11511163
1152- if ( 'mysql ' = == self ::$ db_type ) {
1164+ if ( 'sqlite ' ! == self ::$ db_type ) {
11531165 $ this ->create_db ();
11541166 }
11551167 $ this ->create_run_dir ();
@@ -1179,7 +1191,7 @@ public function install_wp( $subdir = '' ) {
11791191 if ( 'sqlite ' === self ::$ db_type ) {
11801192 copy ( "{$ install_cache_path }.sqlite " , "$ run_dir/wp-content/database/.ht.sqlite " );
11811193 } else {
1182- self ::run_sql ( ' mysql --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*/ );
11831195 }
11841196 } else {
11851197 $ this ->proc ( 'wp core install ' , $ install_args , $ subdir )->run_check ();
@@ -1189,8 +1201,9 @@ public function install_wp( $subdir = '' ) {
11891201
11901202 self ::dir_diff_copy ( $ run_dir , self ::$ cache_dir , $ install_cache_path );
11911203
1192- if ( 'mysql ' === self ::$ db_type ) {
1193- $ mysqldump_binary = Utils \force_env_on_nix_systems ( 'mysqldump ' );
1204+ if ( 'sqlite ' !== self ::$ db_type ) {
1205+ $ mysqldump_binary = Utils \get_sql_dump_command ();
1206+ $ mysqldump_binary = Utils \force_env_on_nix_systems ( $ mysqldump_binary );
11941207 $ support_column_statistics = exec ( "{$ mysqldump_binary } --help | grep 'column-statistics' " );
11951208 $ command = "{$ mysqldump_binary } --no-defaults --no-tablespaces " ;
11961209 if ( $ support_column_statistics ) {
0 commit comments