55use Carbon \Carbon ;
66use Exception ;
77use HiEvents \DomainObjects \AttendeeDomainObject ;
8+ use HiEvents \DomainObjects \EventSettingDomainObject ;
89use HiEvents \DomainObjects \OrderDomainObject ;
910use HiEvents \DomainObjects \OrderItemDomainObject ;
1011use HiEvents \DomainObjects \ProductPriceDomainObject ;
1112use HiEvents \DomainObjects \Status \OrderStatus ;
1213use HiEvents \Exceptions \ResourceConflictException ;
1314use HiEvents \Repository \Interfaces \AffiliateRepositoryInterface ;
1415use HiEvents \Repository \Interfaces \AttendeeRepositoryInterface ;
16+ use HiEvents \Repository \Interfaces \EventSettingsRepositoryInterface ;
1517use HiEvents \Repository \Interfaces \OrderRepositoryInterface ;
1618use HiEvents \Repository \Interfaces \ProductPriceRepositoryInterface ;
1719use HiEvents \Repository \Interfaces \QuestionAnswerRepositoryInterface ;
@@ -44,6 +46,7 @@ class CompleteOrderHandlerTest extends TestCase
4446 private CompleteOrderHandler $ completeOrderHandler ;
4547 private DomainEventDispatcherService $ domainEventDispatcherService ;
4648 private AffiliateRepositoryInterface |MockInterface $ affiliateRepository ;
49+ private EventSettingsRepositoryInterface $ eventSettingsRepository ;
4750
4851 protected function setUp (): void
4952 {
@@ -60,6 +63,7 @@ protected function setUp(): void
6063 $ this ->productPriceRepository = Mockery::mock (ProductPriceRepositoryInterface::class);
6164 $ this ->domainEventDispatcherService = Mockery::mock (DomainEventDispatcherService::class);
6265 $ this ->affiliateRepository = Mockery::mock (AffiliateRepositoryInterface::class);
66+ $ this ->eventSettingsRepository = Mockery::mock (EventSettingsRepositoryInterface::class);
6367
6468 $ this ->completeOrderHandler = new CompleteOrderHandler (
6569 $ this ->orderRepository ,
@@ -68,7 +72,8 @@ protected function setUp(): void
6872 $ this ->questionAnswersRepository ,
6973 $ this ->productQuantityUpdateService ,
7074 $ this ->productPriceRepository ,
71- $ this ->domainEventDispatcherService
75+ $ this ->domainEventDispatcherService ,
76+ $ this ->eventSettingsRepository ,
7277 );
7378 }
7479
@@ -97,6 +102,8 @@ public function testHandleSuccessfullyCompletesOrder(): void
97102
98103 $ this ->productQuantityUpdateService ->shouldReceive ('updateQuantitiesFromOrder ' );
99104
105+ $ this ->eventSettingsRepository ->shouldReceive ('findFirstWhere ' )->andReturn ($ this ->createMockEventSetting ());
106+
100107 $ this ->completeOrderHandler ->handle ($ orderShortId , $ orderData );
101108
102109 $ this ->assertTrue (true );
@@ -169,6 +176,8 @@ public function testHandleUpdatesProductQuantitiesForFreeOrder(): void
169176
170177 $ this ->productQuantityUpdateService ->shouldReceive ('updateQuantitiesFromOrder ' )->once ();
171178
179+ $ this ->eventSettingsRepository ->shouldReceive ('findFirstWhere ' )->andReturn ($ this ->createMockEventSetting ());
180+
172181 $ this ->domainEventDispatcherService ->shouldReceive ('dispatch ' )
173182 ->withArgs (function (OrderEvent $ event ) use ($ order ) {
174183 return $ event ->type === DomainEventType::ORDER_CREATED
@@ -201,6 +210,8 @@ public function testHandleDoesNotUpdateProductQuantitiesForPaidOrder(): void
201210
202211 $ this ->productQuantityUpdateService ->shouldNotReceive ('updateQuantitiesFromOrder ' );
203212
213+ $ this ->eventSettingsRepository ->shouldReceive ('findFirstWhere ' )->andReturn ($ this ->createMockEventSetting ());
214+
204215 $ this ->completeOrderHandler ->handle ($ orderShortId , $ orderData );
205216
206217 $ this ->expectNotToPerformAssertions ();
@@ -269,6 +280,7 @@ private function createMockCompleteOrderDTO(): CompleteOrderDTO
269280 return new CompleteOrderDTO (
270281 order: $ orderDTO ,
271282 products: new Collection ([$ attendeeDTO ])
283+ ,event_id: 1
272284 );
273285 }
274286
@@ -313,4 +325,11 @@ private function createMockAttendee(): AttendeeDomainObject|MockInterface
313325 $ attendee ->shouldReceive ('getProductId ' )->andReturn (1 );
314326 return $ attendee ;
315327 }
328+
329+ private function createMockEventSetting (): EventSettingDomainObject
330+ {
331+ return (new EventSettingDomainObject ())
332+ ->setId (1 )
333+ ->setEventId (1 );
334+ }
316335}
0 commit comments