SlideShare a Scribd company logo
1 of 69
Download to read offline
Modelling by Example
Ciaran McNulty at PHPNW 2016
Modelling by Example
BDD + DDD
BDD fundamentals
Behaviour Driven Development
BDD is the art of using examples in
conversa6ons to illustrate behaviour
— Liz Keogh
➡ Input
⬅ Output
➡ Action
⬅ Reaction
➡➡ Actions
➡ Action
⬅ Reaction
Given ➡➡
When ➡
Then ⬅
Given I bought a microwave for £10
When I return the microwave
Then I should be refunded £10
Who writes examples?
Business expert
Tes(ng expert
Development expert
All discussing the feature together
When to write scenarios
• Before you start work on the feature
• Not too long before!
• Whenever you have access to the right people
Refining scenarios
When would this outcome not be true?
Given I bought a microwave for £10
When I return the microwave
Then I should be refunded £10
When would this outcome not be true?
Given I bought a microwave for £10
When I return the microwave with a valid receipt
Then I should be refunded £10
When would this outcome not be true?
Given I bought a microwave for £10
When I return the microwave with a valid receipt
Then I should be refunded £10
Given I bought a microwave for £10
When I try to return the microwave without a valid receipt
Then I should be refunded £10 store credit
What other outcomes are there?
Given I bought a microwave for £10
When I return the microwave with a valid receipt
Then I should be refunded £10
What other outcomes are there?
Given I bought a microwave for £10
When I return the microwave with a valid receipt
Then I should be refunded £10
And the microwave should be returned to stock
When would this outcome not be true?
Given I bought a microwave for £10
When I return the microwave with a valid receipt
Then I should be refunded £10
And the microwave should be returned to stock
When would this outcome not be true?
Given I bought a microwave for £10
When I return the microwave with a valid receipt
And the microwave is not damaged
Then I should be refunded £10
And the microwave should be returned to stock
When would this outcome not be true?
Given I bought a microwave for £10
When I return the microwave with a valid receipt
And the microwave is not damaged
Then I should be refunded £10
And the microwave should be returned to stock
Given I bought a microwave for £10
When I return the microwave with a valid receipt
And the microwave is damaged
Then I should not be refunded
And the microwave should not be returned to stock
Does this implementa)on detail ma+er?
When I go to '/returns'
And I fill in 'form#returns input.product' field with 'microwave'
And hit the 'refund' bu>on
Does this implementa)on detail ma+er?
When I fill in the returns form with the details of the microwave
Does this implementa)on detail ma+er?
When I return the microwave through the website
Does this implementa)on detail ma+er?
When I return the microwave
Examples and rules
• Rules are hard to express and ambiguous
• Examples are very easy to understand
• Examples help us understand the rules
• Examples work best as feedback
Example Mapping
Domain Driven Design
DDD tackles complexity by focusing
the team's a7en8on on knowledge
of the domain
— Eric Evans
Invest (me in
understanding
the business
Ubiquitous Language
• A shared way of speaking about domain concepts
• Reduces the cost of transla.on when business and development
communicate
• Try to establish and use terms the business will understand
Modelling by Example
By embedding Ubiquitous Language
in your scenarios, your scenarios
naturally become your domain
model
— Konstan)n Kudryashov (@everzet)
Principles
• The best way to understand the domain is by discussing
examples
• Write scenarios that capture ubiquitous language
• Write scenarios that illustrate real situa5ons
• Directly drive the code model from those examples
Given I bought a microwave for £10
When I return the microwave with a valid receipt
And the microwave is not damaged
Then I should be refunded £10
And the microwave should be returned to stock
Ask about iden.ty
Given I bought a microwave for £10
When I return the microwave with a valid receipt
And the microwave is not damaged
Then I should be refunded £10
And the microwave should be returned to stock
Ask about iden.ty
Given I bought a microwave with SKU "M100" for £10.00
And was given receipt numbered "ABC1234"
When I return the product with a the same receipt
And the product is not damaged
Then I should be refunded £10
And the producy should be returned to stock
Ask about verbs
Given I bought a microwave with SKU "M100" for £10.00
And was given receipt numbered "ABC1234"
When I return the product with a the same receipt
And the product is not damaged
Then I should be refunded £10
And the producy should be returned to stock
Ask about verbs
Given I purchased a microwave with SKU "M100" for £10.00
And was issued a receipt numbered "ABC1234"
When I return the product with a the same receipt
And the product is not damaged
Then I should be credited £10
And the producy should be returned to stock
Ask "how do we know this is true?"
Given I purchased a microwave with SKU "M100" for £10.00
And was issued a receipt numbered "ABC1234"
When I return the product with a the same receipt
And the product is not damaged
Then I should be credited £10
And the producy should be returned to stock
Ask "how do we know this is true?"
Given I purchased a microwave with SKU "M100" for £10.00
And was issued a receipt numbered "ABC1234"
When I return the product with a the same receipt
And the product passes a damage inspec,on
Then I should be credited £10
And the producy should be returned to stock
Exercise: Improving ubiquitous language
Scenario: Flyer takes a flight and earns points
Given I bought a ticket on a flight
And the flight earns 100 points
When I take the flight
Then I should get 100 points
Scenario: Flyer doesn’t take a flight and doesn’t earn points
Given I bought a ticket on a flight
And the flight earns 100 points
When I don't take the flight
Then I should get 0 points
Scenario: Flyer takes a flight and earns Cuke Miles
Given a ticket was bought on a flight
And it was linked to newly registered loyalty account 2352352
And the flight earns 100 Cuke Miles
When the ticket boards the flight
Then account 2352352 should have 100 Cuke Miles
Scenario: Flyer doesn’t take a flight and doesn’t earn Cuke Miles
Given ticket was bought on a flight
And it was linked to newly registered loyalty account 2352352
And the flight earns 100 Cuke Miles
When the ticket does not board the flight
Then account 2352352 should have 0 Cuke Miles
Background:
Given a ticket was bought on a flight "CK-112"
And it was linked to newly registered loyalty account 2352352
And the "LHR-JFK" route earns 100 Cuke Miles
And flight "CK-112" flies the "LHR-JFK" route
Scenario: Flyer takes a flight and earns Cuke Miles
Given the ticket boarded the flight
When the flight arrives at destination
Then account 2352352 should have 100 Cuke Miles
Scenario: Flyer doesn’t take a flight and doesn’t earn Cuke Miles
Given the ticket did not board the flight
When the flight arrives at destination
Then account 2352352 should have 0 Cuke Miles
Break
Modelling the core
Layered architecture
End-to-end tes*ng with Behat
Tes$ng the UI
• Slow to execute
• Bri/le
• Makes you design the domain and UI at the same <me
Test the domain API first
Tes$ng with real infrastructure
• Slow to execute
• Bri/le
• Makes you design the domain and infrastructure at the same
;me
Test with fake infrastructure first
Behat Fundamentals
Behat
• a tool to test business expecta-ons against an applica-on
• developed by Konstan-n Kudryashov
• based on Cucumber by Aslak Hellesøy
Gherkin
Machine-readable and business-readable format for capturing
scenarios
Features
• One per .feature file
• Describes a set of rules the system should exibit by giving
example scenarios
Feature: Returning a microwave
Scenarios
• Many per feature file
• Give an example to illustrate the expected behaviour
Feature: Returning a microwave
Scenario: Returning undamaged product with receipt
Scenario: …
Steps
• Many per feature file
• Give an example to illustrate the expected behaviour
Feature: Returning a microwave
Scenario: Returning undamaged product with receipt
Given I bought a microwave for £10
When I return the microwave with a valid receipt
And the microwave is not damaged
Then I should be refunded £10
And the microwave should be returned to stock
Step defini*ons
Behat's job is to take each step and map it to executable code
• Given steps -> Code that puts the system in the right state
• When steps -> Code that defines the ac:on we are describing
• Then steps -> Code that verifies the outcome we expect
Step defini*ons
/**
* @given I bought a :product for £:cost
*/
function returnAProduct(string $product, string $cost)
{
$this->productPurchaser->purchase(
new Product($product),
new Cost($cost)
);
}
Modelling the core - key principles
• Iden&fy and use Value Objects
• Iden&fy boundaries, define interfaces, and create fake
implementa&ons
• Match the language used in the steps
Demo
Exercise: Modelling a shopping basket
Feature: Applying VAT and delivery costs to basket
In order to know how much I'm paying
As a customer
I need VAT and cost of delivery to be calculated based on my basket price
Rules:
- VAT is 20%
- Delivery cost for basket greater than £10 is £2
- Delivery cost for basket less than £10 is £3
Scenario: Product costing less than £10 results in delivery cost of £3
Given there is a product with SKU "RS1"
And this product is listed at a cost of £5 in the catalogue
When I add this product to my basket from the catalogue
Then the total cost of my basket should be £9
Exercise: Modelling a shopping basket
Clone from github:
http://github.com/ciaranmcnulty/phpnw16-workshop
Work through the feature and model the core domain using Behat
and PhpSpec.
Key command:
bin/phpspec run && bin/behat
Modelling end-to-end
UI is a controller
UI is a controller
Demo: Modelling a shopping basket
Thank You
Ciaran McNulty
PhpSpec lead maintainer
Consultant at Inviqa
@ciaranmcnulty
ciaran@inviqa.com

