diff --git a/src/Context/Support.php b/src/Context/Support.php index c68e2879..cbd84378 100644 --- a/src/Context/Support.php +++ b/src/Context/Support.php @@ -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; diff --git a/src/Context/WhenStepDefinitions.php b/src/Context/WhenStepDefinitions.php index 2de8b3e2..e5a6c123 100644 --- a/src/Context/WhenStepDefinitions.php +++ b/src/Context/WhenStepDefinitions.php @@ -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; + } } /** diff --git a/src/PHPStan/ParseUrlFunctionDynamicReturnTypeExtension.php b/src/PHPStan/ParseUrlFunctionDynamicReturnTypeExtension.php index 55fef897..a875ecb4 100644 --- a/src/PHPStan/ParseUrlFunctionDynamicReturnTypeExtension.php +++ b/src/PHPStan/ParseUrlFunctionDynamicReturnTypeExtension.php @@ -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 );