public function testSendNotification() { DomainEvents::setEventDispatcher(new EventDispatcher()); $user = User::fromDTO(new CreateUserDTO('Ma27', 'test-password', '*****@*****.**')); $publisher = $this->getMock(BackendInterface::class); $publisher->expects($this->once())->method('createAndPublish')->with('sen_mailer', ['override_locale' => true, 'user' => $user, 'content' => 'notification.auth.failures', 'parameters' => ['translation_defaults' => ['%times%' => 2]]]); $hook = new AuthenticationReportListener($publisher); $entity = new AuthenticationFailure($user); $entity->updateReport(); $entity->updateReport(); $entityReport = $entity->createReport(); $event = new AuthenticationAttemptEvent($user); $event->setReport($entityReport); $hook->onAuthenticationFailure($event); }
/** * Updates the failure report */ public function updateReport() { if (null === $this->start) { $this->start = new \DateTime(); $this->attemptCount++; $event = new AuthenticationAttemptEvent($this->relatedUser); $event->setReport($this->createReport()); DomainEvents::raise($event); } else { $intervalTimestamp = $this->start->getTimestamp(); if (time() - $intervalTimestamp > 86400) { $this->start = new \DateTime(); $this->attemptCount = 1; } else { $this->attemptCount++; if (time() - $intervalTimestamp >= 21600) { $event = new AuthenticationAttemptEvent($this->relatedUser); $event->setReport($this->createReport()); DomainEvents::raise($event); } } } }