SlideShare une entreprise Scribd logo
1  sur  98
Télécharger pour lire hors ligne
Howto(finally)startdoing
DDDbyusingBDD
KacperGunia@cakper
So!ware Engineer
@SensioLabsUK / @Inviqa
PHPers Silesia
@PHPersPL
WhatisBDD?
Bug-driven
Development;)
Behaviour-driven development is about
implementing an application
by describing its behaviour
from the perspective of its
stakeholders.
-- Dan North
BDD is about establishing
a shared understanding of “done”
working from the outside in
until you get there
-- Dan North
BDDshowsyouwhattodonext
akaTechnicalDiscipline
HowdoweBDD?
Feature: Traveler searches for cheap itineraries
In order to save money while travelling
As a world traveler
I want to search for the cheapest itinerary
Productownerwritesscenario
anddeveloperautomatesit
Developerwritesscenario
andthenautomatesit
No!
BDDisaboutcommunication!
flickr.com/photos/dvids/5638829762
Scenario: Successfully find cheapest direct flight
Given the flight from "WAW" to "LHR" priced $30 was scheduled
And the flight from "WAW" to "LHR" priced $50 was scheduled
When I open the "/search" page
And I fill "WAW" in the "Departure airport" field
And I fill "LHR" in the "Destination airport" field
And I click "Search"
Then I should be redirected to "/results" page
And I should see $30 in the "#cheapest-flight-price" block
Scenario: Successfully find cheapest direct flight
Given the flight from "WAW" to "LHR" priced $30 was scheduled
And the flight from "WAW" to "LHR" priced $50 was scheduled
When I open the "/search" page
And I fill "WAW" in the "Departure airport" field
And I fill "LHR" in the "Destination airport" field
And I click "Search"
Then I should be redirected to "/results" page
And I should see $30 in the "#cheapest-flight-price" block
Translation
Canwedobetter?
MissionaccomplishedBoys
Wecangohomenow!
flickr.com/photos/dvids/5638829762
Translationagain
Howtofixthat?
DDD
WhatisDDDabout?
It’s about focusing on the domain
and letting it affect the so"ware very
much
-- Jimmy Nilsson
ButWHYdoweneedit?
Everybodyknowsthejargon
intheirOWNFIELD
It'saboutcommon
understanding
Ubiquitouslanguage
Concrete examples are rooted
in the problem domain
-- Matt Wynne
DomainModel
A domain model (...) is not just the
knowledge in a domain expert’s head;
it is a rigorously organized and
selective abstraction of that knowledge
-- Eric Evans
Modeldocuments
theknowledge
Pushing for ubiquitous language hard
enough makes your examples a domain
model
-- Konstantin Kudryashov
Scenario: Successfully find cheapest direct flight
Given the flight from "WAW" to "LHR" priced $30 was scheduled
And the flight from "WAW" to "LHR" priced $50 was scheduled
When I open the "/search" page
And I fill "WAW" in the "Departure airport" field
And I fill "LHR" in the "Destination airport" field
And I click "Search"
Then I should be redirected to "/results" page
And I should see $30 in the "#cheapest-flight-price" block
Scenario: Successfully find cheapest direct itinerary
Given the search for the itinerary schedule
And the itinerary from "WAW" to "LHR" priced $30 was planned in the schedule
And the itinerary from "WAW" to "LHR" priced $50 was planned in the schedule
When I search for cheapest itinerary from "WAW" to "LHR"
Then the cheapest itinerary should cost $30
Modellingbyexample
Phase1
Scenario: Successfully find cheapest direct itinerary
Given the search for the itinerary schedule
And the itinerary from "WAW" to "LHR" priced $30 was planned in the schedule
And the itinerary from "WAW" to "LHR" priced $50 was planned in the schedule
When I search for cheapest itinerary from "WAW" to "LHR"
Then the cheapest itinerary should cost $30
Given the search for the itinerary schedule
/**
* @Given /^the search for the itinerary schedule$/
*/
public function theSearchForTheItinerarySchedule()
{
$this->itinerarySchedule = new ItinerarySchedule();
$this->search = new Search($this->itinerarySchedule);
}
Designemerges
And the itinerary from "WAW" to "LHR"
priced $30 was planned in the schedule
/**
* @Given the itinerary from :fromAirport to :toAirport
* priced $:price was planned in the schedule
*/
public function theItineraryFromToPricedWasPlannedInTheSchedule(
$fromAirport,
$toAirport,
$price
) {
$itinerary = new Itinerary(
Airport::code($fromAirport),
Airport::code($toAirport),
Money::usd($price)
);
$this->itinerarySchedule->plan($itinerary);
}
When I search for cheapest itinerary from "WAW" to "LHR"
/**
* @When I search for cheapest itinerary from :fromAirport to :toAirport
*/
public function iSearchForCheapestItineraryFromTo($fromAirport, $toAirport)
{
$this->cheapestItinerary = $this->search->forCheapest(
Airport::code($fromAirport),
Airport::code($toAirport)
);
}
Then the cheapest itinerary should cost $30
/**
* @Then the cheapest itinerary should cost $:price
*/
public function theCheapestItineraryShouldCost($price)
{
expect($this->cheapestItinerary->cost())->toBeLike(Money::usd($price));
}
Phase2
@ui
Scenario: Successfully find cheapest direct itinerary
Given the search for the itinerary schedule
And the itinerary from "WAW" to "LHR" priced $30 was planned in the schedule
And the itinerary from "WAW" to "LHR" priced $50 was planned in the schedule
When I search for cheapest itinerary from "WAW" to "LHR"
Then the cheapest itinerary should cost $30
Given the search for the itinerary schedule
/**
* @Given the search for the itinerary schedule
*/
public function theSearchForTheItinerarySchedule()
{
$this->visit("/search");
}
And the itinerary from "WAW" to "LHR"
priced $30 was planned in the schedule
/**
* @Given the itinerary from :fromAirport to :toAirport
* priced $:price was planned in the schedule
*/
public function theItineraryFromToPricedWasPlannedInTheSchedule(
$fromAirport,
$toAirport,
$price
) {
$itinerary = new Itinerary(
Airport::code($fromAirport),
Airport::code($toAirport),
Money::usd($price)
);
$this->get("itinerary_schedule")->plan($itinerary);
}
When I search for cheapest itinerary from "WAW" to "LHR"
/**
* @When I search for cheapest itinerary from :fromAirport to :toAirport
*/
public function iSearchForCheapestItineraryFromTo($fromAirport, $toAirport)
{
$this->fillIn("#from-airport", $fromAirport);
$this->fillIn("#to-airport", $toAirport);
$this->clickButton("Search");
}
Then the cheapest itinerary should cost $30
/**
* @Then the cheapest itinerary should cost $:price
*/
public function theCheapestItineraryShouldCost($price)
{
$cheapestItinerary = $this->find("#cheapest-itinerary");
expect($cheapestItinerary)->toContainText(sprintf("From $%s", $price));
}
# behat.yml
default:
suites:
domain:
contexts: [ SearchContext ]
ui:
contexts: [ WebSearchContext ]
filters: { tags: '@ui' }
ModellingbyExample
Inthree(easy)steps
· Have the conversation
· Model your objects
· Go again through UI*
*But
You(really)don't
havetoautomate
everything!
Butthereisa
problem
Weignoredthedepth
ofthedomain
Onpurpose
Youcan'tmodelthe
wholesystemusing
onefeature
Repeattheprocess
andmodelthe
planner
Whatifmodelhasdifferentrequirements
inthiscontext?
BoundedContext
Languageislimited
Search Itinerary
!=
Planner Itinerary
!=
Booking Itinerary
Donotbuildfragilemonoliths!
Buildapplicationswith
Boundedcontextinmind
---Wrapup---
Havethe
conversation
Donotseparatethe
conceptsfromthe
implementation
Youcannotbuild
conceptualmodels
withoutconsidering
implementationissues
Pushfor
Ubiquitouslanguage
UseBehattodriveyourModel
NotonlytheUI
"BDDisabout
conversationsyouhaveto
producesoftware"
"DDDisabouthowyou
exploredomainmodels
andhowyouarticulatethis"
Thanks!
@cakper

