Centralize response assertions between Test_Response and Http_Client\Response classes #753
+633
−37
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR addresses the need to make assertion methods available across both
Mantle\Testing\Test_ResponseandMantle\Http_Client\Responseclasses by centralizing them in a shared trait.Problem
Previously, the
Test_Responseclass had many useful assertion methods likeassertSuccessful(),assertStatus(),assertIsJson(), etc., but these were not available when working with HTTP client responses. This led to:Solution
Created a centralized
Response_Assertionstrait that provides consistent assertion methods for both response classes:Key Changes
New Response_Assertions trait (
src/mantle/support/traits/trait-response-assertions.php)Enhanced Http_Client\Response (
src/mantle/http-client/class-response.php)Response_Assertionstraitstatus(),header(),body())Updated Test_Response (
src/mantle/testing/class-test-response.php)Available Assertions
Both response classes now support identical assertion methods:
Status Assertions:
assertSuccessful(),assertOk(),assertStatus(),assertCreated()assertNotFound(),assertForbidden(),assertUnauthorized()assertClientError(),assertServerError()Header Assertions:
assertHeader(),assertHeaderMissing(),assertLocation()Content Assertions:
assertContent(),assertSee(),assertDontSee(),assertContains()Content-Type Assertions:
assertIsJson(),assertIsNotJson(),assertIsHtml(),assertIsNotHtml()Special Assertions:
assertRedirect(),assertNoContent()Usage Examples
HTTP Client Response:
Test Response (unchanged):
Benefits
This change makes the framework more cohesive by ensuring both response types provide the same powerful assertion interface.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
https://api.github.com/repos/alleyinteractive/composer-wordpress-autoloader/zipball/a3a401b3d755d08f7689d0c5f1566809ea469f90/usr/bin/php8.3 -n -c /tmp/Y6Zn9G /usr/bin/composer install --no-dev(http block)If you need me to access, download, or install something from one of these locations, you can either:
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.