SlideShare una empresa de Scribd logo
1 de 98
Descargar para leer sin conexión
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

Más contenido relacionado

Destacado

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
 

Destacado (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
 

Más de Kacper Gunia

Más 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
 

Último

UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
rknatarajan
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
ankushspencer015
 

Último (20)

(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
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
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 

How to (finally) start doing DDD by using BDD