More Related Content

Similar to Modelling by Example Workshop - PHPNW 2016

Behavior Driven Development
Behavior Driven DevelopmentBehavior Driven Development
Behavior Driven DevelopmentLiz Keogh
 
Automated UI test on mobile - with Cucumber/Calabash
Automated UI test on mobile - with Cucumber/CalabashAutomated UI test on mobile - with Cucumber/Calabash
Automated UI test on mobile - with Cucumber/CalabashNiels Frydenholm
 
Moving away from legacy code with BDD
Moving away from legacy code with BDDMoving away from legacy code with BDD
Moving away from legacy code with BDDKonstantin Kudryashov
 
Enabling agile devliery through enabling BDD in PHP projects
Enabling agile devliery through enabling BDD in PHP projectsEnabling agile devliery through enabling BDD in PHP projects
Enabling agile devliery through enabling BDD in PHP projectsKonstantin Kudryashov
 
Driving Design through Examples - PhpCon PL 2015
Driving Design through Examples - PhpCon PL 2015Driving Design through Examples - PhpCon PL 2015
Driving Design through Examples - PhpCon PL 2015CiaranMcNulty
 
Being an Agile Engineer
Being an Agile EngineerBeing an Agile Engineer
Being an Agile EngineerACM
 
Behaviour Driven Development by Liz Keogh
Behaviour Driven Development by Liz KeoghBehaviour Driven Development by Liz Keogh
Behaviour Driven Development by Liz KeoghSyncConf
 
