mcustiel/phiremock-codeception-extension
A Codeception extension that starts a Phiremock Server before a test suite and stops it afterward. Configure listen address, binary path, logs, debug, readiness waits, and expectations for easier HTTP mocking.
Architecture fit
phiremock-server before a Codeception suite and stops it after, and reads a YAML config block. The actual request matching, expectation schema, and HTTP semantics live in phiremock-server; the client-side expectation API lives in a third package, phiremock-codeception-module.Http::fake() / Http::preventStrayRequests(), which intercept in-process. Out-of-process buys fidelity (real headers, form data, TLS, redirects, retry/timeout behavior, SDK-internal transports); in-process buys speed, zero ports, zero supervision.Http::fake(), this package's incremental value is narrow and specific: acceptance-level tests of the served application (Codeception acceptance suite hitting artisan serve/nginx), testing non-Guzzle clients or SDKs that ignore Laravel's HTTP facade, and TLS/port-level scenarios.Integration feasibility
symfony/process. v4.0.0 additionally requires phiremock-server v2, bumps the PHP floor, and adds Symfony 8 support. wait_until_ready requires phiremock-client via Composer.listen (bind address/port), bin_path, logs_path, debug, start_delay vs. wait_until_ready (with timeout/interval), expectations_path, suites filter, extra_instances (e.g., simultaneous HTTP + HTTPS), certificate*, and server_factory for bringing your own PSR-18 client (Guzzle 6 vs 7 is a real-world friction point this solves).suites: [] filtering and per-suite extension config (Codeception ≥2.2.7) let you scope the server to only the suites that need it — important for keeping the rest of the suite fast.Technical risk
listen address), and readiness timing. wait_until_ready mitigates the readiness case but adds a dependency on phiremock-client.RefreshDatabase-style lifecycle. Any "Laravel integration" is really "Codeception + Laravel module + env-var wiring," which you build.Key questions to resolve before committing
Http::fake() cover them instead?Stack fit
127.0.0.1:18080; the app's config/services.php base URL is pointed at that address via an env var set for the test environment; Phiremock returns canned responses; assertions run against the app's response and, if needed, Phiremock's request log.Http::fake(), Queue::fake(), Event::fake()) for unit/feature tests; Phiremock for acceptance/e2e tests that must traverse the real HTTP stack. Do not migrate existing fast tests to a socket-based mock — that is a net regression in speed and stability.tests/_expectations (or a configured path). That is a contract artifact; treat it as an API surface with review, ownership, and versioning, not as test detritus.Migration path
vendor/bin/phiremock or phar) and validate expectation JSON and app wiring by hand. This isolates "is the mock correct?" from "is the extension orchestrating correctly?" — a distinction that saves days of debugging later.wait_until_ready: true and suites: scoped to the pilot suite. Avoid start_delay as a permanent solution; it is a race condition with a sleep timer._bootstrap.php/global extension that shells out to Phiremock directly, or a Docker Compose service. Document it — it is ~50 lines and it defuses the single-maintainer risk almost entirely.extra_instances (HTTP + HTTPS) only if you actually need TLS fidelity; otherwise stay single-instance.Compatibility
server_factory). Laravel 11 is referenced in v3.1.0; confirm your Laravel version and the Codeception Laravel module compatibility independently — the extension itself is Laravel-agnostic.server_factory subclass up front; it is a small class but requires phiremock-server as a local Composer dependency (not phar/Docker), which constrains your deployment choice.bin_path is used to invoke it and whether your CI runner needs a Docker socket — that is an infrastructure ticket, not a config line.Sequencing (order of work)
Maintenance
v1 vs v2 formats differ) and Codeception's extension API. Both have broken before.Support
debug: true and logs_path to a CI artifact directory from day one; Phiremock's log of received requests is the single most valuable debugging artifact you get.phiremock-codeception-module) handles client-side expectation management. Teams routinely conflate the two in troubleshooting; document the split in your internal runbook.Scaling
Failure modes (and the mitigations a TPM should fund)
wait_until_ready: true with explicit timeout/interval; not start_delay.expectations_path → silent no-stub behavior manifesting as opaque 404s/connection errors; add a startup assertion that the expectation directory exists and is non-empty.certificate* when a test genuinely needs HTTPS.Ramp-up
Http::fake() versus when to use Phiremock. Ambiguity here will cause teams to over-apply the heavier tool and quietly make the suite slower and flakier.How can I help you explore Laravel packages today?