Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Httptest Laravel Package

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.

View on GitHub
Deep Wiki
Context7

PHP Library for HTTP integration testing

Frequently asked questions about Httptest
Can I use httptest to mock HTTP requests in Laravel 9+ or PHP 8.0+?
No, httptest was last updated in 2018 and may not support PHP 8.0+ or Laravel 9+. You’ll need polyfills like symfony/http-foundation v5.x or a custom wrapper to bridge compatibility gaps. Test thoroughly for breaking changes.
How does httptest compare to Laravel’s built-in `Http::fake()` for testing?
httptest offers more granular control over request/response mocking (e.g., templated responses, contract testing) but lacks Laravel-specific features like `actingAs()` or middleware simulation. `Http::fake()` is simpler and natively supported, so weigh your needs.
Will httptest work with PestPHP or only PHPUnit?
httptest is designed for PHPUnit, but it can integrate with PestPHP with minor adjustments (e.g., custom matchers). PestPHP’s `Http::fake()` might be a lower-effort alternative if you’re already using it.
Can I use httptest to test Laravel’s HttpClient or Guzzle HTTP calls?
Not directly—httptest targets PSR-7/HTTP-Foundation interfaces. You’ll need to wrap Laravel’s `HttpClient` or Guzzle instances in a compatible adapter or use a facade to bridge the gap.
Does httptest support testing API contracts (e.g., OpenAPI/Swagger validation)?
Yes, httptest can mock and assert HTTP responses to validate API contracts, but you’ll need to manually define expected payloads, headers, and status codes. No built-in OpenAPI/Swagger parsing exists.
How do I handle middleware (e.g., Auth, CORS) in httptest?
httptest doesn’t simulate Laravel middleware. Use workarounds like `Http::actingAs()` for auth or manually mock middleware responses in your test assertions.
What’s the best way to migrate from httptest to Laravel’s native testing tools?
Start by replacing simple mocks with `Http::fake()`, then gradually adopt PestPHP or PHPUnit’s native assertions. Audit tests for Laravel-specific quirks (e.g., redirects, sessions) that httptest doesn’t handle.
Are there performance concerns with httptest in large test suites?
httptest introduces minimal overhead for mocking, but complex response templating or assertions could slow tests. Benchmark against `Http::fake()`—Laravel’s native tool is optimized for performance.
Can httptest test database or queue interactions triggered by HTTP calls?
No, httptest focuses solely on HTTP layer mocking. For DB/queue interactions, combine it with Laravel’s testing tools (e.g., `refreshDatabase()`, `queueFake()`) or use transactional tests.
What should I do if httptest breaks in a new Laravel/PHP version?
Fork the package and update dependencies (e.g., PSR-7, Symfony components) or switch to alternatives like `mockery` for manual mocking or `vcr` for HTTP recording. Document the migration path in your test suite.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope