09 - marco lopes - driving your domain by examples · 2016-05-10 · developersparadise 2016 /...

63
Sample Title Developers Paradise 2016 / Opatija / Croatia Driving your domain by examples Optional short description of theme

Upload: others

Post on 11-Jul-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

Sample Title

DevelopersParadise2016 / Opatija / Croatia

Driving your domain by examples Optional short description of theme

Page 2: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

Marco LopesSenior Software Engineer - Session Digital

@mpmlopes

Page 3: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

Once upon a time…

Page 4: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

Everything changes

Page 5: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

PANIC! NOW!

Page 6: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

Why does it happen?

Page 7: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

Short feedback cycle

Page 8: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

Short feedback cycle AKA Agile

Page 9: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

Can we do more?

Page 10: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

Shorten feedback cycle

Page 11: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

BDD

Page 12: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

Behat & PHPSpec

Page 13: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

Modelling by Example

Page 14: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

Domain Suite

Page 15: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

Scenario: Paying with a credit card Given AwesomePay has credit card payments enabled When I fill the credit card number with 4444333322221111 And I fill the expiry date with ”04/2018” And I fill the CCV with 123 And the credit card has unlimited funds on payment gateway And I press place order button Then the payment should be accepted And the magento order status should be ”processing”

Page 16: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

Scenario: Paying with a credit card Given AwesomePay has credit card payments enabled When I fill the credit card number with 4444333322221111 And I fill the expiry date with ”04/2018” And I fill the CCV with 123 And the credit card has unlimited funds on payment gateway Then the payment should be accepted And the magento order status should be ”processing”

Page 17: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

Scenario: Paying with a credit card Given AwesomePay has credit card payments enabled When I have credit card 4444333322221111 And the credit card has unlimited funds on payment gateway Then the payment should be accepted And the magento order status should be ”processing”

Page 18: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

Scenario: Paying with a credit card Given AwesomePay has credit card payments enabled And I have credit card 4444333322221111 And the credit card has unlimited funds on payment gateway When I pay £42 using that credit card Then the payment should be accepted And the magento order status should be ”processing”

Page 19: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

Scenario: Paying with a credit card Given the payment gateway has credit card payments enabled And I have credit card 4444333322221111 And the credit card has unlimited funds on payment gateway When I pay £42 using that credit card Then the payment should be accepted And the magento order status should be ”processing”

Page 20: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

AwesomePay

Magento

Interfaces

Interfaces

Domain

Page 21: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

Scenario: Paying with a credit card Given the payment gateway has credit card payments enabled And I have credit card 4444333322221111 And the credit card has unlimited funds on payment gateway When I pay £42 using that credit card Then the payment should be accepted And the magento order status should be ”processing”

Page 22: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

Scenario: Paying with a credit card Given the payment gateway has credit card payments enabled And I have credit card 4444333322221111 And the credit card has unlimited funds on payment gateway When I pay £42 using that credit card Then the payment should be accepted

Page 23: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

/** * @Given the payment gateway has credit card payments enabled */ public function thePaymentGatewayHasCreditCardPaymentsEnabled(){ $this->paymentGateway = new FakePaymentGateway(); expect( $this->paymentGateway->HasCreditCardPaymentsEnabled() )->toBe(true); }

Page 24: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

/** * @Given I have credit card :aCreditCard */ public function iHaveCreditCard(CreditCard $aCreditCard){ $this->creditCard = $aCreditCard; }

Page 25: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

/** * @Transform :aCreditCard */ public function transformNumberToCreditCard($cardNumber){ return CreditCard::fromNumber($cardNumber); }

Page 26: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

CreditCard::fromNumber($cardNumber);

Named Constructor

Page 27: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

/** * @Given the credit card has unlimited funds on payment gateway */ public function theCreditCardHasUnlimitedFundsOnPaymentGateway(){ $this->paymentGateway->cardHasUnlimitedCredit( $this->creditCard ); }

Page 28: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

Scenario: Paying with a credit card Given the payment gateway has credit card payments enabled And I have credit card 4444333322221111 And the credit card has unlimited funds on payment gateway When I pay £42 using that credit card Then the payment should be accepted

Page 29: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

Scenario: Paying with a credit card Given the payment gateway has credit card payments enabled And I have credit card 4444333322221111 And the payment gateway has unlimited credit for that card When I pay £42 using that credit card Then the payment should be accepted

Page 30: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

/** * @Given the payment gateway has unlimited credit for that card */ public function thePaymentGatewayHasUnlimitedCreditForThatCard(){ $this->paymentGateway->hasUnlimitedCreditFor( $this->creditCard ); }

Page 31: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

Code closer to the business language

Page 32: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

Code changes when business changes

Page 33: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

Emergent design

Page 34: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

Decoupling

Page 35: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

AwesomePay

Magento

Interfaces

Interfaces

Domain

Page 36: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

AwesomePay

Magento 2

Interfaces

Interfaces

Domain

Page 37: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

AwesomePay

Magento 2

Interfaces

Interfaces

Domain

Page 38: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

AwesomePay

Symfony Application

Interfaces

Interfaces

Domain

Page 39: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

Mitigates communication problems

Page 40: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

Easier development

Page 41: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

Docs for free

Page 42: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

Test for free

Page 43: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

Easier QA

Page 44: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

Respond to change

Page 45: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

Speaking by experience

Page 46: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

How about e2e tests?

Page 47: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

default: suites: domain: contexts: [DomainContext]

Page 48: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

default: suites: domain: contexts: [DomainContext] web: contexts: [WebContext] filters: { tags: '@web' }

Page 49: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

default: suites: domain: contexts: [DomainContext] filters: { tags: '~@ui' } web: contexts: [WebContext] filters: { tags: '@web' }

Page 50: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

default: suites: domain: contexts: [DomainContext] filters: { tags: '~@ui' } web: contexts: [WebContext] filters: { tags: '@web' } mobile: contexts: [MobileContext] filters: { tags: '@mobile' }

Page 51: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

default: suites: domain: contexts: [DomainContext] filters: { tags: '~@ui' } web: contexts: [WebContext] filters: { tags: '@web' } mobile: contexts: [MobileContext] filters: { tags: '@mobile' } integration: contexts: [IntegrationContext] filters: { tags: '~@ui' }

Page 52: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

In sum

Page 53: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

Bounded domain

Page 54: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

Decoupled parts of our application

Page 55: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

Decoupling from frameworks

Page 56: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

Better understanding of the business domain

Page 57: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

Reduction of communication gaps

Page 58: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

Easier development

Page 59: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

Quicker CI builds

Page 60: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

Easier handover

Page 61: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

“I saw those feature files written by you almost when everything was over. I could not believe myself how much

better it would have been if I have had a chance to see them before starting the QA, as those where mostly the

questions I was trying to get an answer for. Those features and scenarios were very well written and I could easily

understand what the system was trying to achieve. It also gave me thoughts about more edge cases.”

Page 62: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

Questions?

Related Links

http://stakeholderwhisperer.com/posts/2014/10/introducing-modelling-by-exampleIntroducing Modelling by Example

Named Constructors in PHPhttp://verraes.net/2014/06/named-constructors-in-php/

Short Intro to BDD from Konstantin Kudryashovhttps://www.youtube.com/watch?v=njcHzGYv7nI

SocialTwitter: @mpmlopes

Page 63: 09 - Marco Lopes - Driving your domain by examples · 2016-05-10 · DevelopersParadise 2016 / Opatija / Croatia Scenario: Paying with a credit card Given AwesomePay has credit card

DevelopersParadise2016 / Opatija / Croatia

Thank You!