$ show pact-foundation/pact-php
This repository is a PHP implementation of the Pact contract testing framework, enabling consumer-driven contract testing for APIs and microservices. It allows developers to define expected interactions in consumer tests (generating Pact files) and verify provider compliance against those contracts. The library supports multiple transport protocols (HTTP/REST, gRPC, message queues) and data formats (JSON, XML, CSV, Protobuf, etc.) through a plugin architecture. It uses FFI to interface with a Rust-based Pact core and includes a mock server for simulating providers during testing. The codebase features a well-structured domain model, extensive matcher/generator system, and comprehensive compatibility suite validating adherence to Pact specifications v1-v4.
The LLM identified 2 files worth highlighting for reuse:
The main entry point for the matcher system, providing a fluent interface to define matching rules for HTTP interactions. Demonstrates builder and strategy patterns, allowing composable matchers (e.g., combining equality with regex) and integration with generators for dynamic values. The matcher system is extensible via interfaces and traits, making it suitable for reuse in other testing or validation contexts.
A PSR-3 compliant logger supporting multiple sinks (stdout, stderr, file, buffer) with attachable sinks and individual log levels. Demonstrates strategy pattern for log handling and dependency injection for configuration. This self-contained logging component can be easily extracted and used in any PHP project requiring flexible logging.