/**
  * @dataProvider rotateRefreshToken
  */
 public function testCanCreateTokenResponse($rotateRefreshToken)
 {
     $request = $this->getMock(ServerRequestInterface::class);
     $request->expects($this->once())->method('getParsedBody')->willReturn(['refresh_token' => '123', 'scope' => 'read']);
     $owner = $this->getMock(TokenOwnerInterface::class);
     $owner->expects($this->once())->method('getTokenOwnerId')->will($this->returnValue(1));
     $refreshToken = $this->getValidRefreshToken();
     $refreshToken->setScopes(['read']);
     $refreshToken->setOwner($owner);
     $this->refreshTokenService->expects($this->once())->method('getToken')->with('123')->will($this->returnValue($refreshToken));
     if ($rotateRefreshToken) {
         $this->refreshTokenService->expects($this->once())->method('deleteToken')->with($refreshToken);
         $refreshToken = $this->getValidRefreshToken();
         $this->refreshTokenService->expects($this->once())->method('createToken')->will($this->returnValue($refreshToken));
     }
     $accessToken = $this->getValidAccessToken();
     $accessToken->setOwner($owner);
     $this->accessTokenService->expects($this->once())->method('createToken')->will($this->returnValue($accessToken));
     $this->grant->setRotateRefreshTokens($rotateRefreshToken);
     $response = $this->grant->createTokenResponse($request, new Client());
     $body = json_decode($response->getBody(), true);
     $this->assertEquals('azerty_access', $body['access_token']);
     $this->assertEquals('Bearer', $body['token_type']);
     $this->assertEquals(3600, $body['expires_in']);
     $this->assertEquals('read', $body['scope']);
     $this->assertEquals(1, $body['owner_id']);
     $this->assertEquals('azerty_refresh', $body['refresh_token']);
 }
 /**
  * @dataProvider grantOptions
  */
 public function testCanCreateTokenResponse($rotateRefreshToken, $revokeRotatedRefreshToken)
 {
     $grant = new RefreshTokenGrant($this->accessTokenService, $this->refreshTokenService, ServerOptions::fromArray(['rotate_refresh_tokens' => $rotateRefreshToken, 'revoke_rotated_refresh_tokens' => $revokeRotatedRefreshToken]));
     $request = $this->createMock(ServerRequestInterface::class);
     $request->expects($this->once())->method('getParsedBody')->willReturn(['refresh_token' => '123', 'scope' => 'read']);
     $owner = $this->createMock(TokenOwnerInterface::class);
     $owner->expects($this->once())->method('getTokenOwnerId')->will($this->returnValue(1));
     $refreshToken = $this->getValidRefreshToken($owner, ['read']);
     $this->refreshTokenService->expects($this->once())->method('getToken')->with('123')->will($this->returnValue($refreshToken));
     if ($rotateRefreshToken) {
         $this->refreshTokenService->expects($revokeRotatedRefreshToken ? $this->once() : $this->never())->method('deleteToken')->with($refreshToken);
         $refreshToken = $this->getValidRefreshToken();
         $this->refreshTokenService->expects($this->once())->method('createToken')->will($this->returnValue($refreshToken));
     }
     $accessToken = $this->getValidAccessToken($owner);
     $this->accessTokenService->expects($this->once())->method('createToken')->will($this->returnValue($accessToken));
     $response = $grant->createTokenResponse($request, Client::createNewClient('name', []));
     $body = json_decode($response->getBody(), true);
     $this->assertEquals('azerty_access', $body['access_token']);
     $this->assertEquals('Bearer', $body['token_type']);
     $this->assertEquals(3600, $body['expires_in']);
     $this->assertEquals('read', $body['scope']);
     $this->assertEquals(1, $body['owner_id']);
     $this->assertEquals('azerty_refresh', $body['refresh_token']);
 }