Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close output buffer when exception occurs during setup #607

Merged
merged 2 commits into from
Dec 13, 2024
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
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
Loading