Skip to content

Commit e317158

Browse files
committed
Add order by phone
* Add basic menu configuration by owner * Add cashier manages the order of the phone customer * On order confirms, the cook can cook the order's meal * On order ready, the delivery boy can deliver meal * When delivered, the money should be registered
1 parent aba5cd5 commit e317158

File tree

15 files changed

+418
-5
lines changed

15 files changed

+418
-5
lines changed

features/bootstrap/ApplicationContext.php

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,27 @@
99
use Behat\Gherkin\Node\TableNode;
1010
use Example\Domain\Administration\Application\AdministrationService;
1111
use Example\Domain\Administration\Application\HireCandidateCommand;
12+
use Example\Domain\Administration\Application\MenuService;
13+
use Example\Domain\Administration\Application\RegisterNewMeal;
14+
use Example\Domain\Administration\Application\ReleaseMeal;
1215
use Example\Domain\Common\DomainModel\FullName;
1316
use Example\Domain\Administration\DomainModel\Identity\OwnerId;
1417
use Example\Domain\Administration\DomainModel\Owner;
1518
use Example\Domain\Common\DomainModel\JobTitle;
19+
use Example\Domain\Common\DomainModel\MealName;
20+
use Example\Domain\Common\DomainModel\Money;
1621
use Example\Domain\Sale\Application\CashierService;
22+
use Example\Domain\Sale\Application\OrderMeal;
23+
use Example\Domain\Sale\Application\OrderService;
1724
use Example\Domain\Sale\Application\WaitressService;
25+
use Example\Domain\Sale\DomainModel\CustomerName;
26+
use Example\Domain\Sale\DomainModel\CustomerType;
27+
use Example\Domain\Sale\DomainModel\Identity\EmployeeId;
28+
use Example\Domain\Sale\DomainModel\Waitress;
1829
use Example\Domain\Shipping\Application\CreateDeliveryBoyHandler;
1930
use Example\Infrastructure\InMemory\EmployeeCollection;
2031
use Example\Infrastructure\InMemory\OwnerCollection;
32+
use Example\Infrastructure\InMemory\Sale\MealCollection;
2133
use Example\Infrastructure\Symfony\SymfonyPublisher;
2234
use Example\Domain\Sale\Application\CookService;
2335
use PHPUnit_Framework_Assert as Assert;
@@ -37,11 +49,33 @@ class ApplicationContext implements Context, SnippetAcceptingContext
3749
*/
3850
private $owners;
3951

52+
/**
53+
* @var MealCollection
54+
*/
55+
private $meals;
56+
4057
/**
4158
* @var AdministrationService
4259
*/
4360
private $administrationService;
4461

62+
/**
63+
* @var MenuService
64+
*/
65+
private $menuService;
66+
67+
/**
68+
* @var OrderService
69+
*/
70+
private $orderService;
71+
72+
/**
73+
* The current waitress on post
74+
*
75+
* @var Waitress|null
76+
*/
77+
private $waitress;
78+
4579
/**
4680
* Initializes context.
4781
*
@@ -52,16 +86,19 @@ class ApplicationContext implements Context, SnippetAcceptingContext
5286
public function __construct()
5387
{
5488
$publisher = new SymfonyPublisher();
89+
$this->meals = new MealCollection();
5590

5691
// Administration context
5792
$this->owners = new OwnerCollection();
5893
$this->administrationService = new AdministrationService($this->owners, $publisher);
94+
$this->menuService = new MenuService();
5995

6096
// Sale context
6197
$this->employees = new EmployeeCollection();
6298
new CookService($this->employees, $publisher);
6399
new CashierService($this->employees, $publisher);
64100
new WaitressService($this->employees, $publisher);
101+
$this->orderService = new OrderService();
65102

66103
// Shipping context
67104
new CreateDeliveryBoyHandler($this->employees, $publisher);
@@ -86,13 +123,81 @@ public function alreadyEmploysAs($ownerName, $employeeName, $role)
86123
->hire(FullName::fromSingleString($employeeName), JobTitle::fromString($role));
87124
}
88125

126+
/**
127+
* @Given :owner has created the meal :mealName with price of :mealPrice each
128+
*/
129+
public function hasCreatedTheMealWithPriceOfEach($owner, $mealName, $mealPrice)
130+
{
131+
$this->menuService->registerMeal(
132+
new RegisterNewMeal(
133+
new OwnerId(FullName::fromSingleString($owner)),
134+
MealName::fromString($mealName),
135+
Money::fromString($mealPrice)
136+
)
137+
);
138+
}
139+
140+
/**
141+
* @Given :owner has released the meal :mealName
142+
*/
143+
public function hasReleasedTheMeal($owner, $mealName)
144+
{
145+
$this->menuService->releaseMeal(
146+
new ReleaseMeal(
147+
new OwnerId(FullName::fromSingleString($owner)),
148+
MealName::fromString($mealName)
149+
)
150+
);
151+
}
152+
89153
/**
90154
* @Given :applicantName postulate on a job offering
91155
*/
92156
public function postulateOnAJobOffering($applicantName)
93157
{
94158
}
95159