MEMSI June: DE2 - What can you do for your customer?
MEMSI June: DE2 - What can you do for your customer?MEMSI June: DE2 - What can you do for your customer?
MEMSI June: DE2 - What can you do for your customer?Elaine Chen
 
Bdd for Life
Bdd for LifeBdd for Life
Bdd for LifeLiz Keogh
 
Business driven development
Business driven developmentBusiness driven development
Business driven developmentBenoy John, CSM
 
Cheapass.in — presented at JSFoo 2016
Cheapass.in — presented at JSFoo 2016Cheapass.in — presented at JSFoo 2016
Cheapass.in — presented at JSFoo 2016Aakash Goel
 
Testing for Agility: Bringing Testing into Everything
Testing for Agility: Bringing Testing into EverythingTesting for Agility: Bringing Testing into Everything
Testing for Agility: Bringing Testing into EverythingCamille Bell
 
How Shutl Delivers Even Faster Using Neo4J
How Shutl Delivers Even Faster Using Neo4JHow Shutl Delivers Even Faster Using Neo4J
How Shutl Delivers Even Faster Using Neo4JC4Media
 
Living with Acceptance Tests: Beyond Write-Once
Living with Acceptance Tests: Beyond Write-OnceLiving with Acceptance Tests: Beyond Write-Once
Living with Acceptance Tests: Beyond Write-OnceDaniel Wellman
 
Engage! Bringing teams together to deliver software that makes a difference
Engage! Bringing teams together to deliver software that makes a differenceEngage! Bringing teams together to deliver software that makes a difference
Engage! Bringing teams together to deliver software that makes a differenceJohn Ferguson Smart Limited
 
