donatj/mock-webserver
Lightweight PHP mock web server for tests and local development. Spin up an HTTP server on a random port, enqueue canned responses, inspect received requests, and simulate endpoints reliably. Handy for integration tests without external services.
PHP_BINARY fix (PR #85) resolves macOS 26.3+ compatibility issues, eliminating silent failures in CI/CD pipelines. This improves reliability for Dockerized Laravel apps and GitHub Actions.Http::fake() but now with enhanced stability for cross-platform environments. The PHPUnit upgrade (PR #86) ensures compatibility with modern testing workflows (e.g., PestPHP 2.0+), though it introduces breaking changes for legacy test assertions.assertInternalType → assertType), necessitating test suite audits.PHP_BINARY fix mitigates a critical failure mode (e.g., port-binding issues on macOS). The PHP 7.2+ mandate also closes a security vulnerability (CVE-2026-24765), reducing risk in production-like test environments.assertEquals without type hints) may break tests.phpunit --debug to identify deprecated usage.PHP_BINARY fix reduces flakiness in CI, improving confidence in test results.PHP_BINARY change provides clearer error messages for port-binding failures (e.g., macOS-specific issues).PHP_BINARY path issues (e.g., GitHub Actions, self-hosted runners)?assertInternalType($var, 'string') → assertType('string', $var)assertEquals() without type hints.// Before (deprecated)
$this->assertInternalType('array', $response->json());
// After (recommended)
$this->assertIsArray($response->json());
stream_context but now with better cross-platform support and security hardening.PHP_BINARY fix reduces "port not open" errors in containerized tests.composer.json to PHP 7.2+ (or pin to v2.9.0 for legacy projects).
{
"require": {
"php": "^7.4 || ^8.0",
"donatj/mock-webserver": "^2.10.0"
}
}
PHP_BINARY-related errors (e.g., macOS runners).use PHPUnit\Framework\TestCase;
class MockWebServerTest extends TestCase {
public function testDynamicResponse() {
$response = $this->get('/api/user');
$this->assertIsArray($response->json()); // Updated assertion
}
}
@runClassInSeparateProcess to isolate deprecated methods.| Laravel Version | PHP Requirement | MockWebServer Version | Notes |
|---|---|---|---|
| 10+ | PHP 8.1+ | v2.10.0 | Full support |
| 9 | PHP 7.4+ | v2.10.0 | Requires PHP 7.4+ |
| 8 | PHP 7.2+ | v2.9.0 or v2.10.0 | v2.10.0 needs PHP 7.4+ |
| <8 | PHP 7.1+ | v2.9.0 | Fork required for v2.10.0 |
PHP_BINARY fix ensures consistent server startup across environments.composer.json and test basic GET/POST mocks in Laravel 10+.How can I help you explore Laravel packages today?