A test suite that calls a live payment, email or identity provider is slow, costly and unreliable. Provider sandboxes are useful for end-to-end verification, but most application tests should run deterministically without network access. The key is to test the boundary where your application translates between its own model and the provider's protocol.
Isolate the HTTP boundary
Inject a transport interface or use a testable HTTP wrapper. In unit tests, provide a fake response for each scenario: success, validation rejection, expired credentials, rate limiting, malformed JSON, timeout and provider outage. Keep fixtures based on documented provider examples, but remove personal data and secrets.
Test mapping, not just status codes
Assert that external identifiers map to the correct internal records, amounts and currencies are interpreted correctly, optional fields are handled, and unknown provider fields do not break parsing. Include realistic payloads with missing values and unexpected enum values. A 200 response with an invalid body is still a failed integration.
Keep contract fixtures current
Record the provider API version and the date or source of each fixture. When the provider changes its schema, update the adapter and fixtures deliberately. Do not silently rewrite fixtures to make a failing test pass without understanding the behavior change.
Use sandbox tests selectively
Run a small set of scheduled or release-gated tests against the provider's sandbox. Use dedicated test credentials, isolate test data and ensure cleanup. Never point automated tests at production accounts by default.
Further reading
- PHPUnit documentation — https://docs.phpunit.de/
- PHP cURL documentation — https://www.php.net/manual/en/book.curl.php