160+
/**
161+
* @Given :waitressName is taking phone call orders
162+
*/
163+
public function isTakingPhoneCallOrders($waitressName)
164+
{
165+
$this->waitress = $this->employees->employeeWithIdentity(new EmployeeId($waitressName));
166+
}
167+
168+
/**
169+
* @Given :customerName calls the shop to order the meal :mealName
170+
*/
171+
public function callsTheShopToOrderTheMeal($customerName, $mealName)
172+
{
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+
);
183+
}
184+
185+
/**
186+
* @Given :customerName phone number is :phoneNumber
187+
*/
188+
public function phoneNumberIs($customerName, $phoneNumber)
189+
{
190+
throw new PendingException();
191+
}
192+
193+
/**
194+
* @Given :customerName home address is :address
195+
*/
196+
public function homeAddressIs($customerName, $address)
197+
{
198+
throw new PendingException();
199+
}
200+
96201
/**
97202
* @When :ownerName hires :applicantName as the new :role
98203
*/
@@ -107,6 +212,38 @@ public function hiresAsTheNew($ownerName, $applicantName, $role)
107212
);
108213
}
109214

215+
/**
216+
* @When :waitressName confirms the order with id :orderId at :time
217+
*/
218+
public function confirmsTheOrderWithIdAt($waitressName, $orderId, $time)
219+
{
220+
throw new PendingException();
221+
}
222+
223+
/**
224+
* @When :cookName finishes to cook the order :orderId at :time
225+
*/
226+
public function finishesToCookTheOrderAt($cookName, $orderId, $time)
227+
{
228+
throw new PendingException();
229+
}
230+
231+
/**
232+
* @When :deliveryBoyName delivers the order :orderId at :time
233+
*/
234+
public function deliversTheOrderAt($deliveryBoyName, $orderId, $time)
235+
{
236+
throw new PendingException();
237+
}
238+
239+
/**
240+
* @When :customerName pays :price to :deliveryBoyName
241+
*/
242+
public function paysTo($customerName, $price, $deliveryBoyName)
243+
{
244+
throw new PendingException();
245+
}
246+
110247
/**
111248
* @Then :ownerName should have :employeeCount employees
112249
*/
@@ -126,4 +263,36 @@ public function thereShouldBeEmployeesWithTitle($employeeCount, $role)
126263
(int) $employeeCount, $this->employees->employeesWithTitle(JobTitle::fromString($role))
127264
);
128265
}
266+
267+
/**
268+
* @Then Order :orderId should be closed at :time
269+
*/
270+
public function orderShouldBeClosedAt($orderId, $time)
271+
{
272+
throw new PendingException();
273+
}
274+
275+
/**
276+
* @Then The order :orderId should have an income of :money
277+
*/
278+
public function theOrderShouldHaveAnIncomeOf($orderId, $money)
279+
{
280+
throw new PendingException();
281+
}
282+
283+
/**
284+
* @Then The order :orderId should registers a tip of :money
285+
*/
286+
public function theOrderShouldRegistersATipOf($orderId, $money)
287+
{
288+
throw new PendingException();
289+
}
290+
291+
/**
292+
* @Then The order :orderId should have taken :time to complete
293+
*/
294+
public function theOrderShouldHaveTakenToComplete($orderId, $time)
295+
{
296+
throw new PendingException();
297+
}
129298
}

