diff --git a/CHANGELOG.md b/CHANGELOG.md index 42a6d0bf..74647e05 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## v1.0.1 - 2024-04-09 + +### Fixed + +- Changed the timing of the `set_up` method being called in tests to be after + the database transaction is started. +- Allow other use of the `pre_http_request` filter when preventing external + requests during testing. +- Fixed an issue with the streamed HTTP response not being converted to a + `WP_Error` when needed. + ## v1.0.0 - 2024-04-04 ### Added diff --git a/src/mantle/console/concerns/trait-interacts-with-io.php b/src/mantle/console/concerns/trait-interacts-with-io.php index d6ff28fd..f6831b46 100644 --- a/src/mantle/console/concerns/trait-interacts-with-io.php +++ b/src/mantle/console/concerns/trait-interacts-with-io.php @@ -424,8 +424,6 @@ public function set_input( InputInterface $input ): void { /** * Retrieve the output interface. - * - * @return OutputInterface|Output_Style */ public function output(): OutputInterface|Output_Style { return $this->output; diff --git a/src/mantle/events/trait-wordpress-action.php b/src/mantle/events/trait-wordpress-action.php index 82672305..f6237560 100644 --- a/src/mantle/events/trait-wordpress-action.php +++ b/src/mantle/events/trait-wordpress-action.php @@ -176,7 +176,7 @@ protected function validate_argument_type( $argument, ReflectionParameter $param throw new RuntimeException( $type::class . ' is not a supported type-hint.' ); } - if ( $type instanceof ReflectionNamedType && $argument_type === $type->getName() ) { + if ( $argument_type === $type->getName() ) { return $argument; } diff --git a/src/mantle/testing/class-test-case.php b/src/mantle/testing/class-test-case.php index 3b1d31f2..f30a391c 100644 --- a/src/mantle/testing/class-test-case.php +++ b/src/mantle/testing/class-test-case.php @@ -141,11 +141,6 @@ protected function setUp(): void { parent::setUp(); - // Call the PHPUnit 8 'set_up' method if it exists. - if ( method_exists( $this, 'set_up' ) ) { - $this->set_up(); - } - if ( ! isset( $this->app ) ) { $this->refresh_application(); } @@ -171,6 +166,11 @@ function( $trait ): void { remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); add_filter( 'wp_die_handler', [ WP_Die::class, 'get_handler' ] ); + + // Call the PHPUnit 8 'set_up' method if it exists. + if ( method_exists( $this, 'set_up' ) ) { + $this->set_up(); + } } /** @@ -231,6 +231,7 @@ function( $trait ): void { parent::tearDown(); + // Reset the application instance after everything else. if ( $this->app ) { $this->app = null; diff --git a/src/mantle/testing/concerns/trait-interacts-with-requests.php b/src/mantle/testing/concerns/trait-interacts-with-requests.php index b3a7c359..7f1eae56 100644 --- a/src/mantle/testing/concerns/trait-interacts-with-requests.php +++ b/src/mantle/testing/concerns/trait-interacts-with-requests.php @@ -189,6 +189,11 @@ public function mock_response( string $body = '', array $headers = [] ): Mock_Ht * @throws RuntimeException If the request was made without a matching faked request. */ public function pre_http_request( $preempt, $request_args, $url ) { + // Bail early if the preemption is already set. + if ( false !== $preempt ) { + return $preempt; + } + $request = new Request( $request_args, $url ); $this->recorded_requests[] = $request; @@ -199,7 +204,11 @@ public function pre_http_request( $preempt, $request_args, $url ) { // If the request is for streaming the response to a file, store the // response body in the requested file. if ( ! is_wp_error( $stub ) && ! empty( $request_args['stream'] ) ) { - return $this->store_streamed_response( $url, $stub, $request_args ); + try { + return $this->store_streamed_response( $url, $stub, $request_args ); + } catch ( RuntimeException $e ) { + return new WP_Error( 'http_request_failed', $e->getMessage() ); + } } return $stub;