activityManager = $this->createMock(IActivityManager::class); $this->logger = $this->createMock(LoggerInterface::class); $this->listener = new RemoteWipeActivityListener( $this->activityManager, $this->logger ); } public function testHandleUnrelated(): void { $event = new Event(); $this->listener->handle($event); $this->addToAssertionCount(1); } public function testHandleRemoteWipeStarted(): void { /** @var IToken|MockObject $token */ $token = $this->createMock(IToken::class); $event = new RemoteWipeStarted($token); $activityEvent = $this->createMock(IActivityEvent::class); $this->activityManager->expects($this->once()) ->method('generateEvent') ->willReturn($activityEvent); $activityEvent->expects($this->once()) ->method('setApp') ->with('core') ->willReturnSelf(); $activityEvent->expects($this->once()) ->method('setType') ->with('security') ->willReturnSelf(); $token->method('getUID')->willReturn('user123'); $activityEvent->expects($this->once()) ->method('setAuthor') ->with('user123') ->willReturnSelf(); $activityEvent->expects($this->once()) ->method('setAffectedUser') ->with('user123') ->willReturnSelf(); $token->method('getName')->willReturn('Token 1'); $activityEvent->expects($this->once()) ->method('setSubject') ->with('remote_wipe_start', ['name' => 'Token 1']) ->willReturnSelf(); $this->activityManager->expects($this->once()) ->method('publish'); $this->listener->handle($event); } public function testHandleRemoteWipeStartedCanNotPublish(): void { $token = $this->createMock(IToken::class); $event = new RemoteWipeStarted($token); $this->activityManager->expects($this->once()) ->method('generateEvent'); $this->activityManager->expects($this->once()) ->method('publish') ->willThrowException(new \BadMethodCallException()); $this->listener->handle($event); } public function testHandleRemoteWipeFinished(): void { /** @var IToken|MockObject $token */ $token = $this->createMock(IToken::class); $event = new RemoteWipeFinished($token); $activityEvent = $this->createMock(IActivityEvent::class); $this->activityManager->expects($this->once()) ->method('generateEvent') ->willReturn($activityEvent); $activityEvent->expects($this->once()) ->method('setApp') ->with('core') ->willReturnSelf(); $activityEvent->expects($this->once()) ->method('setType') ->with('security') ->willReturnSelf(); $token->method('getUID')->willReturn('user123'); $activityEvent->expects($this->once()) ->method('setAuthor') ->with('user123') ->willReturnSelf(); $activityEvent->expects($this->once()) ->method('setAffectedUser') ->with('user123') ->willReturnSelf(); $token->method('getName')->willReturn('Token 1'); $activityEvent->expects($this->once()) ->method('setSubject') ->with('remote_wipe_finish', ['name' => 'Token 1']) ->willReturnSelf(); $this->activityManager->expects($this->once()) ->method('publish'); $this->listener->handle($event); } }