public function testNotifyNewIpOnLogin()
 {
     $user = User::create('Ma27', '123456', '*****@*****.**');
     $entityManager = $this->getMock(EntityManagerInterface::class);
     $entityManager->expects($this->once())->method('persist')->with($user);
     $entityManager->expects($this->once())->method('flush');
     $eventDispatcher = $this->getMock(EventDispatcherInterface::class);
     $eventDispatcher->expects($this->once())->method('dispatch');
     $request = Request::create('/', 'GET', [], [], [], ['REMOTE_ADDR' => '127.0.0.1']);
     $stack = new RequestStack();
     $stack->push($request);
     $tracer = $this->getMock(IpTracingServiceInterface::class, ['getIpLocationData']);
     $tracer->expects($this->any())->method('getIpLocationData')->willReturn(new IpLocation('127.0.0.1', 'Germany', 'Bavaria', 'Munich', 48, 11));
     $listener = new CredentialNotifyListener($entityManager, $eventDispatcher, $stack, $tracer);
     $listener->onAuthentication(new OnAuthenticationEvent($user));
     $this->assertFalse($user->isNewUserIp('127.0.0.1'));
 }
 public function testNotifyNewIpOnLogin()
 {
     $user = User::create('Ma27', '123456', '*****@*****.**', new PhpPasswordHasher());
     $entityManager = $this->getMock(EntityManagerInterface::class);
     $entityManager->expects($this->once())->method('persist')->with($user);
     $entityManager->expects($this->once())->method('flush');
     $request = Request::create('/', 'GET', [], [], [], ['REMOTE_ADDR' => '127.0.0.1']);
     $stack = new RequestStack();
     $stack->push($request);
     $tracer = $this->getMock(IpTracingServiceInterface::class, ['getIpLocationData']);
     $tracer->expects($this->any())->method('getIpLocationData')->willReturn(new IpLocation('127.0.0.1', 'Germany', 'Bavaria', 'Munich', 48, 11));
     $notificator = $this->getMock(NotificatorInterface::class);
     $notificator->expects(self::once())->method('publishNotification');
     $listener = new CredentialNotifyListener($entityManager, $stack, $tracer, $this->getMock(BlockedAccountWriteProviderInterface::class));
     $listener->setNotificator($notificator);
     $listener->onAuthentication(new OnAuthenticationEvent($user));
     $this->assertFalse($user->addAndValidateNewUserIp('127.0.0.1', new DateTimeComparison()));
 }