Kacper Gunia
Language: Polish
Techniki stosowane w Domain-Driven Design umożliwiają modelowanie złożonych aplikacji, jednak wymagają odpowiedniego podejścia do analizy problemu. Jak w takim razie mając dostęp do Ekspertów domenowych zrobić z nich dobry użytek, wykorzystując posiadane zasoby? Czy istnieją w świecie PHP narzędzia, które mogą nam w tym pomóc?
W prezentacji wprowadzę Was do “Modelling by Example” - nowego podejścia do Behaviour-Driven Development i pokażę jak wykorzystać je do efektywnego modelowania aplikacji. Posłużymy się przy tym dobrze znanymi narzędziami takimi jak Gherkin oraz Behat, które z założenia wspierają komunikację w projekcie. Ale czy tylko? Jak się okazuje, spojrzenie na nie z trochę innej perspektywy (omówione zostanie na przykładach), umożliwia również efektywne modelowanie Domeny aplikacji zgodnie z podejściem stosowanym w DDD.
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));
}