77use Behat \Behat \Tester \Exception \PendingException ;
88use Behat \Gherkin \Node \PyStringNode ;
99use Behat \Gherkin \Node \TableNode ;
10+ use Behat \Transliterator \Transliterator ;
1011use Example \Domain \Administration \Application \AdministrationService ;
1112use Example \Domain \Administration \Application \HireCandidateCommand ;
1213use 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 ;
1518use Example \Domain \Common \DomainModel \FullName ;
1619use Example \Domain \Administration \DomainModel \Identity \OwnerId ;
1720use Example \Domain \Administration \DomainModel \Owner ;
1821use Example \Domain \Common \DomainModel \JobTitle ;
19- use Example \Domain \Common \DomainModel \MealName ;
2022use Example \Domain \Common \DomainModel \Money ;
23+ use Example \Domain \Sale \Application \BuyerService ;
2124use Example \Domain \Sale \Application \CashierService ;
22- use Example \Domain \Sale \Application \OrderMeal ;
25+ use Example \Domain \Sale \Application \CreateMealOnRecipeCreated ;
2326use Example \Domain \Sale \Application \OrderService ;
2427use 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 ;
2630use Example \Domain \Sale \DomainModel \CustomerType ;
2731use 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 ;
2935use Example \Domain \Shipping \Application \CreateDeliveryBoyHandler ;
36+ use Example \Infrastructure \ForgedIdGenerator ;
3037use Example \Infrastructure \InMemory \EmployeeCollection ;
3138use Example \Infrastructure \InMemory \OwnerCollection ;
39+ use Example \Infrastructure \InMemory \Sale \BuyerCollection ;
3240use Example \Infrastructure \InMemory \Sale \MealCollection ;
41+ use Example \Infrastructure \InMemory \Sale \OrderCollection ;
3342use Example \Infrastructure \Symfony \SymfonyPublisher ;
3443use Example \Domain \Sale \Application \CookService ;
3544use 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}
0 commit comments