userSession = $this->createMock(Session::class); $this->session = $this->createMock(ISession::class); $this->request = $this->createMock(IRequest::class); $this->bearerAuth = new BearerAuth( $this->userSession, $this->session, $this->request ); } public function testValidateBearerTokenNotLoggedIn(): void { $this->assertFalse($this->bearerAuth->validateBearerToken('Token')); } public function testValidateBearerToken(): void { $this->userSession ->expects($this->exactly(2)) ->method('isLoggedIn') ->willReturnOnConsecutiveCalls( false, true, ); $user = $this->createMock(IUser::class); $user ->expects($this->once()) ->method('getUID') ->willReturn('admin'); $this->userSession ->expects($this->once()) ->method('getUser') ->willReturn($user); $this->assertSame('principals/users/admin', $this->bearerAuth->validateBearerToken('Token')); } public function testChallenge(): void { /** @var \PHPUnit\Framework\MockObject\MockObject|RequestInterface $request */ $request = $this->createMock(RequestInterface::class); /** @var \PHPUnit\Framework\MockObject\MockObject|ResponseInterface $response */ $response = $this->createMock(ResponseInterface::class); $result = $this->bearerAuth->challenge($request, $response); $this->assertEmpty($result); } }