Skip to content

Commit b961099

Browse files
Update scaffolded tests to enable error reporting
1 parent f593506 commit b961099

File tree

9 files changed

+207
-65
lines changed

9 files changed

+207
-65
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ env:
2424

2525
matrix:
2626
include:
27+
- php: 7.2
28+
env: WP_VERSION=nightly
2729
- php: 7.1
2830
env: WP_VERSION=latest
2931
- php: 7.0

bin/install-package-tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ set -ex
55
install_db() {
66
mysql -e 'CREATE DATABASE IF NOT EXISTS wp_cli_test;' -uroot
77
mysql -e 'GRANT ALL PRIVILEGES ON wp_cli_test.* TO "wp_cli_test"@"localhost" IDENTIFIED BY "password1"' -uroot
8+
mysql -e 'GRANT ALL PRIVILEGES ON wp_cli_test_scaffold.* TO "wp_cli_test"@"localhost" IDENTIFIED BY "password1"' -uroot
89
}
910

1011
install_db

features/bootstrap/FeatureContext.php

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ private static function get_process_env_variables() {
131131
if ( $php_args = getenv( 'WP_CLI_PHP_ARGS' ) ) {
132132
$env['WP_CLI_PHP_ARGS'] = $php_args;
133133
}
134+
if ( $php_used = getenv( 'WP_CLI_PHP_USED' ) ) {
135+
$env['WP_CLI_PHP_USED'] = $php_used;
136+
}
137+
if ( $php = getenv( 'WP_CLI_PHP' ) ) {
138+
$env['WP_CLI_PHP'] = $php;
139+
}
134140
if ( $travis_build_dir = getenv( 'TRAVIS_BUILD_DIR' ) ) {
135141
$env['TRAVIS_BUILD_DIR'] = $travis_build_dir;
136142
}
@@ -526,7 +532,8 @@ public function background_proc( $cmd ) {
526532
$status = proc_get_status( $proc );
527533

528534
if ( !$status['running'] ) {
529-
throw new RuntimeException( stream_get_contents( $pipes[2] ) );
535+
$stderr = is_resource( $pipes[2] ) ? ( ': ' . stream_get_contents( $pipes[2] ) ) : '';
536+
throw new RuntimeException( sprintf( "Failed to start background process '%s'%s.", $cmd, $stderr ) );
530537
} else {
531538
$this->running_procs[] = $proc;
532539
}
@@ -617,7 +624,8 @@ public function install_wp( $subdir = '' ) {
617624
'title' => 'WP CLI Site',
618625
'admin_user' => 'admin',
619626
'admin_email' => 'admin@example.com',
620-
'admin_password' => 'password1'
627+
'admin_password' => 'password1',
628+
'skip-email' => true,
621629
);
622630

623631
$install_cache_path = '';
@@ -658,7 +666,8 @@ public function install_wp_with_composer( $vendor_directory = 'vendor' ) {
658666
'title' => 'WP CLI Site with both WordPress and wp-cli as Composer dependencies',
659667
'admin_user' => 'admin',
660668
'admin_email' => 'admin@example.com',
661-
'admin_password' => 'password1'
669+
'admin_password' => 'password1',
670+
'skip-email' => true,
662671
);
663672

664673
$this->proc( 'wp core install', $install_args )->run_check();
@@ -686,26 +695,13 @@ public function composer_require_current_wp_cli() {
686695
$this->composer_command( 'require wp-cli/wp-cli:dev-master --optimize-autoloader --no-interaction' );
687696
}
688697

689-
public function get_php_binary() {
690-
if ( getenv( 'WP_CLI_PHP_USED' ) )
691-
return getenv( 'WP_CLI_PHP_USED' );
692-
693-
if ( getenv( 'WP_CLI_PHP' ) )
694-
return getenv( 'WP_CLI_PHP' );
695-
696-
if ( defined( 'PHP_BINARY' ) )
697-
return PHP_BINARY;
698-
699-
return 'php';
700-
}
701-
702698
public function start_php_server( $subdir = '' ) {
703699
$dir = $this->variables['RUN_DIR'] . '/';
704700
if ( $subdir ) {
705701
$dir .= trim( $subdir, '/' ) . '/';
706702
}
707703
$cmd = Utils\esc_cmd( '%s -S %s -t %s -c %s %s',
708-
$this->get_php_binary(),
704+
Utils\get_php_binary(),
709705
'localhost:8080',
710706
$dir,
711707
get_cfg_var( 'cfg_file_path' ),

features/bootstrap/Process.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,20 @@ public function run_check() {
115115

116116
return $r;
117117
}
118+
119+
/**
120+
* Run the command, but throw an Exception on error.
121+
* Same as `run_check()` above, but checks the correct stderr.
122+
*
123+
* @return ProcessRun
124+
*/
125+
public function run_check_stderr() {
126+
$r = $this->run();
127+
128+
if ( $r->return_code || ! empty( $r->stderr ) ) {
129+
throw new \RuntimeException( $r );
130+
}
131+
132+
return $r;
133+
}
118134
}

features/bootstrap/support.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
// Utility functions used by Behat steps
44

5+
function assertRegExp( $regex, $actual ) {
6+
if ( ! preg_match( $regex, $actual ) ) {
7+
throw new Exception( "Actual value: " . var_export( $actual, true ) );
8+
}
9+
}
10+
511
function assertEquals( $expected, $actual ) {
612
if ( $expected != $actual ) {
713
throw new Exception( "Actual value: " . var_export( $actual, true ) );

0 commit comments

Comments
 (0)