Skip to content

Commit

Permalink
Close output buffer when exception occurs during setup
Browse files Browse the repository at this point in the history
  • Loading branch information
dlh01 committed Dec 12, 2024
1 parent 33c10bc commit 9158273
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/mantle/testing/class-pending-testable-request.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,14 @@ protected function format_server_header_key( $name ) {
/**
* Call the given URI and return the Response.
*
* @throws \Exception Exceptions thrown while setting up the WordPress query are re-thrown to the caller.
*
* @param string $method Request method.
* @param mixed $uri Request URI.
* @param array $parameters Request params.
* @param array $server Server vars.
* @param array $cookies Cookies to be sent with the request.
* @param string|null $content Request content.
* @param array $cookies Cookies to be sent with the request.
* @param string|null $content Request content.
*/
public function call( string $method, mixed $uri, array $parameters = [], array $server = [], array $cookies = [], ?string $content = null ): Test_Response {
$this->reset_request_state();
Expand Down Expand Up @@ -323,7 +325,13 @@ public function call( string $method, mixed $uri, array $parameters = [], array

ob_start();

$this->setup_wordpress_query();
try {
$this->setup_wordpress_query();
} catch ( \Exception $e ) {
// If an exception occurs, make sure the output buffer is closed before the exception continues to the caller.
ob_end_clean();
throw $e;
}

if ( $this->rest_api_response ) {
// Use the response from the REST API server.
Expand Down

0 comments on commit 9158273

Please sign in to comment.