PHPackages                             mattersight/phppact - 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. mattersight/phppact

Abandoned → [pact-foundation/pact-php](/?search=pact-foundation%2Fpact-php)Library[Testing &amp; Quality](/categories/testing)

mattersight/phppact
===================

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

10.2.1(3mo ago)29616.3k91[5 PRs](https://github.com/pact-foundation/pact-php/pulls)MITPHPPHP ^8.1CI passing

Since Jul 17Pushed 2mo ago15 watchersCompare

[ Source](https://github.com/pact-foundation/pact-php)[ Packagist](https://packagist.org/packages/mattersight/phppact)[ Docs](https://github.com/pact-foundation/pact-php)[ RSS](/packages/mattersight-phppact/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (10)Dependencies (17)Versions (67)Used By (0)

[![logo](https://user-images.githubusercontent.com/53900/121775784-0191d200-cbcd-11eb-83dd-adc001b94519.png)](https://user-images.githubusercontent.com/53900/121775784-0191d200-cbcd-11eb-83dd-adc001b94519.png)

Pact PHP
========

[](#pact-php)

[![Code Analysis & Test](https://github.com/pact-foundation/pact-php/actions/workflows/build.yml/badge.svg)](https://github.com/pact-foundation/pact-php/actions/workflows/build.yml/badge.svg)[![Coverage Status](https://camo.githubusercontent.com/2c0b94ea32a3ebab762d6bb4ea3cf2cb4e813692ae294460ea2aa876ef44565e/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f706163742d666f756e646174696f6e2f706163742d7068702f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/pact-foundation/pact-php?branch=master)[![Compatibility Suite](https://github.com/pact-foundation/pact-php/actions/workflows/compatibility-suite.yml/badge.svg)](https://github.com/pact-foundation/pact-php/actions/workflows/compatibility-suite.yml/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)

#### Fast, easy and reliable testing for your APIs and microservices.

[](#fast-easy-and-reliable-testing-for-your-apis-and-microservices)

 [![Pact PHP Demo](https://private-user-images.githubusercontent.com/3327643/329893196-d62310ef-4c9b-4bf1-ae84-a9ae41d88414.gif?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzMyNzIxNzQsIm5iZiI6MTc3MzI3MTg3NCwicGF0aCI6Ii8zMzI3NjQzLzMyOTg5MzE5Ni1kNjIzMTBlZi00YzliLTRiZjEtYWU4NC1hOWFlNDFkODg0MTQuZ2lmP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDMxMSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjAzMTFUMjMzMTE0WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YzlkN2FjNjY4ZDAwYWQzODc3YjY3Zjc0MDExM2FkMjU1ZjRhNWMwZDY1MjJmNTI4ZjhjNjliNTY0ZDgyNzc1ZSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.1SjI9yNR8OH_FyHCadGxy0otwRGwyQlAMJ5ecyc1WrI)](https://docs.pact.io)

**Pact** is the de-facto API contract testing tool. Replace expensive and brittle end-to-end integration tests with fast, reliable and easy to debug unit tests.

- ⚡ Lightning fast
- 🎈 Effortless full-stack integration testing - from the front-end to the back-end
- 🔌 Supports HTTP/REST and event-driven systems
- 🛠️ Configurable mock server
- 😌 Powerful matching rules prevents brittle tests
- 🤝 Integrates with Pact Broker / PactFlow for powerful CI/CD workflows
- 🔡 Supports 12+ languages

**Why use Pact?**

Contract testing with Pact lets you:

- ⚡ Test locally
- 🚀 Deploy faster
- ⬇️ Reduce the lead time for change
- 💰 Reduce the cost of API integration testing
- 💥 Prevent breaking changes
- 🔎 Understand your system usage
- 📃 Document your APIs for free
- 🗄 Remove the need for complex data fixtures
- 🤷‍♂️ Reduce the reliance on complex test environments

Watch our [series](https://www.youtube.com/playlist?list=PLwy9Bnco-IpfZ72VQ7hce8GicVZs7nm0i) on the problems with end-to-end integrated tests, and how contract testing can help.

[![----------](https://user-images.githubusercontent.com/53900/182992715-aa63e421-170b-41cf-8f95-82fe4b0846c2.png)](https://user-images.githubusercontent.com/53900/182992715-aa63e421-170b-41cf-8f95-82fe4b0846c2.png)

Documentation
-------------

[](#documentation)

This readme offers a basic introduction to the library. The full documentation for Pact PHP and the rest of the framework is available at .

- [Installation](#installation)
- [Consumer Testing](/docs/consumer.md)
- [Provider Testing](/docs/provider.md)
- [Event Driven Systems](/docs/messages.md)
- [Examples](https://github.com/pact-foundation/pact-php/tree/master/examples/)
- [Stub Server](/docs/stub-server.md)
- [Framework Integrations](/docs/framework-integrations.md)
- [Troubleshooting](./docs/troubleshooting.md)

Need Help
---------

[](#need-help)

- [Join](http://slack.pact.io) our community [slack workspace](http://pact-foundation.slack.com/).
- Stack Overflow:
- Say 👋 on Twitter: \[@pact\_up\]

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

[](#installation)

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

# 🚀 now write some tests!
```

Looking for the previous [stable 9.x.x release](https://github.com/pact-foundation/pact-php/tree/release/9.x)?

### Requirements

[](#requirements)

PHP 8.1+ as of pact-php v10

### Runtime requirements (v10+)

[](#runtime-requirements-v10)

Pact PHP v10 uses native FFI bindings.

- PHP 8.1+
- PHP FFI installed and enabled (`ffi.enable=true`)
- On Alpine (musl), install `libgcc` and enable FFI

See: [docs/alpine-ffi-troubleshooting.md](docs/alpine-ffi-troubleshooting.md)

### Do Not Track

[](#do-not-track)

In order to get better statistics as to who is using Pact, we have an anonymous tracking event that triggers when Pact installs for the first time. The only things we [track](https://docs.pact.io/metrics) are your type of OS, and the version information for the package being installed. No PII data is sent as part of this request. You can disable tracking by setting the environment variable `PACT_DO_NOT_TRACK=true`:

[![----------](https://user-images.githubusercontent.com/53900/182992715-aa63e421-170b-41cf-8f95-82fe4b0846c2.png)](https://user-images.githubusercontent.com/53900/182992715-aa63e421-170b-41cf-8f95-82fe4b0846c2.png)

Usage
-----

[](#usage)

### Writing a Consumer test

[](#writing-a-consumer-test)

```
namespace App\Tests;

use App\Service\HttpClientService;
use PhpPact\Consumer\InteractionBuilder;
use PhpPact\Consumer\Matcher\Matcher;
use PhpPact\Consumer\Model\ConsumerRequest;
use PhpPact\Consumer\Model\ProviderResponse;
use PhpPact\Standalone\MockService\MockServerConfig;
use PHPUnit\Framework\TestCase;

class ConsumerServiceHelloTest extends TestCase
{
    public function testGetHelloString(): void
    {
        $matcher = new Matcher();

        // Create your expected request from the consumer.
        $request = new ConsumerRequest();
        $request
            ->setMethod('GET')
            ->setPath('/hello/Bob')
            ->addHeader('Content-Type', 'application/json');

        // Create your expected response from the provider.
        $response = new ProviderResponse();
        $response
            ->setStatus(200)
            ->addHeader('Content-Type', 'application/json')
            ->setBody([
                'message' => $matcher->term('Hello, Bob', '(Hello, )[A-Za-z]+')
            ]);

        // Create a configuration that reflects the server that was started. You can create a custom MockServerConfigInterface if needed.
        $config = new MockServerConfig();
        $config
            ->setConsumer('jsonConsumer')
            ->setProvider('jsonProvider')
            ->setPactDir(__DIR__.'/../../../pacts');
        if ($logLevel = \getenv('PACT_LOGLEVEL')) {
            $config->setLogLevel($logLevel);
        }
        $builder = new InteractionBuilder($config);
        $builder
            ->uponReceiving('A get request to /hello/{name}')
            ->with($request)
            ->willRespondWith($response); // This has to be last. This is what makes FFI calls to register the interaction and start the mock server.

        $service = new HttpClientService($config->getBaseUri()); // Pass in the URL to the Mock Server.
        $helloResult = $service->getHelloString('Bob'); // Make the real API request against the Mock Server.
        $verifyResult = $builder->verify(); // This will verify that the interactions took place.

        $this->assertTrue($verifyResult); // Make your assertions.
        $this->assertEquals('Hello, Bob', $helloResult);
    }
}
```

You can see (and run) the full version of this in `./examples/json`, as well as other examples in the parent folder.

To run the examples

1. Clone the repo `git@github.com:pact-foundation/pact-php.git`
2. Go to the repo `cd pact-php`
3. Install all dependencies `composer install`

Run a single example

`composer run-example:json`

Run all examples

`composer run-examples`

[![----------](https://user-images.githubusercontent.com/53900/182992715-aa63e421-170b-41cf-8f95-82fe4b0846c2.png)](https://user-images.githubusercontent.com/53900/182992715-aa63e421-170b-41cf-8f95-82fe4b0846c2.png)

### Verifying a Provider

[](#verifying-a-provider)

A provider test takes one or more pact files (contracts) as input, and Pact verifies that your provider adheres to the contract. In the simplest case, you can verify a provider as per below using a local pact file, although in practice you would usually use a Pact Broker to manage your contracts and CI/CD workflow.

```
namespace App\Tests;

use GuzzleHttp\Psr7\Uri;
use PhpPact\Standalone\ProviderVerifier\Model\VerifierConfig;
use PhpPact\Standalone\ProviderVerifier\Verifier;
use PhpPactTest\Helper\PhpProcess;
use PHPUnit\Framework\TestCase;

class PactVerifyTest extends TestCase
{
    private PhpProcess $process;

    protected function setUp(): void
    {
        $this->process = new PhpProcess(__DIR__ . '/path/to/public/');
        $this->process->start();
    }

    protected function tearDown(): void
    {
        $this->process->stop();
    }

    /**
     * This test will run after the web server is started.
     */
    public function testPactVerifyConsumer()
    {
        $config = new VerifierConfig();
        $config->getProviderInfo()
            ->setName('jsonProvider') // Providers name to fetch.
            ->setHost('localhost')
            ->setPort($this->process->getPort());
        $config->getProviderState()
            ->setStateChangeUrl(new Uri(sprintf('http://localhost:%d/pact-change-state', $this->process->getPort())))
        ;
        if ($level = \getenv('PACT_LOGLEVEL')) {
            $config->setLogLevel($level);
        }

        $verifier = new Verifier($config);
        $verifier->addFile(__DIR__ . '/path/to/pacts/jsonConsumer-jsonProvider.json');

        $verifyResult = $verifier->verify();

        $this->assertTrue($verifyResult);
    }
}
```

It's best to run Pact verification tests as part of your unit testing suite, so you can readily access stubbing, IaC and other helpful tools.

[![----------](https://user-images.githubusercontent.com/53900/182992715-aa63e421-170b-41cf-8f95-82fe4b0846c2.png)](https://user-images.githubusercontent.com/53900/182992715-aa63e421-170b-41cf-8f95-82fe4b0846c2.png)

Compatibility
-------------

[](#compatibility)

VersionsVersionStatus[Spec](https://github.com/pact-foundation/pact-specification) CompatibilityPHP CompatibilityInstall11.xDeveloping1, 1.1, 2, 3, 4^8.2See [installation](#installation)10.xStable1, 1.1, 2, 3, 4^8.1See [installation](#installation)9.xDeprecated1, 1.1, 2, 3\*^8.0[9xx](https://github.com/pact-foundation/pact-php/tree/release/9.x)8.xDeprecated1, 1.1, 2, 3\*^7.4|^8.07.xDeprecated1, 1.1, 2, 3\*^7.36.xDeprecated1, 1.1, 2, 3\*^7.25.xDeprecated1, 1.1, 2, 3\*^7.14.xDeprecated1, 1.1, 2^7.13.xDeprecated1, 1.1, 2^7.02.xDeprecated1, 1.1, 2&gt;=71.xDeprecated1, 1.1&gt;=7*\** v3 support is limited to the subset of functionality required to enable language inter-operable [Message support](https://github.com/pact-foundation/pact-specification/tree/version-3#introduces-messages-for-services-that-communicate-via-event-streams-and-message-queues).

Supported PlatformsOSArchitectureSupportedPact-PHP VersionOSXx86\_64✅AllLinuxx86\_64✅AllOSXarm64✅9.x +Linuxarm64✅9.x +Windowsx86\_64✅AllWindowsx86✅9.x -Alpinex86\_64✅All \*Alpinearm64✅All \**\** For 9.x and below, supported with a workaround [Ruby Standalone with Alpine](https://github.com/pact-foundation/pact-ruby-standalone/wiki/Using-the-pact-ruby-standalone-with-Alpine-Linux-Docker).

Roadmap
-------

[](#roadmap)

The [roadmap](https://docs.pact.io/roadmap/) for Pact and Pact PHP is outlined on our main website.

Contributing
------------

[](#contributing)

See [CONTRIBUTING](CONTRIBUTING.md).

[ ![](https://camo.githubusercontent.com/1eecdc6c08d3eddbf16aabebcb94b51680e19274a38accfef0477dcb5727eb67/68747470733a2f2f636f6e747269622e726f636b732f696d6167653f7265706f3d706163742d666f756e646174696f6e2f706163742d706870)](https://github.com/pact-foundation/pact-php/graphs/contributors)

###  Health Score

63

—

FairBetter than 99% of packages

Maintenance82

Actively maintained with recent releases

Popularity41

Moderate usage in the ecosystem

Community31

Small or concentrated contributor base

Maturity86

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 63.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~51 days

Recently: every ~96 days

Total

61

Last Release

110d ago

Major Versions

7.2.0 → 8.0.02022-07-31

8.1.0 → 9.0.02023-07-14

9.0.0 → 10.0.0-alpha12023-07-25

9.1.1 → 10.0.0-alpha62024-03-13

10.2.1 → 11.0.0-alpha12026-01-25

PHP version history (11 changes)1.0.1PHP &gt;=7

3.0.0PHP ^7.0

4.0.0PHP ^7.1

6.0.2PHP ^7.2

7.0.0PHP ^7.3

7.1.0PHP ^7.3 |^8.0

7.1.2PHP ^7.3|^8.0

8.0.0PHP ^7.4|^8.0|^8.1

9.0.0PHP ^8.0

10.0.0-alpha6PHP ^8.1

11.0.0-alpha1PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/6ee19e7a59603fcb7b64b274786782e1ce502dd2fbbcaf7a43b06f1911ee04d1?d=identicon)[mattermack](/maintainers/mattermack)

---

Top Contributors

[![tienvx](https://avatars.githubusercontent.com/u/3327643?v=4)](https://github.com/tienvx "tienvx (886 commits)")[![cfmack](https://avatars.githubusercontent.com/u/415720?v=4)](https://github.com/cfmack "cfmack (171 commits)")[![YOU54F](https://avatars.githubusercontent.com/u/19932401?v=4)](https://github.com/YOU54F "YOU54F (92 commits)")[![siad007](https://avatars.githubusercontent.com/u/2149445?v=4)](https://github.com/siad007 "siad007 (64 commits)")[![WaylandAce](https://avatars.githubusercontent.com/u/1263005?v=4)](https://github.com/WaylandAce "WaylandAce (36 commits)")[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (30 commits)")[![Thomblin](https://avatars.githubusercontent.com/u/3504882?v=4)](https://github.com/Thomblin "Thomblin (26 commits)")[![mattermack](https://avatars.githubusercontent.com/u/8886666?v=4)](https://github.com/mattermack "mattermack (14 commits)")[![nbrink91](https://avatars.githubusercontent.com/u/19517049?v=4)](https://github.com/nbrink91 "nbrink91 (13 commits)")[![Sertion](https://avatars.githubusercontent.com/u/288119?v=4)](https://github.com/Sertion "Sertion (8 commits)")[![mente](https://avatars.githubusercontent.com/u/391997?v=4)](https://github.com/mente "mente (7 commits)")[![o-borovets](https://avatars.githubusercontent.com/u/7982859?v=4)](https://github.com/o-borovets "o-borovets (4 commits)")[![bethesque](https://avatars.githubusercontent.com/u/446228?v=4)](https://github.com/bethesque "bethesque (3 commits)")[![jildertmiedema](https://avatars.githubusercontent.com/u/3383186?v=4)](https://github.com/jildertmiedema "jildertmiedema (3 commits)")[![KonstantinCodes](https://avatars.githubusercontent.com/u/844484?v=4)](https://github.com/KonstantinCodes "KonstantinCodes (3 commits)")[![Lewiscowles1986](https://avatars.githubusercontent.com/u/2605791?v=4)](https://github.com/Lewiscowles1986 "Lewiscowles1986 (3 commits)")[![ctrl-f5](https://avatars.githubusercontent.com/u/485346?v=4)](https://github.com/ctrl-f5 "ctrl-f5 (3 commits)")[![frastel](https://avatars.githubusercontent.com/u/433380?v=4)](https://github.com/frastel "frastel (3 commits)")[![andytson-inviqa](https://avatars.githubusercontent.com/u/11387086?v=4)](https://github.com/andytson-inviqa "andytson-inviqa (2 commits)")[![malukenho](https://avatars.githubusercontent.com/u/3275172?v=4)](https://github.com/malukenho "malukenho (2 commits)")

---

Tags

apiscontract-testinghacktoberfestpactpactpact-php

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/mattersight-phppact/health.svg)

```
[![Health](https://phpackages.com/badges/mattersight-phppact/health.svg)](https://phpackages.com/packages/mattersight-phppact)
```

###  Alternatives

[pact-foundation/pact-php

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

2971.7M32](/packages/pact-foundation-pact-php)[vimeo/psalm

A static analysis tool for finding errors in PHP applications

5.8k77.5M6.7k](/packages/vimeo-psalm)[phan/phan

A static analyzer for PHP

5.6k11.2M1.1k](/packages/phan-phan)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[phpbench/phpbench

PHP Benchmarking Framework

2.0k13.0M627](/packages/phpbench-phpbench)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

19462.3M1.3k](/packages/drupal-core)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
