writer = $this->createMock(Writer::class); $this->userHelper = $this->createMock(UserHelper::class); $this->ownerProvider = $this->createMock(OwnerProvider::class); $this->routeHelper = $this->createMock(RouteHelper::class); $this->translator = $this->createMock(TranslatorInterface::class); $userNotificationBuilder = new UserNotificationBuilder($this->userHelper, $this->ownerProvider, $this->routeHelper, $this->translator ); $this->helper = new UserNotificationHelper($this->writer, $userNotificationBuilder); } public function testNotificationSentToOwner(): void { $this->ownerProvider->expects($this->once()) ->method('getOwnersForObjectIds') ->with(Contact::NAME, [1]) ->willReturn([['owner_id' => 1, 'id' => 1]]); $this->userHelper->expects($this->never()) ->method('getAdminUsers'); $this->translator->expects($this->exactly(2)) ->method('trans') ->withConsecutive( ['mautic.integration.sync.user_notification.header', $this->anything()], ['mautic.integration.sync.user_notification.sync_error', $this->anything()] ) ->willReturn('test'); $this->writer->expects($this->once()) ->method('writeUserNotification'); $this->routeHelper->expects($this->once()) ->method('getLink'); $this->helper->writeNotification('test', 'test', 'test', Contact::NAME, 1, 'foobar'); } public function testNotificationSentToAdmins(): void { $this->ownerProvider->expects($this->once()) ->method('getOwnersForObjectIds') ->with(Contact::NAME, [1]) ->willReturn([]); $this->userHelper->expects($this->once()) ->method('getAdminUsers') ->willReturn([1]); $this->translator->expects($this->exactly(2)) ->method('trans') ->withConsecutive( ['mautic.integration.sync.user_notification.header', $this->anything()], ['mautic.integration.sync.user_notification.sync_error', $this->anything()] ) ->willReturn('test'); $this->writer->expects($this->once()) ->method('writeUserNotification'); $this->routeHelper->expects($this->once()) ->method('getLink'); $this->helper->writeNotification('test', 'test', 'test', Contact::NAME, 1, 'foobar'); } }