eventDispatcher = $this->createMock(IEventDispatcher::class); $this->userSession = $this->createMock(IUserSession::class); $this->principalConnector = $this->createMock(Principal::class); $this->mailer = $this->createMock(IMailer::class); $this->logger = $this->createMock(LoggerInterface::class); $this->listener = new CalendarContactInteractionListener( $this->eventDispatcher, $this->userSession, $this->principalConnector, $this->mailer, $this->logger ); } public function testParseUnrelated(): void { $event = new Event(); $this->eventDispatcher->expects(self::never())->method('dispatchTyped'); $this->listener->handle($event); } public function testHandleWithoutAnythingInteresting(): void { $event = new CalendarShareUpdatedEvent(123, [], [], [], []); $user = $this->createMock(IUser::class); $this->userSession->expects(self::once())->method('getUser')->willReturn($user); $this->eventDispatcher->expects(self::never())->method('dispatchTyped'); $this->listener->handle($event); } public function testParseInvalidData(): void { $event = new CalendarObjectCreatedEvent(123, [], [], ['calendardata' => 'BEGIN:FOO']); $user = $this->createMock(IUser::class); $this->userSession->expects(self::once())->method('getUser')->willReturn($user); $this->eventDispatcher->expects(self::never())->method('dispatchTyped'); $this->logger->expects(self::once())->method('warning'); $this->listener->handle($event); } public function testParseCalendarEventWithInvalidEmail(): void { $event = new CalendarObjectCreatedEvent(123, [], [], ['calendardata' => <<createMock(IUser::class); $this->userSession->expects(self::once())->method('getUser')->willReturn($user); $this->eventDispatcher->expects(self::never())->method('dispatchTyped'); $this->logger->expects(self::never())->method('warning'); $this->listener->handle($event); } public function testParseCalendarEvent(): void { $event = new CalendarObjectCreatedEvent(123, [], [], ['calendardata' => <<createMock(IUser::class); $this->userSession->expects(self::once())->method('getUser')->willReturn($user); $this->mailer->expects(self::once())->method('validateMailAddress')->willReturn(true); $this->eventDispatcher->expects(self::once()) ->method('dispatchTyped') ->with(self::equalTo((new ContactInteractedWithEvent($user))->setEmail('user@domain.tld'))); $this->logger->expects(self::never())->method('warning'); $this->listener->handle($event); } }