Skip to content

Commit

Permalink
Merge pull request #59 from wp-cli/update_tests_enable_error_reporting
Browse files Browse the repository at this point in the history
Update tests enable error reporting
  • Loading branch information
danielbachhuber authored Nov 17, 2017
2 parents 7121cfd + 862f871 commit 5019f6e
Show file tree
Hide file tree
Showing 11 changed files with 229 additions and 68 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ env:

matrix:
include:
- php: 7.2
env: WP_VERSION=nightly
- php: 7.1
env: WP_VERSION=latest
- php: 7.0
Expand Down
1 change: 1 addition & 0 deletions bin/install-package-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set -ex
install_db() {
mysql -e 'CREATE DATABASE IF NOT EXISTS wp_cli_test;' -uroot
mysql -e 'GRANT ALL PRIVILEGES ON wp_cli_test.* TO "wp_cli_test"@"localhost" IDENTIFIED BY "password1"' -uroot
mysql -e 'GRANT ALL PRIVILEGES ON wp_cli_test_scaffold.* TO "wp_cli_test"@"localhost" IDENTIFIED BY "password1"' -uroot
}

install_db
30 changes: 13 additions & 17 deletions features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ private static function get_process_env_variables() {
if ( $php_args = getenv( 'WP_CLI_PHP_ARGS' ) ) {
$env['WP_CLI_PHP_ARGS'] = $php_args;
}
if ( $php_used = getenv( 'WP_CLI_PHP_USED' ) ) {
$env['WP_CLI_PHP_USED'] = $php_used;
}
if ( $php = getenv( 'WP_CLI_PHP' ) ) {
$env['WP_CLI_PHP'] = $php;
}
if ( $travis_build_dir = getenv( 'TRAVIS_BUILD_DIR' ) ) {
$env['TRAVIS_BUILD_DIR'] = $travis_build_dir;
}
Expand Down Expand Up @@ -526,7 +532,8 @@ public function background_proc( $cmd ) {
$status = proc_get_status( $proc );

if ( !$status['running'] ) {
throw new RuntimeException( stream_get_contents( $pipes[2] ) );
$stderr = is_resource( $pipes[2] ) ? ( ': ' . stream_get_contents( $pipes[2] ) ) : '';
throw new RuntimeException( sprintf( "Failed to start background process '%s'%s.", $cmd, $stderr ) );
} else {
$this->running_procs[] = $proc;
}
Expand Down Expand Up @@ -617,7 +624,8 @@ public function install_wp( $subdir = '' ) {
'title' => 'WP CLI Site',
'admin_user' => 'admin',
'admin_email' => 'admin@example.com',
'admin_password' => 'password1'
'admin_password' => 'password1',
'skip-email' => true,
);

$install_cache_path = '';
Expand Down Expand Up @@ -658,7 +666,8 @@ public function install_wp_with_composer( $vendor_directory = 'vendor' ) {
'title' => 'WP CLI Site with both WordPress and wp-cli as Composer dependencies',
'admin_user' => 'admin',
'admin_email' => 'admin@example.com',
'admin_password' => 'password1'
'admin_password' => 'password1',
'skip-email' => true,
);

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

public function get_php_binary() {
if ( getenv( 'WP_CLI_PHP_USED' ) )
return getenv( 'WP_CLI_PHP_USED' );

if ( getenv( 'WP_CLI_PHP' ) )
return getenv( 'WP_CLI_PHP' );

if ( defined( 'PHP_BINARY' ) )
return PHP_BINARY;

return 'php';
}

public function start_php_server( $subdir = '' ) {
$dir = $this->variables['RUN_DIR'] . '/';
if ( $subdir ) {
$dir .= trim( $subdir, '/' ) . '/';
}
$cmd = Utils\esc_cmd( '%s -S %s -t %s -c %s %s',
$this->get_php_binary(),
Utils\get_php_binary(),
'localhost:8080',
$dir,
get_cfg_var( 'cfg_file_path' ),
Expand Down
16 changes: 16 additions & 0 deletions features/bootstrap/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,20 @@ public function run_check() {

return $r;
}

/**
* Run the command, but throw an Exception on error.
* Same as `run_check()` above, but checks the correct stderr.
*
* @return ProcessRun
*/
public function run_check_stderr() {
$r = $this->run();

if ( $r->return_code || ! empty( $r->stderr ) ) {
throw new \RuntimeException( $r );
}

return $r;
}
}
6 changes: 6 additions & 0 deletions features/bootstrap/support.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

// Utility functions used by Behat steps

function assertRegExp( $regex, $actual ) {
if ( ! preg_match( $regex, $actual ) ) {
throw new Exception( "Actual value: " . var_export( $actual, true ) );
}
}

function assertEquals( $expected, $actual ) {
if ( $expected != $actual ) {
throw new Exception( "Actual value: " . var_export( $actual, true ) );
Expand Down
Loading

0 comments on commit 5019f6e

Please sign in to comment.