Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Contract Testing Php-pact

799 views

Published on

Contract Testing PHP

Published in: Engineering
  • Be the first to comment

Contract Testing Php-pact

  1. 1. INTEGRATIONINTEGRATION CONTRACT TESTINGCONTRACT TESTING
  2. 2. ABOUT MEABOUT ME DANIELE D'ANGELIDANIELE D'ANGELI @DANGELIDANIELE@DANGELIDANIELE HTTP://DANIELEDANGELI.COMHTTP://DANIELEDANGELI.COM BORN AND RAISED IN ROMEBORN AND RAISED IN ROME 2 YEARS IN LONDON2 YEARS IN LONDON ACTUALLY I'M WORKING WITHACTUALLY I'M WORKING WITH @ADESPRESSO, IN ROME WITH@ADESPRESSO, IN ROME WITH
  3. 3. ... FROM A PREVIOUS... FROM A PREVIOUS PRESENTATION OFPRESENTATION OF MINEMINE
  4. 4. WHAT WE'RE TALKINGWHAT WE'RE TALKING ABOUTABOUT
  5. 5. ..WHATWHAT .HOW.HOW .HOW ABOUT NEXT.HOW ABOUT NEXT CONSUMER DRIVENCONSUMER DRIVEN CONTRACT TESTINGCONTRACT TESTING
  6. 6. ...WEB APPLICATION...WEB APPLICATION
  7. 7. ...WEB APPLICATION TODAY...WEB APPLICATION TODAY
  8. 8. HTTP APIHTTP API
  9. 9. HOW OUR SYSTEMS LOOKSHOW OUR SYSTEMS LOOKS LIKE?LIKE?
  10. 10. ... AT VERY LEAST... AT VERY LEAST
  11. 11. ... A STEP FORWARD... A STEP FORWARD
  12. 12. TESTING STRATEGIESTESTING STRATEGIES CONFIDENCECONFIDENCE FASTER&EASYFASTER&EASY
  13. 13. ISOLATIONISOLATION
  14. 14. INDEPENDENTINDEPENDENT UNIT TESTUNIT TEST TRIVIALTRIVIAL
  15. 15. FUNCTIONAL TESTFUNCTIONAL TEST ISOLATED FROMISOLATED FROM EXTERNALEXTERNAL DEPENDENCIESDEPENDENCIES
  16. 16. STUBBING EXTERNALSTUBBING EXTERNAL RESPONSES!RESPONSES!
  17. 17. CONSUMERCONSUMER PROVIDERPROVIDER REMOTE BOUNDARYREMOTE BOUNDARY STUBSSTUBS
  18. 18. Remember! HTTP IS AHTTP IS A PROTOCOLPROTOCOL
  19. 19. Remember! A NETWORK PROTOCOL DEFINES RULES TO ALLOWING INTERACTIONS BETWEEN TWO PARTS
  20. 20. IT'S A GOOD STUBBING?IT'S A GOOD STUBBING? WHO ENSURE?WHO ENSURE?
  21. 21. IT'S A GOOD INTERACTION?IT'S A GOOD INTERACTION? WHO ENSURE?WHO ENSURE?
  22. 22. NO ONENO ONE
  23. 23. TOO OFTEN THISTOO OFTEN THIS PROCESS IS DRIVENPROCESS IS DRIVEN BYBY HUMANSHUMANS
  24. 24. INTEGRATION TESTINGINTEGRATION TESTING
  25. 25. CONSUMERCONSUMER END 2 END TESTINGEND 2 END TESTING PROVIDERPROVIDER
  26. 26. ...WEB APPLICATION TODAY...WEB APPLICATION TODAY
  27. 27. CONSUMERCONSUMER END 2 END TESTING (...TODAY)END 2 END TESTING (...TODAY) PROVIDERPROVIDER & CONSUMERCONSUMER PROVIDERPROVIDER & CONSUMERCONSUMER PROVIDERPROVIDER & CONSUMERCONSUMER
  28. 28. STRENGHTSSTRENGHTS
  29. 29. WEAKNESSWEAKNESS HARD TO TEST IN DEV ENVHARD TO TEST IN DEV ENV SLOWSLOW HARD TO WRITEHARD TO WRITE HARD TO SETUPHARD TO SETUP
  30. 30. INTEGRATIONINTEGRATION CONTRACT TESTINGCONTRACT TESTING (CONSUMER DRIVEN)(CONSUMER DRIVEN)
  31. 31. ... FROM MARTIN FOWLER... FROM MARTIN FOWLER HTTP://MARTINFOWLER.COM/BLIKI/INTEGRATIOHTTP://MARTINFOWLER.COM/BLIKI/INTEGRATIO NCONTRACTTEST.HTMLNCONTRACTTEST.HTML
  32. 32. Remember! TESTTEST DOUBLEDOUBLE IS A GENERIC TERM FORIS A GENERIC TERM FOR ANY CASE WHERE YOU REPLACE AANY CASE WHERE YOU REPLACE A PRODUCTION OBJECT FOR TESTINGPRODUCTION OBJECT FOR TESTING PURPOSES.PURPOSES. ... FROM MARTIN FOWLER... FROM MARTIN FOWLER
  33. 33. ... FROM MARTIN FOWLER... FROM MARTIN FOWLER RUN YOUR CONSUMER TESTS AGAINSTRUN YOUR CONSUMER TESTS AGAINST A TESTA TEST DOUBLEDOUBLE
  34. 34. RECORD CONSUMERRECORD CONSUMER EXPECTATIONSEXPECTATIONS
  35. 35. VERIFYVERIFY EXPECTATIONS ONEXPECTATIONS ON PROVIDERPROVIDER
  36. 36. HTTPS://GITHUB.COM/REALESTATE-COM-AU/PACTHTTPS://GITHUB.COM/REALESTATE-COM-AU/PACT PACTPACT RUBY IMPLEMENTATIONRUBY IMPLEMENTATION​​ STUBBING AND VERIFYSTUBBING AND VERIFY CONSUMER CONTRACTSCONSUMER CONTRACTS
  37. 37. PACTPACT WORKING WELLWORKING WELL SPECIALLY FOR RUBYSPECIALLY FOR RUBY PROJECTSPROJECTS HTTPS://GITHUB.COM/REALESTATE-COM-AU/PACTHTTPS://GITHUB.COM/REALESTATE-COM-AU/PACT
  38. 38. PACTPACT HTTPS://GITHUB.COM/SEEK-JOBS/PACT-GOHTTPS://GITHUB.COM/SEEK-JOBS/PACT-GO HTTPS://GITHUB.COM/SEEK-JOBS/PACT-NETHTTPS://GITHUB.COM/SEEK-JOBS/PACT-NET​​ HTTPS://GITHUB.COM/DIUS/PACT-JVMHTTPS://GITHUB.COM/DIUS/PACT-JVM HTTPS://GITHUB.COM/REALESTATE-COM-AU/PACTHTTPS://GITHUB.COM/REALESTATE-COM-AU/PACT
  39. 39. Consumer
  40. 40. ProvidersCONSUMERCONSUMER RUNS TEST LOCALLYRUNS TEST LOCALLY
  41. 41. RUNS TEST LOCALLYRUNS TEST LOCALLY Providers STUB, CREATE ANDSTUB, CREATE AND GENERATEGENERATE CONTRACTSCONTRACTS CONSUMERCONSUMER PROVIDERPROVIDER
  42. 42. CONSUMERCONSUMER RUNS TEST LOCALLYRUNS TEST LOCALLY Providers PROVIDERPROVIDER STUBBING, CREATE ANDSTUBBING, CREATE AND GENERATEGENERATE CONTRACTSCONTRACTS SAVESAVE CONTRACTSCONTRACTS SOMEWHERESOMEWHERE
  43. 43. ARTIFACTSARTIFACTS { "consumer": { "name": "collaborator client" }, "provider": { "name": "collaborator api" }, "interactions": [ { "provider_state": "there is a collaborator with id 23", "description": "get collaborator", "request": { "headers": { "Accept": "application/json" }, "method": "GET", "path": "/collaborators/23" }, "response": { "body": { "name": "John", "role": "Client Relantionship" }, "headers": { "Content-Type": "application/json" }, "status": 200 } }, ... }
  44. 44. LOAD CONTRACTSLOAD CONTRACTS PROVIDERPROVIDER
  45. 45. FOREACH CONTRACTFOREACH CONTRACT 1. SET UP WORKING STATESET UP WORKING STATE (DATABASE AND EXTERNAL(DATABASE AND EXTERNAL DEPENDENCIES)DEPENDENCIES) PROVIDERPROVIDER LOAD CONTRACTSLOAD CONTRACTS
  46. 46. 1. SET UP WORKING STATESET UP WORKING STATE (DATABASE AND EXTERNAL(DATABASE AND EXTERNAL DEPENDENCIES)DEPENDENCIES) 2. MAKE INTERNAL HTTP CALLMAKE INTERNAL HTTP CALL (BASED ON CONTRACT)(BASED ON CONTRACT) LOAD CONTRACTSLOAD CONTRACTS FOREACH CONTRACTFOREACH CONTRACT PROVIDERPROVIDER
  47. 47. 1. SET UP WORKING STATESET UP WORKING STATE (DATABASE AND EXTERNAL(DATABASE AND EXTERNAL DEPENDENCIES)DEPENDENCIES) 2. MAKE INTERNAL HTTP CALLMAKE INTERNAL HTTP CALL (BASED ON CONTRACT)(BASED ON CONTRACT) 3. VERIFY RESPONSEVERIFY RESPONSE FOREACH CONTRACTFOREACH CONTRACT LOAD CONTRACTSLOAD CONTRACTS PROVIDERPROVIDER
  48. 48. PACTPACT INTEROPERABILITYINTEROPERABILITY
  49. 49. HOW ABOUT PHP?HOW ABOUT PHP?
  50. 50. OOPS! SOME ERRORS COULDOOPS! SOME ERRORS COULD OCCURS...OCCURS... LET ME TRY LIVELET ME TRY LIVE CODING...CODING...
  51. 51. PACT-PHP [PROVIDER]PACT-PHP [PROVIDER] PARSE CONTRACTSPARSE CONTRACTS LOAD STATELOAD STATE PARSE AND CREATEPARSE AND CREATE PSR7PSR7 REQUESTREQUEST PROVIDER APIPROVIDER API CREATECREATE PSR7PSR7 RESPONSERESPONSE VERIFY EXPECTEDVERIFY EXPECTED PSR7PSR7 RESPONSERESPONSE
  52. 52. PACT-PHP [PROVIDER]PACT-PHP [PROVIDER] /** * @param Closure $makeRequest How make a ps7Request * @param Closure $setUp Setup the test state * @param Closure $tearDown Setup up back the state */ public function honorContracts( Closure $makeRequest, Closure $setUp, Closure $tearDown ) FRAMEWORK INDEPENDENTFRAMEWORK INDEPENDENT
  53. 53. RECAPRECAP CONSUMER DRIVENCONSUMER DRIVEN CONTRACT TEST IS ANCONTRACT TEST IS AN ALTERNATIVE TO END TOALTERNATIVE TO END TO END TESTEND TEST
  54. 54. WHENWHEN SOA/MICROSERVICESSOA/MICROSERVICES ARCHITECTUREARCHITECTURE ONLY WHEN YOU REALLYONLY WHEN YOU REALLY NEED ITNEED IT
  55. 55. PACTO-PHPPACTO-PHP IMPROVE SERVICEIMPROVE SERVICE PROVIDERPROVIDER
  56. 56. PACTO-PHPPACTO-PHP IMPLEMENT CONSUMERIMPLEMENT CONSUMER SIDESIDE Integration with Guzzle?
  57. 57. THANKSTHANKS

×