SlideShare uma empresa Scribd logo
1 de 98
Baixar para ler offline
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

Mais conteúdo relacionado

Destaque

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
 

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

Mais de Kacper Gunia

Mais 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

Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Christo Ananth
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Christo Ananth
 

Último (20)

Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
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
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
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
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
(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
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
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...
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 

How to (finally) start doing DDD by using BDD