Contenu connexe

En vedette

Why elasticsearch rocks!
Why elasticsearch rocks!Why elasticsearch rocks!
Why elasticsearch rocks!
tlrx
 
L'ABC du BDD (Behavior Driven Development)
L'ABC du BDD (Behavior Driven Development)L'ABC du BDD (Behavior Driven Development)
L'ABC du BDD (Behavior Driven Development)
Arnauld Loyer
 

En vedette (20)

Mocking Demystified
Mocking DemystifiedMocking Demystified
Mocking Demystified
 
Top tips my_sql_performance
Top tips my_sql_performanceTop tips my_sql_performance
Top tips my_sql_performance
 
Why elasticsearch rocks!
Why elasticsearch rocks!Why elasticsearch rocks!
Why elasticsearch rocks!
 
Understanding Craftsmanship SwanseaCon2015
Understanding Craftsmanship SwanseaCon2015Understanding Craftsmanship SwanseaCon2015
Understanding Craftsmanship SwanseaCon2015
 
Writing infinite scalability web applications with PHP and PostgreSQL
Writing infinite scalability web applications with PHP and PostgreSQLWriting infinite scalability web applications with PHP and PostgreSQL
Writing infinite scalability web applications with PHP and PostgreSQL
 
Si le tdd est mort alors pratiquons une autopsie mix-it 2015
Si le tdd est mort alors pratiquons une autopsie mix-it 2015Si le tdd est mort alors pratiquons une autopsie mix-it 2015
Si le tdd est mort alors pratiquons une autopsie mix-it 2015
 
L'ABC du BDD (Behavior Driven Development)
L'ABC du BDD (Behavior Driven Development)L'ABC du BDD (Behavior Driven Development)
L'ABC du BDD (Behavior Driven Development)
 
Caching on the Edge
Caching on the EdgeCaching on the Edge
Caching on the Edge
 
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
 