features/manage-store.feature

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,57 @@ Feature:
88
And 'John' already employs 'Jake' as 'delivery boy'
99
And 'John' already employs 'Judy' as 'waitress'
1010
And 'John' already employs 'Mark' as 'cashier'
11+
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'
1114

1215
Scenario: Hiring new cashier to help customer pay for meals
1316
Given 'Jane' postulate on a job offering
1417
When 'John' hires 'Jane' as the new 'cashier'
15-
Then 'John' should have 4 employees
18+
Then 'John' should have 5 employees
1619
And There should be 2 employees with 'cashier' title
1720
# todo cashier receives payment from customer for order
1821
# todo Should be in sale context
1922

2023
Scenario: Hiring new cook to cook meals
2124
Given 'Luke' postulate on a job offering
2225
When 'John' hires 'Luke' as the new 'cook'
23-
Then 'John' should have 4 employees
24-
And There should be 1 employees with 'cook' title
26+
Then 'John' should have 5 employees
27+
And There should be 2 employees with 'cook' title
2528
# todo cook prepare order of customer
2629
# todo Should be in sale context
2730

2831
Scenario: Hiring new waitress to take order from customer
2932
Given 'Leia' postulate on a job offering
3033
When 'John' hires 'Leia' as the new 'waitress'
31-
Then 'John' should have 4 employees
34+
Then 'John' should have 5 employees
3235
And There should be 2 employees with 'waitress' title
3336
# todo waitress take order from customer (create order)
3437
# todo Should be in sale context
3538

3639
Scenario: Hiring new delivery boy to deliver meals
3740
Given 'Han' postulate on a job offering
3841
When 'John' hires 'Han' as the new 'delivery boy'
39-
Then 'John' should have 4 employees
42+
Then 'John' should have 5 employees
4043
And There should be 2 employees with 'delivery boy' title
4144
# todo delivery boy deliver meal to customer
4245
# todo Should be in shipping context
46+
47+
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'
51+
# 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'
54+
And 'Esther' finishes to cook the order '333' at '18:10:00'
55+
And 'Jake' delivers the order '333' at '18:30:00'
56+
And 'Billy' pays '12.00$' to 'Jake'
57+
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$'
60+
And The order '333' should have taken '0:30:00' to complete
61+
62+
# Scenario: Cashier serves a front desk customer
63+
64+
# Scenario: Cashier serves a drive-in customer
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
/**
3+
* This file is part of the php-ddd project.
4+
*
5+
* (c) Yannick Voyer <star.yvoyer@gmail.com> (http://github.com/yvoyer)
6+
*/
7+
8+
namespace Example\Domain\Administration\Application;
9+
10+
final class MenuService
11+
{
12+
public function registerMeal(RegisterNewMeal $command)
13+
{
14+
}
15+
16+
public function releaseMeal(ReleaseMeal $command)
17+
{
18+
}
19+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
/**
3+
* This file is part of the php-ddd project.
4+
*
5+
* (c) Yannick Voyer <star.yvoyer@gmail.com> (http://github.com/yvoyer)
6+
*/
7+
8+
namespace Example\Domain\Administration\Application;
9+
10+
final class RegisterNewMeal
11+
{
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
/**
3+
* This file is part of the php-ddd project.
4+
*
5+
* (c) Yannick Voyer <star.yvoyer@gmail.com> (http://github.com/yvoyer)
6+
*/
7+
8+
namespace Example\Domain\Administration\Application;
9+
10+
final class ReleaseMeal
11+
{
12+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
/**
3+
* This file is part of the php-ddd project.
4+
*
5+
* (c) Yannick Voyer <star.yvoyer@gmail.com> (http://github.com/yvoyer)
6+
*/
7+
8+
namespace Example\Domain\Administration\DomainModel;
9+
10+
final class Meal
11+
{
12+
/**
13+
* @return MealId
14+
*/
15+
public function getIdentity()
16+
{
17+
return new MealId();
18+
}
19+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
/**
3+
* This file is part of the php-ddd project.
4+
*
5+
* (c) Yannick Voyer <star.yvoyer@gmail.com> (http://github.com/yvoyer)
6+
*/
7+
8+
namespace Example\Domain\Administration\DomainModel;
9+
10+
final class MealId
11+
{
12+
}

0 commit comments

Comments
 (0)