Building a Pyramid: Symfony Testing Strategies
Building a Pyramid: Symfony Testing StrategiesBuilding a Pyramid: Symfony Testing Strategies
Building a Pyramid: Symfony Testing StrategiesCiaranMcNulty
 
Math unit9 consumer arithmetic
Math unit9 consumer arithmeticMath unit9 consumer arithmetic
Math unit9 consumer arithmeticeLearningJa
 
Panning for User Story Gold - by Damon Poole, Agile Coach
Panning for User Story Gold - by Damon Poole, Agile CoachPanning for User Story Gold - by Damon Poole, Agile Coach
Panning for User Story Gold - by Damon Poole, Agile CoachSynerzip
 

Similar to Modelling by Example Workshop - PHPNW 2016 (20)

Behavior Driven Development
Behavior Driven DevelopmentBehavior Driven Development
Behavior Driven Development
 
Automated UI test on mobile - with Cucumber/Calabash
Automated UI test on mobile - with Cucumber/CalabashAutomated UI test on mobile - with Cucumber/Calabash
Automated UI test on mobile - with Cucumber/Calabash
 
Moving away from legacy code with BDD
Moving away from legacy code with BDDMoving away from legacy code with BDD
Moving away from legacy code with BDD
 
Enabling agile devliery through enabling BDD in PHP projects
Enabling agile devliery through enabling BDD in PHP projectsEnabling agile devliery through enabling BDD in PHP projects
Enabling agile devliery through enabling BDD in PHP projects
 
Driving Design through Examples - PhpCon PL 2015
Driving Design through Examples - PhpCon PL 2015Driving Design through Examples - PhpCon PL 2015
Driving Design through Examples - PhpCon PL 2015
 
Star Trek: BDD Enterprise
Star Trek: BDD EnterpriseStar Trek: BDD Enterprise
Star Trek: BDD Enterprise
 
Being an Agile Engineer
Being an Agile EngineerBeing an Agile Engineer
Being an Agile Engineer
 
Behaviour Driven Development by Liz Keogh
Behaviour Driven Development by Liz KeoghBehaviour Driven Development by Liz Keogh
Behaviour Driven Development by Liz Keogh
 
MEMSI June: DE2 - What can you do for your customer?
MEMSI June: DE2 - What can you do for your customer?MEMSI June: DE2 - What can you do for your customer?
MEMSI June: DE2 - What can you do for your customer?
 
Bdd for Life
Bdd for LifeBdd for Life
Bdd for Life
 
Business driven development
Business driven developmentBusiness driven development
Business driven development
 
EIA 2015 Validating Revenue Model Assumptions
EIA 2015 Validating Revenue Model AssumptionsEIA 2015 Validating Revenue Model Assumptions
EIA 2015 Validating Revenue Model Assumptions
 
Cheapass.in — presented at JSFoo 2016
Cheapass.in — presented at JSFoo 2016Cheapass.in — presented at JSFoo 2016
Cheapass.in — presented at JSFoo 2016
 
Testing for Agility: Bringing Testing into Everything
Testing for Agility: Bringing Testing into EverythingTesting for Agility: Bringing Testing into Everything
Testing for Agility: Bringing Testing into Everything
 
How Shutl Delivers Even Faster Using Neo4J
How Shutl Delivers Even Faster Using Neo4JHow Shutl Delivers Even Faster Using Neo4J
How Shutl Delivers Even Faster Using Neo4J
 
Living with Acceptance Tests: Beyond Write-Once
Living with Acceptance Tests: Beyond Write-OnceLiving with Acceptance Tests: Beyond Write-Once
Living with Acceptance Tests: Beyond Write-Once
 
Engage! Bringing teams together to deliver software that makes a difference
Engage! Bringing teams together to deliver software that makes a differenceEngage! Bringing teams together to deliver software that makes a difference
Engage! Bringing teams together to deliver software that makes a difference
 
Building a Pyramid: Symfony Testing Strategies
Building a Pyramid: Symfony Testing StrategiesBuilding a Pyramid: Symfony Testing Strategies
Building a Pyramid: Symfony Testing Strategies
 
Math unit9 consumer arithmetic
Math unit9 consumer arithmeticMath unit9 consumer arithmetic
Math unit9 consumer arithmetic
 
