PHPackages                             pact/pact - 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. pact/pact

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

pact/pact
=========

Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project.

0.2.1(10y ago)834.7k4MITPHPCI passing

Since Sep 17Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/mopoke/pact-php)[ Packagist](https://packagist.org/packages/pact/pact)[ RSS](/packages/pact-pact/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (2)Versions (4)Used By (0)

Pact-PHP
========

[](#pact-php)

Define a pact between service consumers and providers, enabling "consumer driven contract" testing.

[![CI](https://github.com/andykelk/pact-php/actions/workflows/ci.yml/badge.svg)](https://github.com/andykelk/pact-php/actions/workflows/ci.yml)

How to use
----------

[](#how-to-use)

1. Install pact mock service:

    1. Install Ruby and Ruby Gems
    2. Write a Gemfile:

        ```
        source 'https://rubygems.org'
        gem 'pact-mock_service', '~> 0.7.0'
        ```
    3. Run bundler to get the gems: `gem install bundler && bundle install`
2. Install composer:
3. Install dependencies: `composer install`
4. Write a phpunit test similar to the following:

    ```
    use Pact\Pact;

    class MyProviderTest extends PHPUnit\Framework\TestCase
    {
        public function testMyProvider(): void
        {
            $client = new ZooClient('http://localhost:1234');

            $alligatorProvider = Pact::mockService([
                'consumer' => 'Alligator Consumer',
                'provider' => 'Alligator Provider',
                'port' => 1234
            ]);

            $alligatorProvider
                ->given("an alligator with the name Mary exists")
                ->uponReceiving("a request for an alligator")
                ->withRequest("get", "/alligators/Mary", [
                    "Accept" => "application/json"
                ])->willRespondWith(200, [
                    "Content-Type" => "application/json"
                ], [
                    "name" => "Mary"
                ]);

            $alligatorProvider->run(function () use ($client) {
                $alligator = $client->getAlligatorByName('Mary');
                $this->assertInstanceOf("Alligator", $alligator);
                $this->assertEquals("Mary", $alligator->getName());
            });
        }
    }
    ```
5. Start the mock server: `bundle exec pact-mock-service -p 1234 --pact-specification-version 2.0.0 -l log/pact.logs --pact-dir tmp/pacts`
6. Run phpunit: `./vendor/bin/phpunit`
7. Inspect the pact file in `tmp/pacts`

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance57

Moderate activity, may be stable

Popularity31

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~2 days

Total

3

Last Release

3939d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e38dd12e65d4cde74e283409d745b2765e799bafd8ccd13c9cd05657b0474156?d=identicon)[mopoke](/maintainers/mopoke)

---

Top Contributors

[![andykelk](https://avatars.githubusercontent.com/u/3691521?v=4)](https://github.com/andykelk "andykelk (24 commits)")

---

Tags

pact

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[pact-foundation/pact-php

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

3002.0M43](/packages/pact-foundation-pact-php)[dms/phpunit-arraysubset-asserts

This package provides ArraySubset and related asserts once deprecated in PHPUnit 8

14429.2M360](/packages/dms-phpunit-arraysubset-asserts)

PHPackages © 2026

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