public function testCreateNewTokenUntilOneDoesNotExist()
 {
     $token = new AccessToken();
     $this->scopeService->expects($this->once())->method('getDefaultScopes')->will($this->returnValue(['read']));
     $this->tokenRepository->expects($this->at(0))->method('findByToken')->with($this->isType('string'))->will($this->returnValue(new AccessToken()));
     $this->tokenRepository->expects($this->at(1))->method('findByToken')->with($this->isType('string'))->will($this->returnValue(null));
     $this->tokenService->createToken($token);
     $this->assertEquals(40, strlen($token->getToken()));
 }
 public function testCreateNewTokenUntilOneDoesNotExist()
 {
     $this->scopeService->expects($this->once())->method('getDefaultScopes')->will($this->returnValue(['read']));
     $this->tokenRepository->expects($this->at(0))->method('tokenExists')->with($this->isType('string'))->willReturn(true);
     $this->tokenRepository->expects($this->at(1))->method('tokenExists')->with($this->isType('string'))->willReturn(false);
     $this->tokenRepository->expects($this->once())->method('save')->will($this->returnArgument(0));
     $owner = $this->createMock(TokenOwnerInterface::class);
     $client = $this->createMock(Client::class);
     $token = $this->tokenService->createToken($owner, $client, []);
     $this->assertEquals(40, strlen($token->getToken()));
 }
 /**
  * Validate the token scopes against the registered scope
  *
  * @param  array $scopes
  * @return void
  * @throws OAuth2Exception
  */
 protected function validateTokenScopes(array $scopes)
 {
     $registeredScopes = $this->scopeService->getAll();
     foreach ($registeredScopes as &$registeredScope) {
         $registeredScope = is_string($registeredScope) ? $registeredScope : $registeredScope->getName();
     }
     $diff = array_diff($scopes, $registeredScopes);
     if (count($diff) > 0) {
         throw OAuth2Exception::invalidScope(sprintf('Some scope(s) do not exist: %s', implode(', ', $diff)));
     }
 }