Skip to content

Commit

Permalink
Close output buffer when exception occurs during setup (#607)
Browse files Browse the repository at this point in the history
* Close output buffer when exception occurs during setup

* CHANGELOG

---------

Co-authored-by: Sean Fisher <[email protected]>
  • Loading branch information
dlh01 and srtfisher authored Dec 13, 2024
1 parent 33c10bc commit 9fdb1a9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## v1.3.1 - 2024-12-13

### Fixed

- Fixed issue where output buffers were left open when an exception occurred during setup.

## v1.3.0 - 2024-12-02

### Added
Expand Down
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 9fdb1a9

Please sign in to comment.