- What does mcustiel/phiremock-codeception-module actually do?
- It is a Codeception module that acts as a client adapter to an external Phiremock server. Through the Codeception actor you can create expectations, load them from JSON files, and reset the server state semantically instead of hand-crafting HTTP control requests. It does not stub HTTP itself; the actual mocking happens in the separate Phiremock server process.
- How do I install phiremock-codeception-module in a Laravel project?
- Add mcustiel/phiremock-codeception-module to your require-dev section with Composer. Then enable the Phiremock module in your Codeception suite YAML with host, port, and other options as needed. You also need a running Phiremock server reachable from the test runner, usually via Docker or a local PHP process.
- Does this package work with Laravel 10 or 11 and Guzzle 7?
- The README documents a guzzlehttp/guzzle ^6.0 requirement, while modern Laravel releases ship Guzzle 7. That version pin is the most likely hard blocker, so check the actual Composer constraints of the release you install before adopting. If a conflict appears, you either need a compatible fork or a different approach such as Laravel's Http::fake().
- How do I configure the Phiremock module in a Codeception suite?
- Add Phiremock under modules: enabled: in your suite YAML and set host and port to where the Phiremock server listens. Optional keys include reset_before_each_test, expectations_path, secure, client_factory, and extra_connections. Defaults are localhost, port 8086, and expectations stored under codeception_dir/_data/phiremock-expectations.
- What does reset_before_each_test do and should I enable it?
- When set to true, the module executes haveACleanSetupInRemoteService before every test, clearing previous expectations. This enforces isolation for suites that mutate stub state across tests. It is slightly slower per test but usually worth enabling for acceptance suites that define different expectations in each scenario.
- How do I point my application's outbound HTTP calls at the Phiremock server?
- The module only controls the mock server; your application still needs to send its requests there. Configure the base URLs of your external services, or the Guzzle client options, so outbound calls resolve to the Phiremock host and port during tests. Common approaches are environment variables in the test suite or an HTTP client middleware that rewrites hosts.
- Can I load prewritten expectations from JSON files?
- Yes. The expectations_path option points to a directory of JSON expectation files, defaulting to codeception_dir/_data/phiremock-expectations. You can reference these files from annotations and have them loaded automatically. This keeps large or reused stub definitions out of your test code.
- Is phiremock-codeception-module a good alternative to Laravel's Http::fake()?
- Only in specific cases. If your code exclusively uses Laravel's HTTP client, Http::fake() is simpler because it needs no extra infrastructure. Phiremock is useful when you need a real HTTP endpoint with realistic status codes, headers, delays, or malformed responses, or when the code under test uses a separately configured Guzzle client or non-Guzzle transport.
- What are the licensing and maintenance risks of this package?
- The package is GPL-3.0, which is generally tolerated in dev dependencies but can trigger legal review in organizations with strict OSS policies. It is also a small single-maintainer project with few stars and dependents, so bus factor and slow PHP version support are real concerns. Pin a working version and have a fallback plan if releases stall.
- What happens if the Phiremock server is not running during tests?
- Tests fail with connectivity errors rather than assertion failures, which can make diagnosis confusing. Make sure your CI pipeline starts the Phiremock server and waits for it to be reachable before running the suite. A health check or startup wait in the pipeline avoids flaky failures caused by race conditions.