Slides from talk presented during 4 Developers Conference in Warsaw.
Techniques used in Domain-Driven Design enable advanced modelling of applications but also require you to analyse problems in a specific way. So how in cooperation with Domain Experts and using existing resources can we make most of it? Are there any tools in PHP world that can help us achieving this goal? In this talk you'll be introduced to “Modelling by Example” - a new approach to Behaviour-Driven Development - and shown how to effectively use it to model applications. We will make use of well known tools like Gherkin and Behat, which by design drive the project communication, but what if they can do more? It turns out if we look at these tools from a different perspective they also enable modelling of the problem like we do in DDD. We will analyse this approach on examples to give you a starting point for your own projects!
More Domain-Driven Design related content at: https://domaincentric.net/
5. Behaviour-driven development is about
implementing an application
by describing its behaviour
from the perspective of its
stakeholders.
-- Dan North
6. BDD is about establishing
a shared understanding of “done”
working from the outside in
until you get there
-- Dan North
9. 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
15. 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
16.
17.
18. 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
43. 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
45. Pushing for ubiquitous language hard
enough makes your examples a domain
model
-- Konstantin Kudryashov
46. 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
47. 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
53. 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
54.
55. 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);
}
58. 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);
}
59.
60. 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)
);
}
61. 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));
}
66. @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
67. Given the search for the itinerary schedule
/**
* @Given the search for the itinerary schedule
*/
public function theSearchForTheItinerarySchedule()
{
$this->visit("/search");
}
68. 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);
}
69. 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");
}
70. 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));
}