SlideShare a Scribd company logo
1 of 17
@andykelk | #SydPHP
Consumer-driven
Contracts with Pact and
PHP
@andykelk | #SydPHP
provider
consumer 1
consumer 2
consumer 3
{
status: “ok”,
count: 20,
items: [
{
id: 10000,
name: ...
Providers and consumers
@andykelk | #SydPHP
Consumer-driven contracts
• In a service oriented architecture, a service provider
typically has many consumers.
• Each of those consumers has expectations about the
service.
• Over time, consumer expectations change and the
provider must evolve to meet them.
• Standard approaches to this introduce
interdependence into the relationship.
• The Consumer-Driven Contracts pattern solves that.
@andykelk | #SydPHP
Consumer-driven contracts
provider
consumer 1
consumer 2
consumer 3
{
status: “ok”,
count: 20,
items: [
{
id: 10000,
name: ...
@andykelk | #SydPHP
Pact
• Ruby gem which implements automated testing for
consumer-driven contracts
• There are also implementations for
• .Net (Provider, Consumer)
• JVM (Provider, Consumer)
• JavaScript (Provider, Consumer)
• Swift (Consumer)
@andykelk | #SydPHP
Pact
https://github.com/realestate-com-au/pact
@andykelk | #SydPHP
Pact
• BUT… no PHP implementation 😞
• Luckily we can use the Provider Proxy to help us test a
PHP service provider
@andykelk | #SydPHP
JavaScript Consumer
Jasmine
PhantomJS
PAC
T
Karma
Test framework/
Test runner
Browser
(headless)
Mock/contract
endpoint
App code
(HTTP client,
model)
Production code
exercise
s
invokes via
socket
creates
pact json file
@andykelk | #SydPHP
beforeEach(function() {
client = ZooClient.createClient('http://localhost:1234');
alligatorProvider = Pact.mockService({
consumer: 'Alligator Consumer',
provider: 'Alligator Provider',
port: 1234,
done: function (error) {
expect(error).toBe(null);
}
});
});
Setting up a JavaScript consumer
@andykelk | #SydPHP
Setting up a JavaScript consumer
it("should return an alligator", function(done) {
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(done, function(runComplete) {
expect(client.getAlligatorByName("Mary")).toEqual(new Alligator("Mary"));
runComplete();
});
});
@andykelk | #SydPHP
Now we have a pact
{
"consumer": { "name": "Alligator Consumer" },
"provider": { "name": "Alligator Provider" },
"interactions": [
{
"description": "a request for an alligator",
"provider_state": "an alligator with the name Mary exists",
"request": {
"method": "get",
"path": "/alligators/Mary",
"headers": { "Accept": "application/json" }
},
"response": {
"status": 200,
"headers": { "Content-Type": "application/json" },
"body": { "name": "Mary" }
}
}
],
"metadata": { "pactSpecificationVersion": "1.0.0" }
}
@andykelk | #SydPHP
PHP Provider
Rake
PAC
T
prox
y
Test framework/
Test runner
Mock/contract
endpoint
App code
(service
provider)
Production code
invokes
pact json file
reads
@andykelk | #SydPHP
Create the API provider
<?php
require 'vendor/autoload.php';
$app = new SlimSlim();
$app->get('/alligators/:name', function ($name) use ($app) {
$app->response->setStatus(200);
$app->response()->headers->set('Content-Type', 'application/json');
echo json_encode(array('name' => $name));
});
$app->run();
@andykelk | #SydPHP
Use rake and pact provider proxy to test
require 'pact/provider/proxy/tasks'
Pact::ProxyVerificationTask.new :alligator do | task |
task.pact_url './spec/pacts/alligator_consumer-alligator_provider.json',
:pact_helper => './spec/support/alligator_pact_helper'
task.provider_base_url 'http://localhost:8000'
end
Pact.provider_states_for "Alligator Consumer" do
provider_state "an alligator with the name Mary exists" do
set_up do
# Set-up the provider state (e.g. create fixture) here
end
end
end
@andykelk | #SydPHP
Demo Time!
@andykelk | #SydPHP
What’s next?
• PHP implementation of the pact specification
• Use pact broker to share pact files and provide:
• Auto-generated documentation
• Dynamically generated network diagrams
• The ability to tag a pact (ie. "prod") so a provider
can verify itself against a fixed version of a pact to
ensure backwards compatibility.
• Webhooks to trigger provider builds when a pact is
published.
@andykelk | #SydPHP
Questions?
• Further reading:
• http://martinfowler.com/articles/consumerDrivenContracts.html
• https://github.com/realestate-com-au/pact
• http://techblog.realestate.com.au/testing-interactions-with-web-services-
without-integration-tests-in-ruby/
• http://techblog.realestate.com.au/enter-the-pact-matrix-or-how-to-
decouple-the-release-cycles-of-your-microservices/
• Code from the demo:
• https://github.com/mopoke/pact-php-demo
• Relive this talk in blog form:
• http://www.andykelk.net/tech/consumer-driven-contracts-with-pact-and-
php

More Related Content

What's hot

Consumer-Driven Contract Testing
Consumer-Driven Contract TestingConsumer-Driven Contract Testing
Consumer-Driven Contract TestingPaulo Clavijo
 
vodQA(Pune) 2018 - Consumer driven contract testing using pact
vodQA(Pune) 2018 - Consumer driven contract testing using pactvodQA(Pune) 2018 - Consumer driven contract testing using pact
vodQA(Pune) 2018 - Consumer driven contract testing using pactvodQA
 
Consumer-Driven Contract Testing - Workshop - January 2021
Consumer-Driven Contract Testing - Workshop - January 2021Consumer-Driven Contract Testing - Workshop - January 2021
Consumer-Driven Contract Testing - Workshop - January 2021Paulo Clavijo
 
Collaborative Contract Driven Development
Collaborative Contract Driven DevelopmentCollaborative Contract Driven Development
Collaborative Contract Driven DevelopmentBilly Korando
 
TDD for APIs in a Microservice World (Short Version) by Michael Kuehne-Schlin...
TDD for APIs in a Microservice World (Short Version) by Michael Kuehne-Schlin...TDD for APIs in a Microservice World (Short Version) by Michael Kuehne-Schlin...
TDD for APIs in a Microservice World (Short Version) by Michael Kuehne-Schlin...Michael Kuehne-Schlinkert
 
Consumer Driven Contracts
Consumer Driven ContractsConsumer Driven Contracts
Consumer Driven ContractsVisuality
 
Super slideshow 2
Super slideshow 2Super slideshow 2
Super slideshow 2zhangxw205
 
Microservices. Test smarter, not harder. Voxxed Days 2019
Microservices. Test smarter, not harder. Voxxed Days 2019Microservices. Test smarter, not harder. Voxxed Days 2019
Microservices. Test smarter, not harder. Voxxed Days 2019Beth Skurrie
 
Fed London - January 2015
Fed London - January 2015Fed London - January 2015
Fed London - January 2015Phil Leggetter
 
Contract testing | Евгений Кузьмин | CODEiD
Contract testing | Евгений Кузьмин | CODEiDContract testing | Евгений Кузьмин | CODEiD
Contract testing | Евгений Кузьмин | CODEiDCODEiD PHP Community
 
Design and Evolution of APIs in Microservice Architecture
Design and Evolution of APIs in Microservice ArchitectureDesign and Evolution of APIs in Microservice Architecture
Design and Evolution of APIs in Microservice ArchitectureLohika_Odessa_TechTalks
 
Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Cons...
Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Cons...Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Cons...
Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Cons...Peter Sellars
 
Agile Business Conference 2018: Procurement on Disruption by Mirko Kleiner
Agile Business Conference 2018: Procurement on Disruption by Mirko KleinerAgile Business Conference 2018: Procurement on Disruption by Mirko Kleiner
Agile Business Conference 2018: Procurement on Disruption by Mirko KleinerMirko Kleiner
 
Contract Testing
Contract TestingContract Testing
Contract Testingkloia
 
API Design Collaboration
API Design CollaborationAPI Design Collaboration
API Design CollaborationUchit Vyas ☁
 
CI/CD non-breaking changes exercise - Cork Software Crafters - February 2020
CI/CD non-breaking changes exercise - Cork Software Crafters - February 2020CI/CD non-breaking changes exercise - Cork Software Crafters - February 2020
CI/CD non-breaking changes exercise - Cork Software Crafters - February 2020Paulo Clavijo
 
Gengo Jaws Days Tokyo 2014 Presentation
Gengo Jaws Days Tokyo  2014 PresentationGengo Jaws Days Tokyo  2014 Presentation
Gengo Jaws Days Tokyo 2014 PresentationDerek Szydlowski
 
OpenAPI Spec at Google (Open API Initiative Meetup on 2016-09-15)
OpenAPI Spec at Google (Open API Initiative Meetup on 2016-09-15)OpenAPI Spec at Google (Open API Initiative Meetup on 2016-09-15)
OpenAPI Spec at Google (Open API Initiative Meetup on 2016-09-15)Open API Initiative (OAI)
 
apidays LIVE Paris 2021 - Building an Accessible API Spec with Traditional En...
apidays LIVE Paris 2021 - Building an Accessible API Spec with Traditional En...apidays LIVE Paris 2021 - Building an Accessible API Spec with Traditional En...
apidays LIVE Paris 2021 - Building an Accessible API Spec with Traditional En...apidays
 
[API World 2021 ] - Understanding Cloud Native Deployment
[API World 2021 ] - Understanding Cloud Native Deployment[API World 2021 ] - Understanding Cloud Native Deployment
[API World 2021 ] - Understanding Cloud Native DeploymentWSO2
 

What's hot (20)

Consumer-Driven Contract Testing
Consumer-Driven Contract TestingConsumer-Driven Contract Testing
Consumer-Driven Contract Testing
 
vodQA(Pune) 2018 - Consumer driven contract testing using pact
vodQA(Pune) 2018 - Consumer driven contract testing using pactvodQA(Pune) 2018 - Consumer driven contract testing using pact
vodQA(Pune) 2018 - Consumer driven contract testing using pact
 
Consumer-Driven Contract Testing - Workshop - January 2021
Consumer-Driven Contract Testing - Workshop - January 2021Consumer-Driven Contract Testing - Workshop - January 2021
Consumer-Driven Contract Testing - Workshop - January 2021
 
Collaborative Contract Driven Development
Collaborative Contract Driven DevelopmentCollaborative Contract Driven Development
Collaborative Contract Driven Development
 
TDD for APIs in a Microservice World (Short Version) by Michael Kuehne-Schlin...
TDD for APIs in a Microservice World (Short Version) by Michael Kuehne-Schlin...TDD for APIs in a Microservice World (Short Version) by Michael Kuehne-Schlin...
TDD for APIs in a Microservice World (Short Version) by Michael Kuehne-Schlin...
 
Consumer Driven Contracts
Consumer Driven ContractsConsumer Driven Contracts
Consumer Driven Contracts
 
Super slideshow 2
Super slideshow 2Super slideshow 2
Super slideshow 2
 
Microservices. Test smarter, not harder. Voxxed Days 2019
Microservices. Test smarter, not harder. Voxxed Days 2019Microservices. Test smarter, not harder. Voxxed Days 2019
Microservices. Test smarter, not harder. Voxxed Days 2019
 
Fed London - January 2015
Fed London - January 2015Fed London - January 2015
Fed London - January 2015
 
Contract testing | Евгений Кузьмин | CODEiD
Contract testing | Евгений Кузьмин | CODEiDContract testing | Евгений Кузьмин | CODEiD
Contract testing | Евгений Кузьмин | CODEiD
 
Design and Evolution of APIs in Microservice Architecture
Design and Evolution of APIs in Microservice ArchitectureDesign and Evolution of APIs in Microservice Architecture
Design and Evolution of APIs in Microservice Architecture
 
Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Cons...
Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Cons...Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Cons...
Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Cons...
 
Agile Business Conference 2018: Procurement on Disruption by Mirko Kleiner
Agile Business Conference 2018: Procurement on Disruption by Mirko KleinerAgile Business Conference 2018: Procurement on Disruption by Mirko Kleiner
Agile Business Conference 2018: Procurement on Disruption by Mirko Kleiner
 
Contract Testing
Contract TestingContract Testing
Contract Testing
 
API Design Collaboration
API Design CollaborationAPI Design Collaboration
API Design Collaboration
 
CI/CD non-breaking changes exercise - Cork Software Crafters - February 2020
CI/CD non-breaking changes exercise - Cork Software Crafters - February 2020CI/CD non-breaking changes exercise - Cork Software Crafters - February 2020
CI/CD non-breaking changes exercise - Cork Software Crafters - February 2020
 
Gengo Jaws Days Tokyo 2014 Presentation
Gengo Jaws Days Tokyo  2014 PresentationGengo Jaws Days Tokyo  2014 Presentation
Gengo Jaws Days Tokyo 2014 Presentation
 
OpenAPI Spec at Google (Open API Initiative Meetup on 2016-09-15)
OpenAPI Spec at Google (Open API Initiative Meetup on 2016-09-15)OpenAPI Spec at Google (Open API Initiative Meetup on 2016-09-15)
OpenAPI Spec at Google (Open API Initiative Meetup on 2016-09-15)
 
apidays LIVE Paris 2021 - Building an Accessible API Spec with Traditional En...
apidays LIVE Paris 2021 - Building an Accessible API Spec with Traditional En...apidays LIVE Paris 2021 - Building an Accessible API Spec with Traditional En...
apidays LIVE Paris 2021 - Building an Accessible API Spec with Traditional En...
 
[API World 2021 ] - Understanding Cloud Native Deployment
[API World 2021 ] - Understanding Cloud Native Deployment[API World 2021 ] - Understanding Cloud Native Deployment
[API World 2021 ] - Understanding Cloud Native Deployment
 

Similar to Consumer-driven contracts with Pact and PHP

"Asynchronous" Integration Tests for Microservices - RootConf 2017
"Asynchronous" Integration Tests for Microservices - RootConf 2017"Asynchronous" Integration Tests for Microservices - RootConf 2017
"Asynchronous" Integration Tests for Microservices - RootConf 2017Ramya Authappan
 
Consumer Driven Contracts - A Deep Dive
Consumer Driven Contracts - A Deep DiveConsumer Driven Contracts - A Deep Dive
Consumer Driven Contracts - A Deep DiveRamya Authappan
 
APIdays Helsinki 2019 - Beyond REST: GraphQL API Management with Amit Acharya...
APIdays Helsinki 2019 - Beyond REST: GraphQL API Management with Amit Acharya...APIdays Helsinki 2019 - Beyond REST: GraphQL API Management with Amit Acharya...
APIdays Helsinki 2019 - Beyond REST: GraphQL API Management with Amit Acharya...apidays
 
APIdays Helsinki 2019 - GraphQL API Management with Amit P. Acharya, IBM
APIdays Helsinki 2019 - GraphQL API Management with Amit P. Acharya, IBMAPIdays Helsinki 2019 - GraphQL API Management with Amit P. Acharya, IBM
APIdays Helsinki 2019 - GraphQL API Management with Amit P. Acharya, IBMapidays
 
Brushing skills on SignalR for ASP.NET developers
Brushing skills on SignalR for ASP.NET developersBrushing skills on SignalR for ASP.NET developers
Brushing skills on SignalR for ASP.NET developersONE BCG
 
SRV418 Deep Dive on Accelerating Content, APIs, and Applications with Amazon ...
SRV418 Deep Dive on Accelerating Content, APIs, and Applications with Amazon ...SRV418 Deep Dive on Accelerating Content, APIs, and Applications with Amazon ...
SRV418 Deep Dive on Accelerating Content, APIs, and Applications with Amazon ...Amazon Web Services
 
ATAGTR2017 CDC Tests - Integration Tests cant be made simpler than this!
ATAGTR2017 CDC Tests - Integration Tests cant be made simpler than this!ATAGTR2017 CDC Tests - Integration Tests cant be made simpler than this!
ATAGTR2017 CDC Tests - Integration Tests cant be made simpler than this!Agile Testing Alliance
 
MongoDB.local Dallas 2019: Pissing Off IT and Delivery: A Tale of 2 ODS's
MongoDB.local Dallas 2019: Pissing Off IT and Delivery: A Tale of 2 ODS'sMongoDB.local Dallas 2019: Pissing Off IT and Delivery: A Tale of 2 ODS's
MongoDB.local Dallas 2019: Pissing Off IT and Delivery: A Tale of 2 ODS'sMongoDB
 
CDC Tests - Integration Tests cant be made simpler than this!
CDC Tests - Integration Tests cant be made simpler than this!CDC Tests - Integration Tests cant be made simpler than this!
CDC Tests - Integration Tests cant be made simpler than this!Ramya Authappan
 
MongoDB Stich Overview
MongoDB Stich OverviewMongoDB Stich Overview
MongoDB Stich OverviewMongoDB
 
How Disney Streaming Services and TrueCar Deliver Web Applications for Scale,...
How Disney Streaming Services and TrueCar Deliver Web Applications for Scale,...How Disney Streaming Services and TrueCar Deliver Web Applications for Scale,...
How Disney Streaming Services and TrueCar Deliver Web Applications for Scale,...Amazon Web Services
 
The case for consumer-driven contracts
The case for consumer-driven contractsThe case for consumer-driven contracts
The case for consumer-driven contractsDiUS
 
Event-Based API Patterns and Practices
Event-Based API Patterns and PracticesEvent-Based API Patterns and Practices
Event-Based API Patterns and PracticesLaunchAny
 
Spring Cloud: API gateway upgrade & configuration in the cloud
Spring Cloud: API gateway upgrade & configuration in the cloudSpring Cloud: API gateway upgrade & configuration in the cloud
Spring Cloud: API gateway upgrade & configuration in the cloudOrkhan Gasimov
 
REST API 20.2 - Appworks Gateway Integration.pptx
REST API 20.2 - Appworks Gateway Integration.pptxREST API 20.2 - Appworks Gateway Integration.pptx
REST API 20.2 - Appworks Gateway Integration.pptxJason452803
 
Saving Money by Optimizing Your Cloud Add-On Infrastructure
Saving Money by Optimizing Your Cloud Add-On InfrastructureSaving Money by Optimizing Your Cloud Add-On Infrastructure
Saving Money by Optimizing Your Cloud Add-On InfrastructureAtlassian
 
Generating Unified APIs with Protocol Buffers and gRPC
Generating Unified APIs with Protocol Buffers and gRPCGenerating Unified APIs with Protocol Buffers and gRPC
Generating Unified APIs with Protocol Buffers and gRPCC4Media
 
Move fast and consumer driven contract test things
Move fast and consumer driven contract test thingsMove fast and consumer driven contract test things
Move fast and consumer driven contract test thingsAlon Pe'er
 

Similar to Consumer-driven contracts with Pact and PHP (20)

"Asynchronous" Integration Tests for Microservices - RootConf 2017
"Asynchronous" Integration Tests for Microservices - RootConf 2017"Asynchronous" Integration Tests for Microservices - RootConf 2017
"Asynchronous" Integration Tests for Microservices - RootConf 2017
 
Consumer Driven Contracts - A Deep Dive
Consumer Driven Contracts - A Deep DiveConsumer Driven Contracts - A Deep Dive
Consumer Driven Contracts - A Deep Dive
 
Mastering the api hell
Mastering the api hellMastering the api hell
Mastering the api hell
 
APIdays Helsinki 2019 - Beyond REST: GraphQL API Management with Amit Acharya...
APIdays Helsinki 2019 - Beyond REST: GraphQL API Management with Amit Acharya...APIdays Helsinki 2019 - Beyond REST: GraphQL API Management with Amit Acharya...
APIdays Helsinki 2019 - Beyond REST: GraphQL API Management with Amit Acharya...
 
APIdays Helsinki 2019 - GraphQL API Management with Amit P. Acharya, IBM
APIdays Helsinki 2019 - GraphQL API Management with Amit P. Acharya, IBMAPIdays Helsinki 2019 - GraphQL API Management with Amit P. Acharya, IBM
APIdays Helsinki 2019 - GraphQL API Management with Amit P. Acharya, IBM
 
Brushing skills on SignalR for ASP.NET developers
Brushing skills on SignalR for ASP.NET developersBrushing skills on SignalR for ASP.NET developers
Brushing skills on SignalR for ASP.NET developers
 
SRV418 Deep Dive on Accelerating Content, APIs, and Applications with Amazon ...
SRV418 Deep Dive on Accelerating Content, APIs, and Applications with Amazon ...SRV418 Deep Dive on Accelerating Content, APIs, and Applications with Amazon ...
SRV418 Deep Dive on Accelerating Content, APIs, and Applications with Amazon ...
 
ATAGTR2017 CDC Tests - Integration Tests cant be made simpler than this!
ATAGTR2017 CDC Tests - Integration Tests cant be made simpler than this!ATAGTR2017 CDC Tests - Integration Tests cant be made simpler than this!
ATAGTR2017 CDC Tests - Integration Tests cant be made simpler than this!
 
MongoDB.local Dallas 2019: Pissing Off IT and Delivery: A Tale of 2 ODS's
MongoDB.local Dallas 2019: Pissing Off IT and Delivery: A Tale of 2 ODS'sMongoDB.local Dallas 2019: Pissing Off IT and Delivery: A Tale of 2 ODS's
MongoDB.local Dallas 2019: Pissing Off IT and Delivery: A Tale of 2 ODS's
 
CDC Tests - Integration Tests cant be made simpler than this!
CDC Tests - Integration Tests cant be made simpler than this!CDC Tests - Integration Tests cant be made simpler than this!
CDC Tests - Integration Tests cant be made simpler than this!
 
MongoDB Stich Overview
MongoDB Stich OverviewMongoDB Stich Overview
MongoDB Stich Overview
 
How Disney Streaming Services and TrueCar Deliver Web Applications for Scale,...
How Disney Streaming Services and TrueCar Deliver Web Applications for Scale,...How Disney Streaming Services and TrueCar Deliver Web Applications for Scale,...
How Disney Streaming Services and TrueCar Deliver Web Applications for Scale,...
 
The case for consumer-driven contracts
The case for consumer-driven contractsThe case for consumer-driven contracts
The case for consumer-driven contracts
 
Event-Based API Patterns and Practices
Event-Based API Patterns and PracticesEvent-Based API Patterns and Practices
Event-Based API Patterns and Practices
 
Spring Cloud: API gateway upgrade & configuration in the cloud
Spring Cloud: API gateway upgrade & configuration in the cloudSpring Cloud: API gateway upgrade & configuration in the cloud
Spring Cloud: API gateway upgrade & configuration in the cloud
 
Servlet
ServletServlet
Servlet
 
REST API 20.2 - Appworks Gateway Integration.pptx
REST API 20.2 - Appworks Gateway Integration.pptxREST API 20.2 - Appworks Gateway Integration.pptx
REST API 20.2 - Appworks Gateway Integration.pptx
 
Saving Money by Optimizing Your Cloud Add-On Infrastructure
Saving Money by Optimizing Your Cloud Add-On InfrastructureSaving Money by Optimizing Your Cloud Add-On Infrastructure
Saving Money by Optimizing Your Cloud Add-On Infrastructure
 
Generating Unified APIs with Protocol Buffers and gRPC
Generating Unified APIs with Protocol Buffers and gRPCGenerating Unified APIs with Protocol Buffers and gRPC
Generating Unified APIs with Protocol Buffers and gRPC
 
Move fast and consumer driven contract test things
Move fast and consumer driven contract test thingsMove fast and consumer driven contract test things
Move fast and consumer driven contract test things
 

Recently uploaded

Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 

Recently uploaded (20)

Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 

Consumer-driven contracts with Pact and PHP

  • 2. @andykelk | #SydPHP provider consumer 1 consumer 2 consumer 3 { status: “ok”, count: 20, items: [ { id: 10000, name: ... Providers and consumers
  • 3. @andykelk | #SydPHP Consumer-driven contracts • In a service oriented architecture, a service provider typically has many consumers. • Each of those consumers has expectations about the service. • Over time, consumer expectations change and the provider must evolve to meet them. • Standard approaches to this introduce interdependence into the relationship. • The Consumer-Driven Contracts pattern solves that.
  • 4. @andykelk | #SydPHP Consumer-driven contracts provider consumer 1 consumer 2 consumer 3 { status: “ok”, count: 20, items: [ { id: 10000, name: ...
  • 5. @andykelk | #SydPHP Pact • Ruby gem which implements automated testing for consumer-driven contracts • There are also implementations for • .Net (Provider, Consumer) • JVM (Provider, Consumer) • JavaScript (Provider, Consumer) • Swift (Consumer)
  • 7. @andykelk | #SydPHP Pact • BUT… no PHP implementation 😞 • Luckily we can use the Provider Proxy to help us test a PHP service provider
  • 8. @andykelk | #SydPHP JavaScript Consumer Jasmine PhantomJS PAC T Karma Test framework/ Test runner Browser (headless) Mock/contract endpoint App code (HTTP client, model) Production code exercise s invokes via socket creates pact json file
  • 9. @andykelk | #SydPHP beforeEach(function() { client = ZooClient.createClient('http://localhost:1234'); alligatorProvider = Pact.mockService({ consumer: 'Alligator Consumer', provider: 'Alligator Provider', port: 1234, done: function (error) { expect(error).toBe(null); } }); }); Setting up a JavaScript consumer
  • 10. @andykelk | #SydPHP Setting up a JavaScript consumer it("should return an alligator", function(done) { 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(done, function(runComplete) { expect(client.getAlligatorByName("Mary")).toEqual(new Alligator("Mary")); runComplete(); }); });
  • 11. @andykelk | #SydPHP Now we have a pact { "consumer": { "name": "Alligator Consumer" }, "provider": { "name": "Alligator Provider" }, "interactions": [ { "description": "a request for an alligator", "provider_state": "an alligator with the name Mary exists", "request": { "method": "get", "path": "/alligators/Mary", "headers": { "Accept": "application/json" } }, "response": { "status": 200, "headers": { "Content-Type": "application/json" }, "body": { "name": "Mary" } } } ], "metadata": { "pactSpecificationVersion": "1.0.0" } }
  • 12. @andykelk | #SydPHP PHP Provider Rake PAC T prox y Test framework/ Test runner Mock/contract endpoint App code (service provider) Production code invokes pact json file reads
  • 13. @andykelk | #SydPHP Create the API provider <?php require 'vendor/autoload.php'; $app = new SlimSlim(); $app->get('/alligators/:name', function ($name) use ($app) { $app->response->setStatus(200); $app->response()->headers->set('Content-Type', 'application/json'); echo json_encode(array('name' => $name)); }); $app->run();
  • 14. @andykelk | #SydPHP Use rake and pact provider proxy to test require 'pact/provider/proxy/tasks' Pact::ProxyVerificationTask.new :alligator do | task | task.pact_url './spec/pacts/alligator_consumer-alligator_provider.json', :pact_helper => './spec/support/alligator_pact_helper' task.provider_base_url 'http://localhost:8000' end Pact.provider_states_for "Alligator Consumer" do provider_state "an alligator with the name Mary exists" do set_up do # Set-up the provider state (e.g. create fixture) here end end end
  • 16. @andykelk | #SydPHP What’s next? • PHP implementation of the pact specification • Use pact broker to share pact files and provide: • Auto-generated documentation • Dynamically generated network diagrams • The ability to tag a pact (ie. "prod") so a provider can verify itself against a fixed version of a pact to ensure backwards compatibility. • Webhooks to trigger provider builds when a pact is published.
  • 17. @andykelk | #SydPHP Questions? • Further reading: • http://martinfowler.com/articles/consumerDrivenContracts.html • https://github.com/realestate-com-au/pact • http://techblog.realestate.com.au/testing-interactions-with-web-services- without-integration-tests-in-ruby/ • http://techblog.realestate.com.au/enter-the-pact-matrix-or-how-to- decouple-the-release-cycles-of-your-microservices/ • Code from the demo: • https://github.com/mopoke/pact-php-demo • Relive this talk in blog form: • http://www.andykelk.net/tech/consumer-driven-contracts-with-pact-and- php