- How do I use this package to mock HTTP responses in Laravel unit tests?
- Register the static provider as a custom HTTP client resolver in your Laravel service provider. Then, replace `Http::get()` calls with your predefined static responses. The package works with PSR-15/17 interfaces, so it integrates seamlessly with Laravel’s HTTP stack. Example: Bind a custom client in `config/http.php` or via a service provider.
- Does this package support Laravel’s built-in `Http::fake()` functionality?
- No, this package is a standalone static HTTP provider and doesn’t replace Laravel’s `Http::fake()`. However, it can supplement it by providing predefined responses for specific endpoints, especially in cases where you need static JSON/XML files or fixed responses without dynamic mocking.
- What Laravel versions and PHP versions does this package support?
- The package requires PHP 8.4+ and is designed to work with modern Laravel versions (8.x and above). It leverages PSR-15/17 interfaces, which are compatible with Laravel’s HTTP client stack. Always check the latest `composer.json` for exact version constraints.
- Can I use this package to mock API responses for Stripe, PayPal, or other third-party services?
- Yes, this package is ideal for mocking third-party API responses in tests or local development. Define static responses for endpoints like `stripe.com` or `paypal.com` and inject them into your Laravel HTTP client. It’s lightweight and avoids real network calls, making it perfect for isolated testing.
- How do I configure custom headers or status codes in the static responses?
- The package allows you to define custom headers, status codes, and response bodies when setting up your static HTTP provider. Use the Boson configuration system to specify these values. For example, you can return a `404 Not Found` with custom headers or a `200 OK` with a predefined JSON payload.
- Will this package work with PestPHP or PHPUnit test suites?
- Yes, the package is framework-agnostic and works with both PestPHP and PHPUnit. You can register the static provider in your test setup and use it to mock HTTP responses in your test cases. It’s particularly useful for unit tests where you need deterministic, repeatable responses.
- Is there a performance overhead compared to Laravel’s `Http::fake()`?
- The performance overhead is minimal since this package serves static responses without network calls. However, if you need dynamic responses (e.g., request-based variations), `Http::fake()` or a hybrid approach might be more efficient. For purely static use cases, this package is lightweight and fast.
- How do I integrate this with Laravel’s HTTP client facade (e.g., `Http::get()`)?
- You’ll need to bind the static provider as a custom HTTP client resolver in your Laravel application. This typically involves creating a service provider, binding the Boson static provider to the HTTP client container, and configuring it to resolve requests for specific endpoints. Refer to the Boson documentation for detailed integration steps.
- Are there alternatives to this package for mocking HTTP responses in Laravel?
- Yes, alternatives include Laravel’s built-in `Http::fake()`, `vcr-php/vcr` for record/replay testing, and `mockery/php-mock` for lower-level HTTP mocking. This package is best suited for static responses, while `Http::fake()` offers more dynamic mocking capabilities. Choose based on whether you need static or dynamic responses.
- Who maintains this package, and is it actively updated?
- This package is part of the Boson PHP ecosystem and is maintained by the Boson team. While it’s a subtree split of the main Boson package, updates may align with Boson’s roadmap. Check the GitHub repository for recent activity or join their Telegram community for updates. Contributions are welcome for Laravel-specific features.