jcchavezs/httptest
Spin up a lightweight local HTTP server for integration testing real HTTP calls (e.g., cURL). Define a request handler to assert method/headers/body and craft responses, enabling client- and server-side assertions without mocking HTTP.
httptest package is tailored for HTTP integration testing, making it a strong fit for Laravel applications requiring mock HTTP clients, request/response validation, or API contract testing.HttpClient, Route testing) and can complement tools like PestPHP or PHPUnit.HttpFoundation/Psr7 dependencies.HttpClient, Route testing helpers, or Testing facade. Workarounds (e.g., wrapping HttpClient instances) may be needed.symfony/http-client or guzzlehttp/guzzle. Dependency injection (DI) may require manual setup.actingAs(), followRedirects()). Could require custom assertions or extensions.HttpClient mocking or PestPHP’s Http::fake()?
httptest offer unique features (e.g., advanced response templating, contract testing)?mockery, vcr)?symfony/http-foundation v5.x for PSR-7 compatibility.httptest with HttpClient.Http::fake() or PestPHP plugins meet needs with lower risk.assertRedirect(), assertSession()).httptest could fill.Http::fake() performance).httptest from Laravel’s HttpClient.httptest-specific test runs.httptest may not simulate Laravel middleware (e.g., Auth, CORS). Use Http::actingAs() or middleware mocks as workarounds.HttpException handling may differ from httptest’s responses.httptest doesn’t interfere with Laravel’s service providers.httptest for isolated HTTP tests (e.g., API clients).Http::fake() for specific use cases (e.g., complex response templating).httptest limitations (e.g., no E2E support).httptest outputs match Laravel’s expectations (e.g., headers, status codes).httptest may not scale for large test suites due to:
--parallel).httptest’s syntax.| Risk | Impact | Mitigation |
|---|---|---|
| Package incompatibility | Tests break on PHP/Laravel upgrades | Fork the package or switch to native tools. |
| False positives/negatives | Mocks misrepresent real HTTP behavior | Pair with VCR (e.g., vcrphp) for safety nets. |
| Integration debt | Custom wrappers become unmaintainable | Document assumptions; refactor incrementally. |
| Security gaps | Mocks expose unintended endpoints | Use Http::fake() for sensitive routes. |
httptest syntax and Laravel integration patterns.TestCase base class to standardize httptest usage.httptest vs. Laravel’s tools; highlight trade-offs.HttpClient, validating responses).httptest reduces flakiness or adds value.Http::fake()).How can I help you explore Laravel packages today?