2017 © Pedro Peláez
 

library 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.

image

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.

  • Monday, September 21, 2015
  • by mopoke
  • Repository
  • 2 Watchers
  • 8 Stars
  • 11,240 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 1 Open issues
  • 4 Versions
  • 10 % Grown

The README.md

Pact-PHP

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

Build Status, (*2)

How to use

  1. Install pact mock service:, (*3)

    1. Install Ruby and Ruby Gems
    2. Write a Gemfile:, (*4)

      source 'https://rubygems.org'
      gem 'pact-mock_service', '~> 0.7.0'
      
    3. Run bundler to get the gems: gem install bundler && bundle install, (*5)

  2. Install composer: curl -sS https://getcomposer.org/installer | php
  3. Install dependencies: php composer.phar install
  4. Write a phpunit test similar to the following:, (*6)

    public function testMyProvider() {
      $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, (*7)

  6. Run phpunit: ./vendor/bin/phpunit
  7. Inspect the pact file in tmp/pacts

The Versions

21/09 2015

dev-master

9999999-dev

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.

  Sources   Download

MIT

The Development Requires

by Andy Kelk

pact

21/09 2015

0.2.1

0.2.1.0

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.

  Sources   Download

MIT

The Development Requires

by Andy Kelk

pact

17/09 2015

0.1.1

0.1.1.0

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.

  Sources   Download

MIT

The Development Requires

by Andy Kelk

pact

17/09 2015

0.0.1

0.0.1.0

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.

  Sources   Download

MIT

The Development Requires

by Andy Kelk

pact