- What is codeception/module-rest used for?
- It is the REST module for Codeception, a testing framework that simplifies testing REST and JSON APIs. It lets you send HTTP requests, set headers and authentication, validate response codes and content types, and assert JSON or XML payloads. It is typically combined with a browser or framework module such as PhpBrowser or the Codeception Laravel module to build end-to-end API tests.
- How do I install codeception/module-rest with Composer?
- Install it as a dev dependency with composer require --dev codeception/module-rest. Because it is a Codeception module, you will normally also have codeception/codeception and a connector module installed. After installation, enable REST in your suite configuration file and rebuild Codeception with vendor/bin/codecept build.
- Does codeception/module-rest work with Laravel?
- It can run alongside Laravel, but Laravel does not use Codeception by default, so integrating it requires extra setup such as a separate test suite, a custom bootstrap, and a compatible connector module. Nothing in the package is Laravel-specific, so you are essentially adding a second testing framework next to PHPUnit or Pest. For most Laravel projects the built-in HTTP testing helpers are a better fit than introducing Codeception.
- Which Codeception and PHP versions does codeception/module-rest require?
- Version requirements are defined in the package's composer.json on the codeception/module-rest repository, and recent releases target Codeception 5.x and modern PHP versions. Always check the released tags against your installed Codeception version before upgrading, since major Codeception releases have introduced breaking configuration changes. There is no published matrix mapping module versions to specific Laravel versions, so verify compatibility in a non-production branch first.
- How do I configure the REST module in a Codeception suite?
- Add REST to the enabled modules list in your suite configuration, usually with a depends entry pointing at the module that actually performs the requests, such as PhpBrowser or the framework module. You then configure options like the base URL, default headers, and auth credentials. If REST depends on a module that makes requests, headers and URLs set through REST are forwarded to that underlying module.
- How do I set headers and authentication in Codeception REST tests?
- The module provides methods such as haveHttpHeader for arbitrary headers, amHttpAuthenticated for basic auth, and amBearerAuthenticated for token auth, and you can also pass headers per request. These calls apply to subsequent requests in the same test, so set them before you send the request. This makes it straightforward to test protected endpoints by obtaining a token in a setup step and then authenticating the test client.
- Can I assert JSON and XML responses with codeception/module-rest?
- Yes, the module includes assertions such as seeResponseCodeIs, seeResponseIsJson, seeResponseContainsJson, and seeResponseJsonMatchesJsonPath for JSON, plus XML equivalents like seeResponseIsXml and seeXmlResponseIncludes. You can also assert response format and content type. For complex contracts, prefer JSONPath or XML assertions over full-body string comparisons, which are brittle and prone to flaky failures.
- Should I replace Laravel's PHPUnit or Pest HTTP tests with Codeception REST?
- Generally no. Laravel's native test client, HTTP helpers, and factories are tightly integrated with the framework and require no extra configuration, while adopting Codeception means rewriting existing tests into a different syntax and maintaining two toolchains. The migration cost is significant for legacy codebases and offers little benefit for typical Laravel applications. Only consider it if your organization already standardizes on Codeception across multiple frameworks.
- How do I run Codeception REST tests in CI alongside Laravel's test suite?
- You will need a separate Codeception run command and configuration path alongside your normal php artisan test or vendor/bin/phpunit step, which means two CI stages and two sets of environment variables to keep in sync. Codeception also needs its own bootstrap and actor classes to be generated and committed. Budget for extra pipeline complexity and keep both suites pointed at an isolated test database to avoid interference.
- Is codeception/module-rest actively maintained, and what are the alternatives?
- The package lives in the official Codeception GitHub organization, but its community footprint is small, with modest star counts, so you should review recent commit activity and open issues before depending on it. Some release metadata for the project has looked inconsistent, which makes version checks especially important. Alternatives include Laravel's built-in HTTP testing helpers, Pest plugins, and plain Guzzle-based integration tests that stay within the PHPUnit ecosystem.