From 981542f3d8ca0f18fa8431252c7b1976487a13ce Mon Sep 17 00:00:00 2001 From: scribu Date: Fri, 5 Apr 2013 22:05:15 +0300 Subject: [PATCH] use run_mysql_query() in functional tests too --- features/bootstrap/FeatureContext.php | 19 +++++++++++-------- php/utils.php | 4 +++- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/features/bootstrap/FeatureContext.php b/features/bootstrap/FeatureContext.php index d70fd2be..07038d3e 100644 --- a/features/bootstrap/FeatureContext.php +++ b/features/bootstrap/FeatureContext.php @@ -5,6 +5,8 @@ use Behat\Behat\Context\ClosuredContextInterface, Behat\Behat\Context\BehatContext, Behat\Behat\Event\SuiteEvent; +use \WP_CLI\Utils; + require_once 'PHPUnit/Framework/Assert/Functions.php'; require_once __DIR__ . '/../../php/utils.php'; @@ -92,21 +94,22 @@ class FeatureContext extends BehatContext implements ClosuredContextInterface { if ( !$path ) { $path = sys_get_temp_dir() . '/wp-cli-test-cache'; - system( \WP_CLI\Utils\create_cmd( 'mkdir -p %s', $path ) ); + system( Utils\create_cmd( 'mkdir -p %s', $path ) ); } return $path . '/' . $file; } public function download_file( $url, $path ) { - system( \WP_CLI\Utils\create_cmd( 'curl -sSL %s > %s', $url, $path ) ); + system( Utils\create_cmd( 'curl -sSL %s > %s', $url, $path ) ); } private static function run_sql( $sql ) { - putenv( 'MYSQL_PWD=' . self::$db_settings['dbpass'] ); - - system( \WP_CLI\Utils\create_cmd( 'mysql -u%s -e %s', - self::$db_settings['dbuser'], $sql ) ); + Utils\run_mysql_query( $sql, array( + 'host' => 'localhost', + 'user' => self::$db_settings['dbuser'], + 'pass' => self::$db_settings['dbpass'], + ) ); } public function create_db() { @@ -121,7 +124,7 @@ class FeatureContext extends BehatContext implements ClosuredContextInterface { private function _run( $command, $assoc_args, $subdir = '' ) { if ( !empty( $assoc_args ) ) - $command .= \WP_CLI\Utils\assoc_args_to_str( $assoc_args ); + $command .= Utils\assoc_args_to_str( $assoc_args ); $subdir = $this->get_path( $subdir ); @@ -184,7 +187,7 @@ class FeatureContext extends BehatContext implements ClosuredContextInterface { if ( $subdir ) mkdir( $dest_dir ); - $cmd = \WP_CLI\Utils\create_cmd( "cp -r %s/* %s", $cache_dir, $dest_dir ); + $cmd = Utils\create_cmd( "cp -r %s/* %s", $cache_dir, $dest_dir ); system( $cmd ); } diff --git a/php/utils.php b/php/utils.php index 73e89b9e..51f25b54 100644 --- a/php/utils.php +++ b/php/utils.php @@ -377,7 +377,9 @@ function run_mysql_command( $cmd, $arg_str, $pass ) { $final_cmd = "$cmd --defaults-file=/dev/null $arg_str"; putenv( 'MYSQL_PWD=' . $pass ); - \WP_CLI::launch( $final_cmd ); + $r = proc_close( proc_open( $final_cmd, array( STDIN, STDOUT, STDERR ), $pipes ) ); putenv( 'MYSQL_PWD=' . $old_val ); + + if ( $r ) exit( $r ); } -- 2.11.0