Panning for User Story Gold - by Damon Poole, Agile Coach
Panning for User Story Gold - by Damon Poole, Agile CoachPanning for User Story Gold - by Damon Poole, Agile Coach
Panning for User Story Gold - by Damon Poole, Agile Coach
 

More from CiaranMcNulty

Greener web development at PHP London
Greener web development at PHP LondonGreener web development at PHP London
Greener web development at PHP LondonCiaranMcNulty
 
Doodle Driven Development
Doodle Driven DevelopmentDoodle Driven Development
Doodle Driven DevelopmentCiaranMcNulty
 
Behat Best Practices with Symfony
Behat Best Practices with SymfonyBehat Best Practices with Symfony
Behat Best Practices with SymfonyCiaranMcNulty
 
Behat Best Practices
Behat Best PracticesBehat Best Practices
Behat Best PracticesCiaranMcNulty
 
Behat Best Practices with Symfony
Behat Best Practices with SymfonyBehat Best Practices with Symfony
Behat Best Practices with SymfonyCiaranMcNulty
 
Finding the Right Testing Tool for the Job
Finding the Right Testing Tool for the JobFinding the Right Testing Tool for the Job
Finding the Right Testing Tool for the JobCiaranMcNulty
 
Conscious Decoupling - Lone Star PHP
Conscious Decoupling - Lone Star PHPConscious Decoupling - Lone Star PHP
Conscious Decoupling - Lone Star PHPCiaranMcNulty
 
TDD with PhpSpec - Lone Star PHP 2016
TDD with PhpSpec - Lone Star PHP 2016TDD with PhpSpec - Lone Star PHP 2016
TDD with PhpSpec - Lone Star PHP 2016CiaranMcNulty
 
Fly In Style (without splashing out)
Fly In Style (without splashing out)Fly In Style (without splashing out)
Fly In Style (without splashing out)CiaranMcNulty
 
Why Your Test Suite Sucks - PHPCon PL 2015
Why Your Test Suite Sucks - PHPCon PL 2015Why Your Test Suite Sucks - PHPCon PL 2015
Why Your Test Suite Sucks - PHPCon PL 2015CiaranMcNulty
 
Why Your Test Suite Sucks
Why Your Test Suite SucksWhy Your Test Suite Sucks
Why Your Test Suite SucksCiaranMcNulty
 
Driving Design with PhpSpec
Driving Design with PhpSpecDriving Design with PhpSpec
Driving Design with PhpSpecCiaranMcNulty
 
Using HttpKernelInterface for Painless Integration
Using HttpKernelInterface for Painless IntegrationUsing HttpKernelInterface for Painless Integration
Using HttpKernelInterface for Painless IntegrationCiaranMcNulty
 

More from CiaranMcNulty (14)

Greener web development at PHP London
Greener web development at PHP LondonGreener web development at PHP London
Greener web development at PHP London
 
Doodle Driven Development
Doodle Driven DevelopmentDoodle Driven Development
Doodle Driven Development
 
Behat Best Practices with Symfony
Behat Best Practices with SymfonyBehat Best Practices with Symfony
Behat Best Practices with Symfony
 
Behat Best Practices
Behat Best PracticesBehat Best Practices
Behat Best Practices
 
Behat Best Practices with Symfony
Behat Best Practices with SymfonyBehat Best Practices with Symfony
Behat Best Practices with Symfony
 
Finding the Right Testing Tool for the Job
Finding the Right Testing Tool for the JobFinding the Right Testing Tool for the Job
Finding the Right Testing Tool for the Job
 
Conscious Decoupling - Lone Star PHP
Conscious Decoupling - Lone Star PHPConscious Decoupling - Lone Star PHP
Conscious Decoupling - Lone Star PHP
 
TDD with PhpSpec - Lone Star PHP 2016
TDD with PhpSpec - Lone Star PHP 2016TDD with PhpSpec - Lone Star PHP 2016
TDD with PhpSpec - Lone Star PHP 2016
 
Fly In Style (without splashing out)
Fly In Style (without splashing out)Fly In Style (without splashing out)
Fly In Style (without splashing out)
 
Why Your Test Suite Sucks - PHPCon PL 2015
Why Your Test Suite Sucks - PHPCon PL 2015Why Your Test Suite Sucks - PHPCon PL 2015
Why Your Test Suite Sucks - PHPCon PL 2015
 