Performance serveur et apache
Performance serveur et apachePerformance serveur et apache
Performance serveur et apache
 
Behat 3.0 meetup (March)
Behat 3.0 meetup (March)Behat 3.0 meetup (March)
Behat 3.0 meetup (March)
 
The Wonderful World of Symfony Components
The Wonderful World of Symfony ComponentsThe Wonderful World of Symfony Components
The Wonderful World of Symfony Components
 
PHPSpec - the only Design Tool you need - 4Developers
PHPSpec - the only Design Tool you need - 4DevelopersPHPSpec - the only Design Tool you need - 4Developers
PHPSpec - the only Design Tool you need - 4Developers
 
Design how your objects talk through mocking
Design how your objects talk through mockingDesign how your objects talk through mocking
Design how your objects talk through mocking
 
Password (in)security
Password (in)securityPassword (in)security
Password (in)security
 
Measuring Web Performance - HighEdWeb Edition
Measuring Web Performance - HighEdWeb EditionMeasuring Web Performance - HighEdWeb Edition
Measuring Web Performance - HighEdWeb Edition
 
I.T.A.K.E Unconference - Mutation testing to the rescue of your tests
I.T.A.K.E Unconference - Mutation testing to the rescue of your testsI.T.A.K.E Unconference - Mutation testing to the rescue of your tests
I.T.A.K.E Unconference - Mutation testing to the rescue of your tests
 
Composer in monolithic repositories
Composer in monolithic repositoriesComposer in monolithic repositories
Composer in monolithic repositories
 
Love and Loss: A Symfony Security Play
Love and Loss: A Symfony Security PlayLove and Loss: A Symfony Security Play
Love and Loss: A Symfony Security Play
 
Driving Design through Examples
Driving Design through ExamplesDriving Design through Examples
Driving Design through Examples
 

Plus de Kacper Gunia

Plus de Kacper Gunia (16)

How a large corporation used Domain-Driven Design to replace a loyalty system
How a large corporation used Domain-Driven Design to replace a loyalty systemHow a large corporation used Domain-Driven Design to replace a loyalty system
How a large corporation used Domain-Driven Design to replace a loyalty system
 
Rebuilding Legacy Apps with Domain-Driven Design - Lessons learned
Rebuilding Legacy Apps with Domain-Driven Design - Lessons learnedRebuilding Legacy Apps with Domain-Driven Design - Lessons learned
Rebuilding Legacy Apps with Domain-Driven Design - Lessons learned
 
The IoC Hydra - Dutch PHP Conference 2016
The IoC Hydra - Dutch PHP Conference 2016The IoC Hydra - Dutch PHP Conference 2016
The IoC Hydra - Dutch PHP Conference 2016
 
The top 10 things that any pro PHP developer should be doing
The top 10 things that any pro PHP developer should be doingThe top 10 things that any pro PHP developer should be doing
The top 10 things that any pro PHP developer should be doing
 
Embrace Events and let CRUD die
Embrace Events and let CRUD dieEmbrace Events and let CRUD die
Embrace Events and let CRUD die
 
The IoC Hydra
The IoC HydraThe IoC Hydra
The IoC Hydra
 
Forget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers CracowForget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers Cracow
 
Domain-driven Design in PHP and Symfony - Drupal Camp Wroclaw!
Domain-driven Design in PHP and Symfony - Drupal Camp Wroclaw!Domain-driven Design in PHP and Symfony - Drupal Camp Wroclaw!
Domain-driven Design in PHP and Symfony - Drupal Camp Wroclaw!
 
OmniFocus - the #1 ‘Getting Things Done’ tool
OmniFocus - the #1 ‘Getting Things Done’ toolOmniFocus - the #1 ‘Getting Things Done’ tool
OmniFocus - the #1 ‘Getting Things Done’ tool
 
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Scaling Symfony2 apps with RabbitMQ - Symfony UK MeetupScaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
 
Forget about index.php and build you applications around HTTP!
Forget about index.php and build you applications around HTTP!Forget about index.php and build you applications around HTTP!
Forget about index.php and build you applications around HTTP!
 
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you needDutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you need
 
November Camp - Spec BDD with PHPSpec 2
November Camp - Spec BDD with PHPSpec 2November Camp - Spec BDD with PHPSpec 2
November Camp - Spec BDD with PHPSpec 2
 
Dependency Injection in PHP
Dependency Injection in PHPDependency Injection in PHP
Dependency Injection in PHP
 
Code Dojo
Code DojoCode Dojo
Code Dojo
 
SpecBDD in PHP
SpecBDD in PHPSpecBDD in PHP
SpecBDD in PHP
 

Dernier

Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
jaanualu31
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 

Dernier (20)

DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
Bridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptxBridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptx
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
Rums floating Omkareshwar FSPV IM_16112021.pdf
Rums floating Omkareshwar FSPV IM_16112021.pdfRums floating Omkareshwar FSPV IM_16112021.pdf
Rums floating Omkareshwar FSPV IM_16112021.pdf
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planes
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086
 

How to (finally) start doing DDD by using BDD