Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/Context/Support.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,23 @@ protected function check_string( $output, $expected, $action, $message = false,
$message = $output;
}

$action_message = '';
switch ( $action ) {
case 'be':
$action_message = 'Output does not exactly match expected string:';
break;
case 'contain':
$action_message = 'Output does not contain expected string:';
break;
case 'not contain':
$action_message = 'Output unexpectedly contains string:';
break;
default:
throw new \Behat\Behat\Tester\Exception\PendingException();
}

$message .= "\n\n" . $action_message . "\n" . $expected;

$diff = $this->generate_diff( $expected, rtrim( $output, "\n" ) );
if ( ! empty( $diff ) ) {
$message .= "\n\n" . $diff;
Expand Down
19 changes: 18 additions & 1 deletion src/Context/WhenStepDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,24 @@ public function wpcli_tests_invoke_proc( $proc, $mode ) {
);
$method = $map[ $mode ];

return $proc->$method();
try {
return $proc->$method();
} catch ( \RuntimeException $e ) {
if ( 'run' === $mode ) {
$message = $e->getMessage();
$status = preg_match( '/exit status: (\d+)$/', $message, $matches ) ? $matches[1] : 'unknown';

if ( '0' === $status ) {
$message .= "\n\nThe command unexpectedly produced STDERR output. If you expect a non-zero exit status or STDERR output, use `When I try [...]`. Else, this may be a bug in your code or test.";
} else {
$message .= "\n\nThe command unexpectedly exited with status {$status}. If you expect a non-zero exit status, use `When I try [...]`. Else, this may be a bug in your code or test.";
}

throw new \RuntimeException( $message, $e->getCode(), $e );
}

throw $e;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function getTypeFromFunctionCall( FunctionReflection $functionReflection,
$types = [];
foreach ( $urlType->getConstantStrings() as $constantString ) {
try {
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
$result = @parse_url( $constantString->getValue(), $componentType->getValue() );
} catch ( \Error $e ) {
$types[] = new ConstantBooleanType( false );
Expand Down