PHPackages                             waylandace/pact-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. waylandace/pact-php

AbandonedLibrary[Testing &amp; Quality](/categories/testing)

waylandace/pact-php
===================

Enables consumer driven contract testing, following the PACT foundation principles.

7.2.5(3y ago)01.2kMITPHPPHP ^7.3|^8.0

Since Jul 17Pushed 3y agoCompare

[ Source](https://github.com/WaylandAce/pact-php)[ Packagist](https://packagist.org/packages/waylandace/pact-php)[ Docs](https://github.com/pact-foundation/pact-php)[ RSS](/packages/waylandace-pact-php/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (6)Dependencies (22)Versions (59)Used By (0)

Pact PHP
========

[](#pact-php)

[![pact-php](https://github.com/pact-foundation/pact-php/workflows/pact-php/badge.svg)](https://github.com/pact-foundation/pact-php/workflows/pact-php/badge.svg)[![Packagist](https://camo.githubusercontent.com/7110e3f6a363ea617b33df8253bc37adaf4ecd2883c57f727a6270def530da2c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f706163742d666f756e646174696f6e2f706163742d7068703f7374796c653d666c61742d737175617265)](https://packagist.org/packages/pact-foundation/pact-php)

[![Downloads](https://camo.githubusercontent.com/7c75d58a17acd1d57282b003d88414d2ccde11c3e86dc1c4cc8160c238352ed7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f706163742d666f756e646174696f6e2f706163742d7068703f7374796c653d666c61742d737175617265)](https://packagist.org/packages/pact-foundation/pact-php)[![Downloads This Month](https://camo.githubusercontent.com/01fa4d302d116f504db29e98f7e20cf047d7cd0f66ce36e94f695959df74cc8a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f706163742d666f756e646174696f6e2f706163742d7068703f7374796c653d666c61742d737175617265)](https://packagist.org/packages/pact-foundation/pact-php)

PHP version of [Pact](https://pact.io). Enables consumer driven contract testing. Please read the [Pact.io](https://pact.io) for specific information about PACT.

Table of contents
=================

[](#table-of-contents)

- [Versions](#versions)
- [Specifications](#specifications)
- [Installation](#installation)
- [Basic Consumer Usage](#basic-consumer-usage)
    - [Start and Stop the Mock Server](#start-and-stop-the-mock-server)
    - [Create Consumer Unit Test](#create-consumer-unit-test)
    - [Create Mock Request](#create-mock-request)
    - [Create Mock Response](#create-mock-response)
    - [Build the Interaction](#build-the-interaction)
    - [Make the Request](#make-the-request)
    - [Make Assertions](#make-assertions)
- [Basic Provider Usage](#basic-provider-usage)
    - [Create Unit Tests](#create-unit-test)
    - [Start API](#start-api)
    - [Provider Verification](#provider-verification)
        - [Verify From Pact Broker](#verify-from-pact-broker)
        - [Verify All from Pact Broker](#verify-all-from-pact-broker)
        - [Verify Files by Path](#verify-files-by-path)
- [Tips](#tips)
    - [Starting API Asynchronously](#starting-api-asynchronously)
    - [Set Up Provider State](#set-up-provider-state)
    - [Examples](#additional-examples)

Versions
--------

[](#versions)

8.X updates internal dependencies and libraries. This results in dropping PHP 7.3

7.x updates internal dependencies and libraries, mostly to Guzzle 7.X. This results in dropping support for PHP 7.2. 6.x updates internal dependencies, mostly surrounding the Amp library. This results in dropping support for PHP 7.1.

5.X adds preliminary support for async messages and pact specification 3.X. This does not yet support the full pact specification 3.X as the backend implementations are incomplete. However, pact-messages are supported.

The 4.X tags are accompany changes in PHPUnit 7.X which requires a PHP 7.1 or higher. Thus, 4.X drops support for PHP 7.0.

The 3.X tags are a major breaking change to the 2.X versions. To be similar to the rest of the Pact ecosystem, Pact-PHP migrated to leverage the Ruby backend. This mirrors the .Net, JS, Python, and Go implementations.

If you wish to stick with the 2.X implementation, you can continue to pull from the [latest 2.X.X tag](https://github.com/pact-foundation/pact-php/tree/2.2.1).

Specifications
--------------

[](#specifications)

The 3.X version is the version of Pact-PHP, not the pact specification version that it supports. Pact-Php 3.X supports [Pact-Specification 2.X](https://github.com/pact-foundation/pact-specification/tree/version-2).

Installation
------------

[](#installation)

Install the latest version with:

```
$ composer require pact-foundation/pact-php --dev
```

Composer hosts older versions under `mattersight/phppact`, which is abandoned. Please convert to the new package name.

Basic Consumer Usage
--------------------

[](#basic-consumer-usage)

All of the following code will be used exclusively for the Consumer.

### Start and Stop the Mock Server

[](#start-and-stop-the-mock-server)

This library contains a wrapper for the [Ruby Standalone Mock Service](https://github.com/pact-foundation/pact-mock_service).

The easiest way to configure this is to use a [PHPUnit Listener](https://phpunit.de/manual/current/en/appendixes.configuration.html#appendixes.configuration.test-listeners). A default listener is included in this project, see [PactTestListener.php](/src/PhpPact/Consumer/Listener/PactTestListener.php). This utilizes environmental variables for configurations. These env variables can either be added to the system or to the phpunit.xml configuration file. Here is an example [phpunit.xml](/example/phpunit.consumer.xml) file configured to use the default. Keep in mind that both the test suite and the arguments array must be the same value.

Alternatively, you can start and stop as in whatever means you would like by following this example:

```
