Skip to content

Commit 4bc4d3f

Browse files
committed
Add recipe/meal construction
* Add recipe state * Add recipe creation * Add events generation on recipe by Owner * Manage order setup with meals * Create Meal on Recipe released
1 parent e317158 commit 4bc4d3f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+2359
-179
lines changed

features/bootstrap/ApplicationContext.php

Lines changed: 115 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,38 @@
77
use Behat\Behat\Tester\Exception\PendingException;
88
use Behat\Gherkin\Node\PyStringNode;
99
use Behat\Gherkin\Node\TableNode;
10+
use Behat\Transliterator\Transliterator;
1011
use Example\Domain\Administration\Application\AdministrationService;
1112
use Example\Domain\Administration\Application\HireCandidateCommand;
1213
use Example\Domain\Administration\Application\MenuService;
13-
use Example\Domain\Administration\Application\RegisterNewMeal;
14-
use Example\Domain\Administration\Application\ReleaseMeal;
14+
use Example\Domain\Administration\Application\RegisterNewRecipe;
15+
use Example\Domain\Administration\Application\ReleaseRecipe;
16+
use Example\Domain\Administration\DomainModel\RecipeId;
17+
use Example\Domain\Administration\DomainModel\RecipeName;
1518
use Example\Domain\Common\DomainModel\FullName;
1619
use Example\Domain\Administration\DomainModel\Identity\OwnerId;
1720
use Example\Domain\Administration\DomainModel\Owner;
1821
use Example\Domain\Common\DomainModel\JobTitle;
19-
use Example\Domain\Common\DomainModel\MealName;
2022
use Example\Domain\Common\DomainModel\Money;
23+
use Example\Domain\Sale\Application\BuyerService;
2124
use Example\Domain\Sale\Application\CashierService;
22-
use Example\Domain\Sale\Application\OrderMeal;
25+
use Example\Domain\Sale\Application\CreateMealOnRecipeCreated;
2326
use Example\Domain\Sale\Application\OrderService;
2427
use Example\Domain\Sale\Application\WaitressService;
25-
use Example\Domain\Sale\DomainModel\CustomerName;
28+
use Example\Domain\Sale\DomainModel\BuyerId;
29+
use Example\Domain\Sale\DomainModel\BuyerRepository;
2630
use Example\Domain\Sale\DomainModel\CustomerType;
2731
use Example\Domain\Sale\DomainModel\Identity\EmployeeId;
28-
use Example\Domain\Sale\DomainModel\Waitress;
32+
use Example\Domain\Sale\DomainModel\Identity\MealId;
33+
use Example\Domain\Sale\DomainModel\Identity\OrderId;
34+
use Example\Domain\Sale\DomainModel\PhoneNumber;
2935
use Example\Domain\Shipping\Application\CreateDeliveryBoyHandler;
36+
use Example\Infrastructure\ForgedIdGenerator;
3037
use Example\Infrastructure\InMemory\EmployeeCollection;
3138
use Example\Infrastructure\InMemory\OwnerCollection;
39+
use Example\Infrastructure\InMemory\Sale\BuyerCollection;
3240
use Example\Infrastructure\InMemory\Sale\MealCollection;
41+
use Example\Infrastructure\InMemory\Sale\OrderCollection;
3342
use Example\Infrastructure\Symfony\SymfonyPublisher;
3443
use Example\Domain\Sale\Application\CookService;
3544
use PHPUnit_Framework_Assert as Assert;
@@ -50,9 +59,14 @@ class ApplicationContext implements Context, SnippetAcceptingContext
5059
private $owners;
5160

5261
/**
53-
* @var MealCollection
62+
* @var BuyerRepository
5463
*/
55-
private $meals;
64+
private $buyers;
65+
66+
/**
67+
* @var PhoneNumber[]
68+
*/
69+
private $phones = [];
5670

5771
/**
5872
* @var AdministrationService
@@ -62,19 +76,32 @@ class ApplicationContext implements Context, SnippetAcceptingContext
6276
/**
6377
* @var MenuService
6478
*/
65-
private $menuService;
79+
private $menu;
80+
81+
/**
82+
* @var BuyerService
83+
*/
84+
private $buyerService;
6685