TDD with PhpSpec
TDD with PhpSpecTDD with PhpSpec
TDD with PhpSpec
 
Why Your Test Suite Sucks
Why Your Test Suite SucksWhy Your Test Suite Sucks
Why Your Test Suite Sucks
 
Driving Design with PhpSpec
Driving Design with PhpSpecDriving Design with PhpSpec
Driving Design with PhpSpec
 
Using HttpKernelInterface for Painless Integration
Using HttpKernelInterface for Painless IntegrationUsing HttpKernelInterface for Painless Integration
Using HttpKernelInterface for Painless Integration
 

Recently uploaded

办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一z xss
 
Elevate Your Business with Our IT Expertise in New Orleans
Elevate Your Business with Our IT Expertise in New OrleansElevate Your Business with Our IT Expertise in New Orleans
Elevate Your Business with Our IT Expertise in New Orleanscorenetworkseo
 
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Dana Luther
 
Blepharitis inflammation of eyelid symptoms cause everything included along w...
Blepharitis inflammation of eyelid symptoms cause everything included along w...Blepharitis inflammation of eyelid symptoms cause everything included along w...
Blepharitis inflammation of eyelid symptoms cause everything included along w...Excelmac1
 
SCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is prediSCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is predieusebiomeyer
 
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一Fs
 
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一Fs
 
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书rnrncn29
 
Top 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxTop 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxDyna Gilbert
 
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作ys8omjxb
 
Intellectual property rightsand its types.pptx
Intellectual property rightsand its types.pptxIntellectual property rightsand its types.pptx
Intellectual property rightsand its types.pptxBipin Adhikari
 
Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170Sonam Pathan
 
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170Sonam Pathan
 
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书rnrncn29
 
Magic exist by Marta Loveguard - presentation.pptx
Magic exist by Marta Loveguard - presentation.pptxMagic exist by Marta Loveguard - presentation.pptx
Magic exist by Marta Loveguard - presentation.pptxMartaLoveguard
 
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一Fs
 
Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24Paul Calvano
 

Recently uploaded (20)

办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
 
Elevate Your Business with Our IT Expertise in New Orleans
Elevate Your Business with Our IT Expertise in New OrleansElevate Your Business with Our IT Expertise in New Orleans
Elevate Your Business with Our IT Expertise in New Orleans
 
Hot Sexy call girls in Rk Puram 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in  Rk Puram 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in  Rk Puram 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Rk Puram 🔝 9953056974 🔝 Delhi escort Service
 
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
 
Blepharitis inflammation of eyelid symptoms cause everything included along w...
Blepharitis inflammation of eyelid symptoms cause everything included along w...Blepharitis inflammation of eyelid symptoms cause everything included along w...
Blepharitis inflammation of eyelid symptoms cause everything included along w...
 
SCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is prediSCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is predi
 
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
 
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
 
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
 
Model Call Girl in Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in  Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in  Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
 
Top 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxTop 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptx
 
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
 
Intellectual property rightsand its types.pptx
Intellectual property rightsand its types.pptxIntellectual property rightsand its types.pptx
Intellectual property rightsand its types.pptx
 
Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170
 
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
 
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
 
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
 
Magic exist by Marta Loveguard - presentation.pptx
Magic exist by Marta Loveguard - presentation.pptxMagic exist by Marta Loveguard - presentation.pptx
Magic exist by Marta Loveguard - presentation.pptx
 
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
 
Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24
 

