Releases: Thavarshan/fetch-php
v3.3.0
Added
- Comprehensive Testing Utilities inspired by Laravel's HTTP client testing:
MockServerwith URL pattern matching (wildcards, method-specific, callbacks)MockResponsefluent builder with convenience methods for all HTTP status codesMockResponseSequencefor testing retry logic and flaky endpointsRecorderfor capturing and replaying request/response pairs- Comprehensive assertion helpers (
assertSent(),assertNotSent(),assertSentCount(),assertNothingSent()) - Request recording with JSON export/import for test fixtures
- Stray request prevention with allowlist support
HandlesMockingtrait integrated intoClientHandlerfor request interceptionRequest::createFromBase()method for PSR-7 request conversion- 117 new tests with 288 assertions for testing utilities
- Comprehensive testing documentation in
docs/guide/testing.md(617 lines) - Complete API reference in
docs/api/testing.md(539 lines) - Testing utilities section in VitePress sidebar navigation
Changed
- Updated
PerformsHttpRequeststo support mock request interception - Enhanced
ClientHandlerwithHandlesMockingtrait for testing support
Fixed
- Fixed async helper function imports to use correct
Matrix\Support\*namespace:- Updated imports in
ManagesPromisestrait (async,await,all,any,race,reject,resolve,timeout) - Updated imports in
PerformsHttpRequeststrait (async) - Updated imports in
ManagesPromisesTestandAsyncRequestsTest
- Updated imports in
- All 282 tests now passing with 841 assertions
Removed
- Removed Dependabot configuration (
dependabot.yml) - Removed Dependabot auto-merge workflow
Full Changelog: v3.2.3...v3.3.0
v3.2.3
Added
- Comprehensive test coverage for array body handling in
ConfiguresRequestsTest - Explicit option conflict prevention in request body configuration
- Better error prevention for Guzzle HTTP client integration
Changed
ConfiguresRequests::withBody()method now ensures mutual exclusivity of body-related options- Request option handling now explicitly removes conflicting options (
json,body,form_params,multipart) - Improved reliability of JSON array requests by preventing option conflicts
Fixed
- BREAKING FIX: Resolved Guzzle
InvalidArgumentExceptionwhen sending POST requests with array bodies - Fixed issue where both
jsonandbodyoptions were set simultaneously, causing Guzzle to reject requests - Eliminated "Passing in the 'body' request option as an array to send a request is not supported" error
- Restored ability to send structured JSON data using PHP arrays in request bodies
- Fixed helper functions (
post(),put(),patch(), etc.) failing with array payloads
Full Changelog: 3.2.2...3.2.3
v3.2.2
Fixed
- "Fatal error: Uncaught Error: Interface
Psr\Log\LoggerAwareInterfacenot found" closes #21
Full Changelog: 3.2.1...3.2.2
v3.2.1
v3.2.0
Added
- Added tests for various HTTP methods (GET, POST, PUT, DELETE, PATCH, OPTIONS) with appropriate assertions.
Changed
- Simplified
ManagesRetriesTestby using a mock class for retry-logic testing. - Consolidated tests for retryable status codes and exceptions into a single method.
- Updated
PerformsHttpRequestsTestto useGuzzleHttpclient mocks for more accurate request simulation. - Enhanced exception-handling tests to verify error messages and retry behaviour.
- Removed unnecessary reflection methods and streamlined test setup.
Fixed
- Improved back-off delay calculations in retry tests to ensure correct timing.
v3.1.1
Added
- Implemented the missing
finalizeRequest()method in thePerformsHttpRequeststrait. This method centralizes request finalization logic, enabling internal shortcut methods likeget(),post(), etc., to function correctly.
Changed
- Internal shortcut HTTP methods (
get(),post(),put(), etc.) inPerformsHttpRequestsnow route through the newly addedfinalizeRequest()method for consistent request handling.
Fixed
- Fixed a fatal error caused by calling an undefined
finalizeRequest()method inClientHandler. The missing method has now been properly defined and implemented.
v3.1.0
Added
-
PSR-18 Client:
Fetch\Http\Clientnow implementsPsr\Http\Client\ClientInterfacefor drop-in interoperability. -
Fluent Request Builder: Chainable helpers on
ClientHandlerfor headers, query params, JSON/form/multipart bodies, bearer token, basic auth, timeouts, redirects, cookies, proxy, certificates. -
Async/Promise Support: Built-in ReactPHP-style promises (
async(),await(),all(),race(),any(),sequence()), with->async()toggle andwrapAsync()/awaitPromise()helpers. -
Automatic Retries: Configurable max retries, retry delay, exponential backoff with jitter, and retry-on-status (408, 429, 5xx) or exceptions (
ConnectException). -
PSR-3 Logging: Optional
LoggerInterfaceinjection onClientandClientHandlerwith info/debug/error logs and sensitive-data masking for retries, requests, and responses. -
Immutable PSR-7 Extensions:
Fetch\Http\Requestextends Guzzle’s PSR-7Requestwith immutability traits and JSON/form/multipart constructors.Fetch\Http\Responseextends Guzzle’s PSR-7Responsewith buffered body, array-access to JSON payloads, and helpers:->json(),->text(),->xml(),->blob(),->arrayBuffer(), status inspectors, etc.
-
Enums for Safety:
Fetch\Enum\Method,ContentType, andStatusenums for validating methods, content types, and status codes. -
Test Helpers:
ClientHandler::createMockResponse()andcreateJsonResponse()to easily stub HTTP responses in unit tests.
Changed
- Consolidated Handler Traits: Core behavior refactored into six concerns (
ConfiguresRequests,HandlesUris,ManagesPromises,ManagesRetries,PerformsHttpRequests,SendsRequests) for clearer separation of URI handling, retries, promises, and request dispatch. - Unified Fetch API:
Client::fetch()now returns either aResponseInterfaceor the handler for method chaining, replacing older ad-hoc patterns. - Error-handling Alignment: Top-level
Client::sendRequest()now throws standardizedNetworkException,RequestException, orClientExceptioninstead of rawRuntimeException. - Default Options Management: Moved default method, headers, and timeout into
ClientHandler::$defaultOptionswith newgetDefaultOptions()andsetDefaultOptions(). - Guzzle Configuration:
ClientHandlernow reuses a single Guzzle client instance withRequestOptions::HTTP_ERRORSdisabled (handling errors internally) andCONNECT_TIMEOUTmapped from handler timeout.
v3.0.0
Added
- True Asynchronous Support: Completely reimplemented asynchronous functionality using Matrix's PHP Fiber-based library
- JavaScript-like Syntax: Added support for JavaScript-like async/await patterns with
async()andawait()functions - Promise-based API: Introduced a clean Promise interface with
then(),catch(), andfinally()methods - Concurrent Request Helpers: Added support for managing multiple concurrent requests with
all(),race(), andany()functions - Task Lifecycle Management: Implemented proper task lifecycle control (start, pause, resume, cancel, retry)
- Enhanced Error Handling: Added improved error handling with customizable error handlers
- New Helper Methods:
wrapAsync(): For wrapping callables in async functionsawaitPromise(): For awaiting promise resolution
Changed
- New Matrix Integration: Migrated from legacy AsyncHelper to the new Matrix Fiber-based promises
- Return Type Changes: Updated method signatures to use union types (
ResponseInterface|PromiseInterface) - Simplified API: Streamlined the API to match JavaScript's fetch pattern more closely
- Improved Retry Logic: Enhanced retry mechanisms for both synchronous and asynchronous requests
- Updated Documentation: Completely revised documentation to reflect the new async patterns
Removed
- AsyncHelper Class: Removed the legacy AsyncHelper class in favor of direct Matrix integration
Fixed
- Promise Handling: Fixed various issues with Promise resolution and rejection
- Retry Mechanism: Fixed retry logic to properly handle both network and server errors
- Error Propagation: Improved how errors are propagated through Promise chains
- Event Loop Management: Fixed event loop management for proper async task execution
v2.0.6
Added
- Added
withQueryParameter()method for adding a single query parameter - Added
withJson()method as a convenient way to set JSON request bodies - Added
withFormParams()andwithMultipart()helper methods for form submissions - Added
configurePostableRequest()helper method to standardize request body handling
Changed
- Enhanced
withBody()method to support multiple content types (JSON, form-encoded, multipart) - Improved
post()andput()methods to properly handle different content types - Improved retry mechanism with exponential backoff and jitter for better reliability
- Enhanced error handling to be more selective about which errors trigger retries
Fixed
- Fixed query parameter handling to properly merge with existing parameters instead of overwriting
- Fixed URL construction in
getFullUri()to correctly append query parameters - Fixed retry logic to perform exactly the specified number of retries (not one extra)
- Fixed duplicate implementation of
isRetryableError()method - Fixed retry failure detection to properly identify the last retry attempt
Full Changelog: 2.0.5...2.0.6
v2.0.5
Added
- Added the following utility methods to
ClientHandler:getOptions(): Retrieve the full request options array.getHeaders(): Retrieve the headers array from the request options.hasHeader(string $header): bool: Check if a specific header is set in the request.hasOption(string $option): bool: Check if a specific option is set in the request.
Full Changelog: 2.0.4...2.0.5