notificationManager = $this->createMock(INotificationManager::class); $this->timeFactory = $this->createMock(ITimeFactory::class); $this->listener = new RemoteWipeNotificationsListener( $this->notificationManager, $this->timeFactory ); } public function testHandleUnrelated(): void { $event = new Event(); $this->listener->handle($event); $this->addToAssertionCount(1); } public function testHandleRemoteWipeStarted(): void { $token = $this->createMock(IToken::class); $event = new RemoteWipeStarted($token); $notification = $this->createMock(INotification::class); $this->notificationManager->expects($this->once()) ->method('createNotification') ->willReturn($notification); $notification->expects($this->once()) ->method('setApp') ->with('auth') ->willReturnSelf(); $token->method('getUID')->willReturn('user123'); $notification->expects($this->once()) ->method('setUser') ->with('user123') ->willReturnSelf(); $now = new DateTime(); $this->timeFactory->method('getDateTime')->willReturn($now); $notification->expects($this->once()) ->method('setDateTime') ->with($now) ->willReturnSelf(); $token->method('getId')->willReturn(123); $notification->expects($this->once()) ->method('setObject') ->with('token', '123') ->willReturnSelf(); $token->method('getName')->willReturn('Token 1'); $notification->expects($this->once()) ->method('setSubject') ->with('remote_wipe_start', [ 'name' => 'Token 1' ]) ->willReturnSelf(); $this->notificationManager->expects($this->once()) ->method('notify'); $this->listener->handle($event); } public function testHandleRemoteWipeFinished(): void { $token = $this->createMock(IToken::class); $event = new RemoteWipeFinished($token); $notification = $this->createMock(INotification::class); $this->notificationManager->expects($this->once()) ->method('createNotification') ->willReturn($notification); $notification->expects($this->once()) ->method('setApp') ->with('auth') ->willReturnSelf(); $token->method('getUID')->willReturn('user123'); $notification->expects($this->once()) ->method('setUser') ->with('user123') ->willReturnSelf(); $now = new DateTime(); $this->timeFactory->method('getDateTime')->willReturn($now); $notification->expects($this->once()) ->method('setDateTime') ->with($now) ->willReturnSelf(); $token->method('getId')->willReturn(123); $notification->expects($this->once()) ->method('setObject') ->with('token', '123') ->willReturnSelf(); $token->method('getName')->willReturn('Token 1'); $notification->expects($this->once()) ->method('setSubject') ->with('remote_wipe_finish', [ 'name' => 'Token 1' ]) ->willReturnSelf(); $this->notificationManager->expects($this->once()) ->method('notify'); $this->listener->handle($event); } }