Skip to content

Commit

Permalink
Update scaffolded tests to latest
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbachhuber committed Sep 29, 2017
1 parent 82865ff commit be1e9d0
Show file tree
Hide file tree
Showing 8 changed files with 608 additions and 115 deletions.
8 changes: 7 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ matrix:
env: WP_VERSION=latest

before_install:
- phpenv config-rm xdebug.ini
- |
# Remove Xdebug for a huge performance increase:
if [ -f ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini ]; then
phpenv config-rm xdebug.ini
else
echo "xdebug.ini does not exist"
fi
install:
- composer require wp-cli/wp-cli:dev-master
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wp-cli/super-admin-command",
"description": "Manage super admins on WordPress multisite.",
"description": "Lists, adds, or removes super admin users on a multisite install.",
"type": "wp-cli-package",
"homepage": "https://github.com/wp-cli/super-admin-command",
"support": {
Expand Down
342 changes: 316 additions & 26 deletions features/bootstrap/FeatureContext.php

Large diffs are not rendered by default.

62 changes: 45 additions & 17 deletions features/bootstrap/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,25 @@ class Process {
*/
private $env;

/**
* @var array Descriptor spec for `proc_open()`.
*/
private static $descriptors = array(
0 => STDIN,
1 => array( 'pipe', 'w' ),
2 => array( 'pipe', 'w' ),
);

/**
* @var bool Whether to log run time info or not.
*/
public static $log_run_times = false;

/**
* @var array Array of process run time info, keyed by process command, each a 2-element array containing run time and run count.
*/
public static $run_times = array();

/**
* @param string $command Command to execute.
* @param string $cwd Directory to execute the command in.
Expand All @@ -46,30 +65,39 @@ private function __construct() {}
* @return ProcessRun
*/
public function run() {
$cwd = $this->cwd;

$descriptors = array(
0 => STDIN,
1 => array( 'pipe', 'w' ),
2 => array( 'pipe', 'w' ),
);
$start_time = microtime( true );

$proc = proc_open( $this->command, $descriptors, $pipes, $cwd, $this->env );
$proc = proc_open( $this->command, self::$descriptors, $pipes, $this->cwd, $this->env );

$stdout = stream_get_contents( $pipes[1] );
fclose( $pipes[1] );

$stderr = stream_get_contents( $pipes[2] );
fclose( $pipes[2] );

return new ProcessRun( array(
'stdout' => $stdout,
'stderr' => $stderr,
'return_code' => proc_close( $proc ),
'command' => $this->command,
'cwd' => $cwd,
'env' => $this->env,
) );
$return_code = proc_close( $proc );

$run_time = microtime( true ) - $start_time;

if ( self::$log_run_times ) {
if ( ! isset( self::$run_times[ $this->command ] ) ) {
self::$run_times[ $this->command ] = array( 0, 0 );
}
self::$run_times[ $this->command ][0] += $run_time;
self::$run_times[ $this->command ][1]++;
}

return new ProcessRun(
array(
'stdout' => $stdout,
'stderr' => $stderr,
'return_code' => $return_code,
'command' => $this->command,
'cwd' => $this->cwd,
'env' => $this->env,
'run_time' => $run_time,
)
);
}

/**
Expand All @@ -81,7 +109,7 @@ public function run_check() {
$r = $this->run();

// $r->STDERR is incorrect, but kept incorrect for backwards-compat
if ( $r->return_code || !empty( $r->STDERR ) ) {
if ( $r->return_code || ! empty( $r->STDERR ) ) {
throw new \RuntimeException( $r );
}

Expand Down
6 changes: 6 additions & 0 deletions features/bootstrap/ProcessRun.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ class ProcessRun {
*/
public $return_code;

/**
* @var float The run time of the process.
*/
public $run_time;

/**
* @var array $props Properties of executed command.
*/
Expand All @@ -54,6 +59,7 @@ public function __toString() {
$out = "$ $this->command\n";
$out .= "$this->stdout\n$this->stderr";
$out .= "cwd: $this->cwd\n";
$out .= "run time: $this->run_time\n";
$out .= "exit status: $this->return_code";

return $out;
Expand Down
Loading

0 comments on commit be1e9d0

Please sign in to comment.