6786
/**
6887
* @var OrderService
6988
*/
7089
private $orderService;
7190

7291
/**
73-
* The current waitress on post
74-
*
75-
* @var Waitress|null
92+
* @var OrderCollection
93+
*/
94+
private $orders;
95+
96+
/**
97+
* @var MealCollection
7698
*/
77-
private $waitress;
99+
private $meals;
100+
101+
/**
102+
* @var ForgedIdGenerator
103+
*/
104+
private $fakeIdGenerator;
78105

79106
/**
80107
* Initializes context.
@@ -85,20 +112,28 @@ class ApplicationContext implements Context, SnippetAcceptingContext
85112
*/
86113
public function __construct()
87114
{
115+
// Infrastructure
88116
$publisher = new SymfonyPublisher();
117+
$this->buyers = new BuyerCollection();
118+
$this->owners = new OwnerCollection();
119+
$this->employees = new EmployeeCollection();
120+
$this->fakeIdGenerator = new ForgedIdGenerator();
121+
$this->orders = new OrderCollection();
89122
$this->meals = new MealCollection();
90123

91124
// Administration context
92-
$this->owners = new OwnerCollection();
93125
$this->administrationService = new AdministrationService($this->owners, $publisher);
94-
$this->menuService = new MenuService();
126+
$this->menu = new MenuService($this->owners, $publisher);
95127

96128
// Sale context
97-
$this->employees = new EmployeeCollection();
98129
new CookService($this->employees, $publisher);
99130
new CashierService($this->employees, $publisher);
131+
$this->buyerService = new BuyerService($this->buyers, 'CA'); // default country
100132
new WaitressService($this->employees, $publisher);
101-
$this->orderService = new OrderService();
133+
$this->orderService = new OrderService(
134+
$this->orders, $publisher, $this->buyers, $this->meals, $this->fakeIdGenerator
135+
);
136+
new CreateMealOnRecipeCreated($this->meals, $publisher);
102137

103138
// Shipping context
104139
new CreateDeliveryBoyHandler($this->employees, $publisher);
@@ -119,33 +154,38 @@ public function isTheStoreOwner($name)
119154
*/
120155
public function alreadyEmploysAs($ownerName, $employeeName, $role)
121156
{
122-
$this->owners->ownerWithId(new OwnerId(FullName::fromSingleString($ownerName)))
123-
->hire(FullName::fromSingleString($employeeName), JobTitle::fromString($role));
157+
$this->administrationService->hireCandidate(
158+
new HireCandidateCommand(
159+
new OwnerId(FullName::fromSingleString($ownerName)),
160+
FullName::fromSingleString($employeeName),
161+
JobTitle::fromString($role)
162+
)
163+
);
124164
}
125165

126166
/**
127-
* @Given :owner has created the meal :mealName with price of :mealPrice each
167+
* @Given :owner has created the recipe :recipeName with price of :recipePrice each
128168
*/
129-
public function hasCreatedTheMealWithPriceOfEach($owner, $mealName, $mealPrice)
169+
public function hasCreatedTheRecipeWithPriceOfEach($owner, $recipeName, $recipePrice)
130170
{
131-
$this->menuService->registerMeal(
132-
new RegisterNewMeal(
171+
$this->menu->registerRecipe(
172+
new RegisterNewRecipe(
133173
new OwnerId(FullName::fromSingleString($owner)),
134-
MealName::fromString($mealName),
135-
Money::fromString($mealPrice)
174+
RecipeName::fromString($recipeName),
175+
Money::fromInt($recipePrice)
136176
)
137177
);
138178
}
139179

140180
/**
141-
* @Given :owner has released the meal :mealName
181+
* @Given :owner has released the recipe :recipeName
142182
*/
143-
public function hasReleasedTheMeal($owner, $mealName)
183+
public function hasReleasedTheRecipe($owner, $recipeName)
144184
{
145-
$this->menuService->releaseMeal(
146-
new ReleaseMeal(
185+
$this->menu->releaseRecipe(
186+
new ReleaseRecipe(
147187
new OwnerId(FullName::fromSingleString($owner)),
148-
MealName::fromString($mealName)
188+
new RecipeId(RecipeName::fromString($recipeName))
149189
)
150190
);
151191
}
@@ -158,66 +198,69 @@ public function postulateOnAJobOffering($applicantName)
158198
}
159199

160200
/**
161-
* @Given :waitressName is taking phone call orders
201+
* @Given :customerName never ordered meals to the shop
162202
*/
163-
public function isTakingPhoneCallOrders($waitressName)
203+
public function neverOrderedMealsToTheShop($customerName)
164204
{
165-
$this->waitress = $this->employees->employeeWithIdentity(new EmployeeId($waitressName));
166205
}
167206

168207
/**
169-
* @Given :customerName calls the shop to order the meal :mealName
208+
* @Given :customerName gives his phone number :phoneNumber and home address :address
170209
*/
171-
public function callsTheShopToOrderTheMeal($customerName, $mealName)
210+
public function givesHisPhoneNumberAndHomeAddress($customerName, $phoneNumber, $address)
172211
{
173-
$meal = $this->meals->mealWithName(MealName::fromString($mealName));
174-
175-
$this->orderService->orderMeal(
176-
new OrderMeal(
177-
$this->waitress->getIdentity(),
178-
CustomerType::PhoneCustomer(),
179-
$meal->getIdentity(),
180-
CustomerName::fromString($customerName)
181-
)
182-
);
212+
$this->phones[$customerName] = PhoneNumber::fromString($phoneNumber, 'CA');
213+
$this->buyerService->registerPhoneBuyer($phoneNumber, $address);
183214
}
184215

185216
/**
186-
* @Given :customerName phone number is :phoneNumber
217+
* @When :ownerName hires :applicantName as the new :role
187218
*/
188-
public function phoneNumberIs($customerName, $phoneNumber)
219+
public function hiresAsTheNew($ownerName, $applicantName, $role)
189220
{
190-
throw new PendingException();
221+
$this->administrationService->hireCandidate(
222+
new HireCandidateCommand(
223+
new OwnerId(FullName::fromSingleString($ownerName)),
224+
FullName::fromSingleString($applicantName),
225+
JobTitle::fromString($role)
226+
)
227+
);
191228
}
192229

193230
/**
194-
* @Given :customerName home address is :address
231+
* @When :waitressName starts the order :orderId of :customerName
195232
*/
196-
public function homeAddressIs($customerName, $address)
233+
public function startsTheOrderOf($waitressName, $orderId, $customerName)
197234
{
198-
throw new PendingException();
235+
$this->fakeIdGenerator->returnsOrderIdOnNextCall(new OrderId($orderId));
236+
$this->orderService->startOrder(
237+
EmployeeId::fromName(FullName::fromSingleString($waitressName)),
238+
CustomerType::PhoneCustomer(),
239+
BuyerId::phoneBuyer($this->getPhoneNumberOfCustomer($customerName))
240+
);
199241
}
200242

201243
/**
202-
* @When :ownerName hires :applicantName as the new :role
244+
* @When :customerName order :quantity meal :mealName on order :orderId
203245
*/
204-
public function hiresAsTheNew($ownerName, $applicantName, $role)
246+
public function orderMealOnOrder($customerName, $quantity, $mealName, $orderId)
205247
{
206-
$this->administrationService->hireCandidate(
207-
new HireCandidateCommand(
208-
new OwnerId(FullName::fromSingleString($ownerName)),
209-
FullName::fromSingleString($applicantName),
210-
JobTitle::fromString($role)
211-
)
248+
$this->orderService->orderMeal(
249+
new OrderId($orderId),
250+
$quantity,
251+
new MealId(Transliterator::transliterate($mealName))
212252
);
213253
}
214254

215255
/**
216-
* @When :waitressName confirms the order with id :orderId at :time
256+
* @When :waitressName confirms that :customerName order confirmation number is :orderId at :time
217257
*/
218-
public function confirmsTheOrderWithIdAt($waitressName, $orderId, $time)
258+
public function confirmsThatOrderConfirmationNumberIsAt($waitressName, $customerName, $orderId, $time)
219259
{
220-
throw new PendingException();
260+
$this->orderService->confirmOrder(
261+
new OrderId($orderId),
262+
new \DateTime($time)
263+
);
221264
}
222265

223266
/**
@@ -295,4 +338,14 @@ public function theOrderShouldHaveTakenToComplete($orderId, $time)
295338
{
296339
throw new PendingException();
297340
}
341+
342+
/**
343+
* @param string $customerName
344+
*
345+
* @return PhoneNumber
346+
*/
347+
private function getPhoneNumberOfCustomer($customerName)
348+
{
349+
return $this->phones[$customerName];
350+
}
298351
}

features/manage-store.feature

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,20 @@ Feature:
99
And 'John' already employs 'Judy' as 'waitress'
1010
And 'John' already employs 'Mark' as 'cashier'
1111
And 'John' already employs 'Esther' as 'cook'
12-
And 'John' has created the meal 'All dressed pizza' with price of '10.00$' each
13-
And 'John' has released the meal 'All dressed pizza'
12+
And 'John' has created the recipe 'All dressed pizza' with price of '10.00$' each
13+
And 'John' has released the recipe 'All dressed pizza'
14+
And 'John' has created the recipe 'Small fries' with price of '5.00$' each
15+
And 'John' has released the recipe 'Small fries'
1416

15-
Scenario: Hiring new cashier to help customer pay for meals
17+
Scenario: Hiring new cashier to help customer pay for recipes
1618
Given 'Jane' postulate on a job offering
1719
When 'John' hires 'Jane' as the new 'cashier'
1820
Then 'John' should have 5 employees
1921
And There should be 2 employees with 'cashier' title
2022
# todo cashier receives payment from customer for order
2123
# todo Should be in sale context
2224

23-
Scenario: Hiring new cook to cook meals
25+
Scenario: Hiring new cook to cook recipes
2426
Given 'Luke' postulate on a job offering
2527
When 'John' hires 'Luke' as the new 'cook'
2628
Then 'John' should have 5 employees
@@ -36,27 +38,28 @@ Feature:
3638
# todo waitress take order from customer (create order)
3739
# todo Should be in sale context
3840

39-
Scenario: Hiring new delivery boy to deliver meals
41+
Scenario: Hiring new delivery boy to deliver recipes
4042
Given 'Han' postulate on a job offering
4143
When 'John' hires 'Han' as the new 'delivery boy'
4244
Then 'John' should have 5 employees
4345
And There should be 2 employees with 'delivery boy' title
44-
# todo delivery boy deliver meal to customer
46+
# todo delivery boy deliver recipe to customer
4547
# todo Should be in shipping context
4648

4749
Scenario: Cashier serves a phone customer who wishes its order to be delivered
48-
Given 'Mark' is taking phone call orders
49-
And 'Billy' calls the shop to order the meal 'All dressed pizza'
50-
And 'Billy' phone number is '555-5555'
5150
# todo address must be in range of delivery
52-
And 'Billy' home address is '1 main street'
53-
When 'Mark' confirms the order with id '333' at '18:00:00'
51+
Given 'Billy' never ordered meals to the shop
52+
And 'Billy' gives his phone number '555-5555' and home address '1 main street'
53+
When 'Mark' starts the order '333' of 'Billy'
54+
And 'Billy' order 2 meal 'All dressed pizza' on order '333'
55+
And 'Billy' order 1 meal 'Small fries' on order '333'
56+
And 'Mark' confirms that 'Billy' order confirmation number is '333' at '18:00:00'
5457
And 'Esther' finishes to cook the order '333' at '18:10:00'
5558
And 'Jake' delivers the order '333' at '18:30:00'
5659
And 'Billy' pays '12.00$' to 'Jake'
5760
Then Order '333' should be closed at '18:30:00'
58-
And The order '333' should have an income of '10.00$'
59-
And The order '333' should registers a tip of '2.00$'
61+
And The order '333' should have an income of '25.00$'
62+
And The order '333' should registers a tip of '3.00$'
6063
And The order '333' should have taken '0:30:00' to complete
6164

6265
# Scenario: Cashier serves a front desk customer

src/Domain/Administration/Application/AdministrationService.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
namespace Example\Domain\Administration\Application;
99

10-
use Example\Domain\Administration\DomainModel\CandidateRepository;
1110
use Example\Domain\Administration\DomainModel\OwnerRepository;
1211
use Example\Domain\Common\Application\EventPublisher;
1312

0 commit comments

Comments
 (0)