wpFunctions = $this->createMock(WPFunctions::class); } public function testItNotifyCreatedSubscriberId(): void { $this->wpFunctions->method('currentTime') ->willReturn(1234); $this->wpFunctions->expects($this->once()) ->method('doAction') ->with(SubscriberEntity::HOOK_SUBSCRIBER_CREATED, 6) ->willReturn(true); $notifier = new SubscriberChangesNotifier($this->wpFunctions); $notifier->subscriberCreated(6); $notifier->notify(); } public function testItNotifyMultipleSubscribersCreated(): void { $this->wpFunctions->expects($this->any()) ->method('currentTime') ->willReturnOnConsecutiveCalls(1234, 3456); $this->wpFunctions->expects($this->once()) ->method('doAction') ->with(SubscriberEntity::HOOK_MULTIPLE_SUBSCRIBERS_CREATED, 1234) ->willReturn(true); $notifier = new SubscriberChangesNotifier($this->wpFunctions); $notifier->subscriberCreated(4); $notifier->subscriberCreated(6); $notifier->notify(); } public function testItNotifyUpdatedSubscriberId(): void { $this->wpFunctions->method('currentTime') ->willReturn(4567); $this->wpFunctions->expects($this->once()) ->method('doAction') ->with(SubscriberEntity::HOOK_SUBSCRIBER_UPDATED, 2) ->willReturn(true); $notifier = new SubscriberChangesNotifier($this->wpFunctions); $notifier->subscriberUpdated(2); $notifier->notify(); } public function testItNotifiesUpdatedSubscriberIdWithStatusChange(): void { $this->wpFunctions->method('currentTime') ->willReturn(4567); $this->wpFunctions->expects($this->once()) ->method('doAction') ->with(SubscriberEntity::HOOK_SUBSCRIBER_STATUS_CHANGED, 2) ->willReturn(true); $notifier = new SubscriberChangesNotifier($this->wpFunctions); $notifier->subscriberStatusChanged(2); $notifier->notify(); } public function testItNotifyMultipleSubscribersUpdated(): void { $this->wpFunctions->expects($this->any()) ->method('currentTime') ->willReturnOnConsecutiveCalls(12345, 1234); $this->wpFunctions->expects($this->once()) ->method('doAction') ->with(SubscriberEntity::HOOK_MULTIPLE_SUBSCRIBERS_UPDATED, 1234) ->willReturn(true); $notifier = new SubscriberChangesNotifier($this->wpFunctions); $notifier->subscriberUpdated(2); $notifier->subscriberUpdated(41); $notifier->notify(); } public function testItNotifyDeletedSubscriberId(): void { $this->wpFunctions->method('currentTime') ->willReturn(3456); $this->wpFunctions->expects($this->once()) ->method('doAction') ->with(SubscriberEntity::HOOK_SUBSCRIBER_DELETED, 1) ->willReturn(true); $notifier = new SubscriberChangesNotifier($this->wpFunctions); $notifier->subscriberDeleted(1); $notifier->notify(); } public function testItNotifyMultipleSubscribersDeleted(): void { $this->wpFunctions->expects($this->any()) ->method('currentTime') ->willReturnOnConsecutiveCalls(3456, 98712); $this->wpFunctions->expects($this->once()) ->method('doAction') ->with(SubscriberEntity::HOOK_MULTIPLE_SUBSCRIBERS_DELETED, [1, 12]) ->willReturn(true); $notifier = new SubscriberChangesNotifier($this->wpFunctions); $notifier->subscriberDeleted(1); $notifier->subscriberDeleted(12); $notifier->notify(); } public function testItNotifyDifferentSubscriberChanges(): void { $this->wpFunctions->method('currentTime') ->willReturn(12345); $this->wpFunctions->expects($this->any()) ->method('doAction') ->withConsecutive( [SubscriberEntity::HOOK_SUBSCRIBER_CREATED, 1], [SubscriberEntity::HOOK_SUBSCRIBER_UPDATED, 3], [SubscriberEntity::HOOK_SUBSCRIBER_DELETED, 5] ) ->willReturnOnConsecutiveCalls(true, true, true); $notifier = new SubscriberChangesNotifier($this->wpFunctions); $notifier->subscriberDeleted(5); $notifier->subscriberUpdated(3); $notifier->subscriberCreated(1); $notifier->notify(); } public function testItNotifyUpdateForCreatedSubscriber(): void { $this->wpFunctions->method('currentTime') ->willReturn(1235); $this->wpFunctions->expects($this->once()) ->method('doAction') ->with(SubscriberEntity::HOOK_SUBSCRIBER_CREATED, 11) ->willReturn(true); $notifier = new SubscriberChangesNotifier($this->wpFunctions); $notifier->subscriberCreated(11); $notifier->subscriberUpdated(11); $notifier->notify(); } public function testItNotifySubscribersBatchCreate(): void { $this->wpFunctions->expects($this->any()) ->method('currentTime') ->willReturnOnConsecutiveCalls(3456, 98712); $this->wpFunctions->expects($this->once()) ->method('doAction') ->with(SubscriberEntity::HOOK_MULTIPLE_SUBSCRIBERS_CREATED, 3456) ->willReturn(true); $notifier = new SubscriberChangesNotifier($this->wpFunctions); $notifier->subscribersBatchCreate(); $notifier->subscribersBatchCreate(); $notifier->notify(); } public function testItNotifySubscribersBatchUpdate(): void { $this->wpFunctions->expects($this->any()) ->method('currentTime') ->willReturnOnConsecutiveCalls(1234, 123); $this->wpFunctions->expects($this->once()) ->method('doAction') ->with(SubscriberEntity::HOOK_MULTIPLE_SUBSCRIBERS_UPDATED, 123) ->willReturn(true); $notifier = new SubscriberChangesNotifier($this->wpFunctions); $notifier->subscribersBatchUpdate(); $notifier->subscribersBatchUpdate(); $notifier->notify(); } }