How to Contract Test a Symfony API Against an OpenAPI Spec Using Gesso
A technical guide explains how to perform provider-side contract testing on a Symfony API using an OpenAPI specification as the source of truth. The approach uses four components: an OpenAPI spec document, a WebTestCase or plain Request/Response pair, a PHP trait, and its assertion methods. The open-source library Gesso (studio-design/gesso) serves as the testing framework, supporting OpenAPI versions 3.0 through 3.2 and Symfony versions 6.4 and above. Developers install Gesso as a dev dependency, register a PHPUnit extension to locate spec files, and use the OpenApiAssertions trait to verify that live requests and responses conform to the published schema. This provider-side approach differs from consumer-driven contract testing tools like Pact and is best suited for teams that already maintain an OpenAPI document and want fast, per-endpoint drift detection.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in