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

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
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
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
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
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
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
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
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
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
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
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 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