Modelling by Example Workshop - PHPNW 2016

  • 1. Modelling by Example Ciaran McNulty at PHPNW 2016
  • 5. BDD is the art of using examples in conversa6ons to illustrate behaviour — Liz Keogh
  • 10. Given I bought a microwave for £10 When I return the microwave Then I should be refunded £10
  • 11. Who writes examples? Business expert Tes(ng expert Development expert All discussing the feature together
  • 12. When to write scenarios • Before you start work on the feature • Not too long before! • Whenever you have access to the right people
  • 14. When would this outcome not be true? Given I bought a microwave for £10 When I return the microwave Then I should be refunded £10
  • 15. When would this outcome not be true? Given I bought a microwave for £10 When I return the microwave with a valid receipt Then I should be refunded £10
  • 16. When would this outcome not be true? Given I bought a microwave for £10 When I return the microwave with a valid receipt Then I should be refunded £10 Given I bought a microwave for £10 When I try to return the microwave without a valid receipt Then I should be refunded £10 store credit
  • 17. What other outcomes are there? Given I bought a microwave for £10 When I return the microwave with a valid receipt Then I should be refunded £10
  • 18. What other outcomes are there? Given I bought a microwave for £10 When I return the microwave with a valid receipt Then I should be refunded £10 And the microwave should be returned to stock
  • 19. When would this outcome not be true? Given I bought a microwave for £10 When I return the microwave with a valid receipt Then I should be refunded £10 And the microwave should be returned to stock
  • 20. When would this outcome not be true? Given I bought a microwave for £10 When I return the microwave with a valid receipt And the microwave is not damaged Then I should be refunded £10 And the microwave should be returned to stock
  • 21. When would this outcome not be true? Given I bought a microwave for £10 When I return the microwave with a valid receipt And the microwave is not damaged Then I should be refunded £10 And the microwave should be returned to stock Given I bought a microwave for £10 When I return the microwave with a valid receipt And the microwave is damaged Then I should not be refunded And the microwave should not be returned to stock
  • 22. Does this implementa)on detail ma+er? When I go to '/returns' And I fill in 'form#returns input.product' field with 'microwave' And hit the 'refund' bu>on
  • 23. Does this implementa)on detail ma+er? When I fill in the returns form with the details of the microwave
  • 24. Does this implementa)on detail ma+er? When I return the microwave through the website
  • 25. Does this implementa)on detail ma+er? When I return the microwave
  • 26. Examples and rules • Rules are hard to express and ambiguous • Examples are very easy to understand • Examples help us understand the rules • Examples work best as feedback
  • 29. DDD tackles complexity by focusing the team's a7en8on on knowledge of the domain — Eric Evans
  • 31. Ubiquitous Language • A shared way of speaking about domain concepts • Reduces the cost of transla.on when business and development communicate • Try to establish and use terms the business will understand
  • 33. By embedding Ubiquitous Language in your scenarios, your scenarios naturally become your domain model — Konstan)n Kudryashov (@everzet)
  • 34. Principles • The best way to understand the domain is by discussing examples • Write scenarios that capture ubiquitous language • Write scenarios that illustrate real situa5ons • Directly drive the code model from those examples
  • 35. Given I bought a microwave for £10 When I return the microwave with a valid receipt And the microwave is not damaged Then I should be refunded £10 And the microwave should be returned to stock
  • 36. Ask about iden.ty Given I bought a microwave for £10 When I return the microwave with a valid receipt And the microwave is not damaged Then I should be refunded £10 And the microwave should be returned to stock
  • 37. Ask about iden.ty Given I bought a microwave with SKU "M100" for £10.00 And was given receipt numbered "ABC1234" When I return the product with a the same receipt And the product is not damaged Then I should be refunded £10 And the producy should be returned to stock
  • 38. Ask about verbs Given I bought a microwave with SKU "M100" for £10.00 And was given receipt numbered "ABC1234" When I return the product with a the same receipt And the product is not damaged Then I should be refunded £10 And the producy should be returned to stock
  • 39. Ask about verbs Given I purchased a microwave with SKU "M100" for £10.00 And was issued a receipt numbered "ABC1234" When I return the product with a the same receipt And the product is not damaged Then I should be credited £10 And the producy should be returned to stock
  • 40. Ask "how do we know this is true?" Given I purchased a microwave with SKU "M100" for £10.00 And was issued a receipt numbered "ABC1234" When I return the product with a the same receipt And the product is not damaged Then I should be credited £10 And the producy should be returned to stock
  • 41. Ask "how do we know this is true?" Given I purchased a microwave with SKU "M100" for £10.00 And was issued a receipt numbered "ABC1234" When I return the product with a the same receipt And the product passes a damage inspec,on Then I should be credited £10 And the producy should be returned to stock
  • 42. Exercise: Improving ubiquitous language Scenario: Flyer takes a flight and earns points Given I bought a ticket on a flight And the flight earns 100 points When I take the flight Then I should get 100 points Scenario: Flyer doesn’t take a flight and doesn’t earn points Given I bought a ticket on a flight And the flight earns 100 points When I don't take the flight Then I should get 0 points
  • 43. Scenario: Flyer takes a flight and earns Cuke Miles Given a ticket was bought on a flight And it was linked to newly registered loyalty account 2352352 And the flight earns 100 Cuke Miles When the ticket boards the flight Then account 2352352 should have 100 Cuke Miles Scenario: Flyer doesn’t take a flight and doesn’t earn Cuke Miles Given ticket was bought on a flight And it was linked to newly registered loyalty account 2352352 And the flight earns 100 Cuke Miles When the ticket does not board the flight Then account 2352352 should have 0 Cuke Miles
  • 44. Background: Given a ticket was bought on a flight "CK-112" And it was linked to newly registered loyalty account 2352352 And the "LHR-JFK" route earns 100 Cuke Miles And flight "CK-112" flies the "LHR-JFK" route Scenario: Flyer takes a flight and earns Cuke Miles Given the ticket boarded the flight When the flight arrives at destination Then account 2352352 should have 100 Cuke Miles Scenario: Flyer doesn’t take a flight and doesn’t earn Cuke Miles Given the ticket did not board the flight When the flight arrives at destination Then account 2352352 should have 0 Cuke Miles
  • 45. Break
  • 49. Tes$ng the UI • Slow to execute • Bri/le • Makes you design the domain and UI at the same <me
  • 50. Test the domain API first
  • 51. Tes$ng with real infrastructure • Slow to execute • Bri/le • Makes you design the domain and infrastructure at the same ;me
  • 52. Test with fake infrastructure first
  • 54. Behat • a tool to test business expecta-ons against an applica-on • developed by Konstan-n Kudryashov • based on Cucumber by Aslak Hellesøy
  • 55. Gherkin Machine-readable and business-readable format for capturing scenarios
  • 56. Features • One per .feature file • Describes a set of rules the system should exibit by giving example scenarios Feature: Returning a microwave
  • 57. Scenarios • Many per feature file • Give an example to illustrate the expected behaviour Feature: Returning a microwave Scenario: Returning undamaged product with receipt Scenario: …
  • 58. Steps • Many per feature file • Give an example to illustrate the expected behaviour Feature: Returning a microwave Scenario: Returning undamaged product with receipt Given I bought a microwave for £10 When I return the microwave with a valid receipt And the microwave is not damaged Then I should be refunded £10 And the microwave should be returned to stock
  • 59. Step defini*ons Behat's job is to take each step and map it to executable code • Given steps -> Code that puts the system in the right state • When steps -> Code that defines the ac:on we are describing • Then steps -> Code that verifies the outcome we expect
  • 60. Step defini*ons /** * @given I bought a :product for £:cost */ function returnAProduct(string $product, string $cost) { $this->productPurchaser->purchase( new Product($product), new Cost($cost) ); }
  • 61. Modelling the core - key principles • Iden&fy and use Value Objects • Iden&fy boundaries, define interfaces, and create fake implementa&ons • Match the language used in the steps
  • 62. Demo
  • 63. Exercise: Modelling a shopping basket Feature: Applying VAT and delivery costs to basket In order to know how much I'm paying As a customer I need VAT and cost of delivery to be calculated based on my basket price Rules: - VAT is 20% - Delivery cost for basket greater than £10 is £2 - Delivery cost for basket less than £10 is £3 Scenario: Product costing less than £10 results in delivery cost of £3 Given there is a product with SKU "RS1" And this product is listed at a cost of £5 in the catalogue When I add this product to my basket from the catalogue Then the total cost of my basket should be £9
  • 64. Exercise: Modelling a shopping basket Clone from github: http://github.com/ciaranmcnulty/phpnw16-workshop Work through the feature and model the core domain using Behat and PhpSpec. Key command: bin/phpspec run && bin/behat
  • 66. UI is a controller
  • 67. UI is a controller
  • 68. Demo: Modelling a shopping basket
  • 69. Thank You Ciaran McNulty PhpSpec lead maintainer Consultant at Inviqa @ciaranmcnulty ciaran@inviqa.com