From eaa0c3ac0454fd27ad27cf83482048ab7894f3ed Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Sat, 21 Oct 2017 14:13:37 +0000 Subject: [PATCH] Tests: Return an exit code of 1 in the event that the database server for tests is unavailable. This allows for automated scripts & test suites to handle the failure of the test suite easier. Props danielbachhuber Fixes #41916 git-svn-id: https://develop.svn.wordpress.org/trunk@41966 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/includes/bootstrap.php | 5 ++++- tests/phpunit/includes/functions.php | 17 +++++++++++++++++ tests/phpunit/includes/install.php | 2 ++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/includes/bootstrap.php b/tests/phpunit/includes/bootstrap.php index 2bb428d74c..f93d6bee89 100644 --- a/tests/phpunit/includes/bootstrap.php +++ b/tests/phpunit/includes/bootstrap.php @@ -65,7 +65,10 @@ if ( ! defined( 'WP_DEFAULT_THEME' ) ) { } $wp_theme_directories = array( DIR_TESTDATA . '/themedir1' ); -system( WP_PHP_BINARY . ' ' . escapeshellarg( dirname( __FILE__ ) . '/install.php' ) . ' ' . escapeshellarg( $config_file_path ) . ' ' . $multisite ); +system( WP_PHP_BINARY . ' ' . escapeshellarg( dirname( __FILE__ ) . '/install.php' ) . ' ' . escapeshellarg( $config_file_path ) . ' ' . $multisite, $retval ); +if ( 0 !== $retval ) { + exit( $retval ); +} if ( $multisite ) { echo "Running as multisite..." . PHP_EOL; diff --git a/tests/phpunit/includes/functions.php b/tests/phpunit/includes/functions.php index d9872fb541..928fcd912f 100644 --- a/tests/phpunit/includes/functions.php +++ b/tests/phpunit/includes/functions.php @@ -115,6 +115,10 @@ function _wp_die_handler_filter() { return '_wp_die_handler'; } +function _wp_die_handler_filter_exit() { + return '_wp_die_handler_exit'; +} + function _wp_die_handler_txt( $message, $title, $args ) { echo "\nwp_die called\n"; echo "Message : $message\n"; @@ -127,6 +131,19 @@ function _wp_die_handler_txt( $message, $title, $args ) { } } +function _wp_die_handler_exit( $message, $title, $args ) { + echo "\nwp_die called\n"; + echo "Message : $message\n"; + echo "Title : $title\n"; + if ( ! empty( $args ) ) { + echo "Args: \n"; + foreach( $args as $k => $v ){ + echo "\t $k : $v\n"; + } + } + exit( 1 ); +} + /** * Set a permalink structure. * diff --git a/tests/phpunit/includes/install.php b/tests/phpunit/includes/install.php index 38db3ce55a..7317f4e3ef 100644 --- a/tests/phpunit/includes/install.php +++ b/tests/phpunit/includes/install.php @@ -22,6 +22,8 @@ tests_reset__SERVER(); $PHP_SELF = $GLOBALS['PHP_SELF'] = $_SERVER['PHP_SELF'] = '/index.php'; +tests_add_filter( 'wp_die_handler', '_wp_die_handler_filter_exit' ); + require_once ABSPATH . '/wp-settings.php'; require_once ABSPATH . '/wp-admin/includes/upgrade.php';